Understanding and accessing instance variables

Assignment Help JAVA Programming
Reference no: EM131587453

CSE110 - Arizona State University

Topics
- Conditional and Loops (Chapter 4)
- Implementing classes (Chapter 5)
- Understanding and accessing instance variables (Chapter 8)
- Implementing methods (Chapter 6)
- Object construction (Chapter 6)
- Constructors (chapter 8)
- Encapsulation (Chapter 8)

Coding Guidelines:
- Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).
- Keep identifiers to a reasonably short length.
- User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects).
- Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.
- Use white space to make your program more readable.

Part #1: Written Exercises
None

Part #2 - Programming
Your assignment is to write a class definition (not a program, there is no main method) named Triangle
(saved in a file Triangle.java). A Triangle has 3 instance variables:
int side1, side2, side3;

The class Triangle must include the following constructors and methods: (If your class does not contain any of the following methods, points will be deducted).
- public Triangle (int s1, int s2, int s3) - Sets up a triangle with the specified side lengths.
- private int largest() - Returns the length of the longest side of the triangle. This is a helper method.

- private int shortest() Returns the length of the shortest side of the triangle. This is a helper method.
- public boolean is_equilateral() - Determines whether a triangle is equilateral. If the longest side is equal to the shortest side, then the triangle is equilateral.
- public boolean is_isosceles() - Determines whether a triangle is isosceles. Any (and at least) two sides must be equal.
- public boolean is_scalene() - Determines whether a triangle is scalene. No two sides are equal.
- public String toString() - Prints the sides of the triangle.
Save the Triangle class in a file called Triangle.java and use the following program stored in Assignment4.java which has the main method to create a new Triangle object and to test what kind of Triangle it is. A sample output is shown below.

Important
Your class should have exactly the method headers that are described or otherwise your class will not work with the test driver program (Assignment4.java) that is provided. You should never change the test driver program if the test driver is provided but instead make changes to Triangle class to make it work.

Helpful Hints
- Work on it in steps - write one method, test it with a test driver and make sure it works before going on to the next method.
- Always make sure your code compiles before you add another method.
- Your methods should be able to be called in any order.
Triangle equal = new Triangle (6, 6, 6); //example of equilateral (and isosceles) triangle Triangle isosceles = new Triangle (3, 7, 7); // example of isosceles triangle
Triangle scalene = new Triangle (4, 5, 6); // example of scalene triangle

Sample Outputs
Sample 1:
Enter the sides of the triangle:
3 4 5
3 4 5 triangle:
It is not isosceles
It is not a equilateral It is scalene

Check another Triangle (y/n)? y
Enter the sides of the triangle:
4 5 6
4 5 6 triangle:
It is not isosceles
It is not a equilateral It is scalene

Check another Triangle (y/n)? y
Enter the sides of the triangle:
4 4 4

4 4 4 triangle: It is isosceles It is equilateral
It is not scalene

Check another Triangle (y/n)? y
Enter the sides of the triangle:
3 7 7
3 7 7 triangle: It is isosceles
It is not a equilateral It is not scalene

Check another Triangle (y/n)? n
Press any key to continue . . .

Reference no: EM131587453

Questions Cloud

Write an equation to model the situation : A photo is 4 inches wide. It is placed inside a frame with a border that is x inches wide. The total width of the photo and the frame is 7 inches.
Sources of information security threats : Trojan horse attacks pose serious threats to computer security. There is specialized anti-Trojan software designed to detect Trojans
How it performs in different economic environments : Analyze how it performs in different economic environments.
Determine whether or not argument uses deceptive statistics : Determine whether or not the argument uses any deceptive statistics. Give your opinion on whether or not the argument has persuaded you.
Understanding and accessing instance variables : Implementing classes - Understanding and accessing instance variables - identifiers semantic meaning and make them easy to read
What is the exacted return on this portfolio : what is the exacted return on this portfolio? What is beta of the portfolio? What is the standard deviation.
Define technology and social isolation : What kinds of evidence are would you see in a research paper about Technology and Social Isolation
How much money must abdol shift : Abdol Akhim has just come from a Personal Finance class where he learned that he can determine how much his savings will be worth in the future.
Discuss what you believe are most critical thing to consider : Discuss what you believe are the most critical things to consider when forming a team. Describe how this may or may not be different from what you thought?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd