Write a Java program that has a single module with two classes: 1. A public class that contains the main method, and doe

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Write a Java program that has a single module with two classes: 1. A public class that contains the main method, and doe

Post by answerhappygod »

Write a Java program that has a single module with twoclasses:1. A public class that contains the main method, and does thefollowing:
Creates a Triangle object, triangle1, using the defaultconstructorCreates a Triangle object, triangle2, using these values: 3, 4,5
Gets the perimeter and area of triangle1 using thecorrespondingmethods and prints them out with 3 decimals.
Gets the perimeter and area of triangle2 using thecorrespondingmethods and prints them out with 3 decimals.
2. A class named Triangle, which contains:
Three integer data fields named side1, side2 and side3– thesides of the triangle
A no-arg constructor that creates a default triangle where allsides are of length 1.
A constructor that takes 3 integers, each corresponding to aside in the triangle.
Setter and Getter methods for the length of each side of thetriangle
A method named getPerimeter() that returns the perimeter of thetriangle as an integer.
A method named getArea() that returns the area of the triangleas a double. Your program must use the methodology shown onthis website for getting the area of a triangle from 3 sidelengths: Area of Triangle with 3sides. https://www.cuemath.com/measurement/are ... s/Programs with syntax errors will not beaccepted.
Write A Java Program That Has A Single Module With Two Classes 1 A Public Class That Contains The Main Method And Doe 1
Write A Java Program That Has A Single Module With Two Classes 1 A Public Class That Contains The Main Method And Doe 1 (184.71 KiB) Viewed 30 times
Write a Java program that has a single module with two classes: 1. A public class that contains the main method, and does the following: a. Creates a Triangle object, triangle1, using the default constructor Creates a Triangle object, triangle2, using these values: 3, 4, 5 b. Gets the perimeter and area of triangle1 using the corresponding methods and prints them out with 3 decimals. c. Gets the perimeter and area of triangle2 using the corresponding methods and prints them out with 3 decimals. 2. A class named Triangle, which contains: a. Three integer data fields named side1, side2 and side3 - the sides of the triangle b. A no-arg constructor that creates a default triangle where all sides are of length 1. c. A constructor that takes 3 integers, each corresponding to a side in the triangle. d. Setter and Getter methods for the length of each side of the triangle e. A method named getPerimeter() that returns the perimeter of the triangle as an integer. f. A method named getArea() that returns the area of the triangle as a double. Your program must use the methodology shown on this website for getting the area of a triangle from 3 side lengths: Area of Triangle with 3 sides. Sample Program Run: Triangle 1 perimeter is 3, area is 0.433 Triangle 2 perimeter is 12, area is 6.000
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply