java program

User Generated

snfgqvffbyir

Programming

Description

Java

Unformatted Attachment Preview

Surname 1 1 Define a Java class that will represent a triangle. First create the UML class diagram for the Triangle class as described here. In the class, declare 3 private instance variables (doubles) for the 3 sides, with default values of 1. Also, define the following public instance methods: • constructor with 3 double parameters (call the mutator described next) • 1 public mutator (set) method for the 3 sides (so it must have 3 double parameters), but unlike the Circle class, make sure each of the parameters is > 0 AND the sum of 2 sides > the other (i.e., make sure a+b>c and a+c>b and b+c>a), and if so, assign a parameter to its corresponding instance variable • 3 accessor methods, one for each of the 3 sides (each will return one double) • a method that calculates and returns the perimeter of the triangle (double) • a method that calculates and returns the area of the triangle (double) using Heron's formula shown in Lesson 5 (page 5.6). Before you could test this, read Lesson 5, page 5.7 first (not required to run this for the exercise, you will be required to in the next exercise). UPLOAD the UML class diagram (as a Word doc or PDF or picture and the Triangle class. 2 Write main (may be in the same or separate class from the Triangle class) to test the Triangle class that you wrote, if correct, or the posted answer for Exercise 5.1. Instantiate at least 2 Triangle objects, assigning them to Triangle variables in main. Call at least 2 of the instance methods for EACH of the Triangle objects, displaying the results. Run this, copy and paste the output (commented out) after the end of this program. Surname 2 3 Write a class called Customer which has private instance variables for a name, account number and SavingsAccount (see SavingsAccount class link). Include a constructor with a String, long, and double parameters which instantiates a SavingsAccount using the double parameter. Also include accessors for each instance variable and a mutator for the name only. You MUST also write the UML class diagram for this class.
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Attached.

Surname 1
Name
Instructor
Institution
Course
Date

package triangle;

/**
*
* @author brayoo
*/
public class Triangle {

//private instance variables
private double side1=1;
private double side2=1;
private double side3=1;

//public instance constructor method
public Triangle(double sideA, double sideB, double sideC){

side1=sideA;
side2=sideB;
side3=sideC;
}
//public method mutator to setvalues

Surname 2
public...


Anonymous
Really useful study material!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Similar Content

Related Tags