Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please follow all directions , and create sentinel loop. A note for good coding practices: Starting with this assignment, you need to incorporate the following

please follow all directions , and create sentinel loop.

image text in transcribedimage text in transcribed
A note for good coding practices: Starting with this assignment, you need to incorporate the following concepts/practices in your code as required by the problem statement. Do not expect them to be spelled out in individual problem statement or subsequent assignments. This and subsequent assignments will be assessed for utilization of these concepts in the code. - Apply the concept of encapsulation. - Always declare variables as private. - Provide setters and getters methods to allow access to class variables as per the problem statement requirements and the role/purpose of each variable in the solution. - Always declare support methods as private. - Allow the user to enter input values to facilitate code test-ability. DO not hard code inputs unless stated in the problem statement. - Allow the user to re-run the code in the same session using a sentinel loop. - Always sanitize/validate input values as soon as being entered to make sure they are "good" values (using assertions or if statements).Develop a complete Java program for each of the following problems. Please name the programs as indicated and add proper program headers and output labels as shown below. Please use only concepts and programming constructs/syntax we discuss to date. Make sure you include a header for each program (see previous assignments). Program #1 (20 points): Design and implement class Triangle that inherits from class Geometricobjects (provided to you with this assignment). Class Triangle has the following characteristics: 1. Defines three private variables of type double: side 1, side2, and side3. Each is initialized with the value 1.0. 2. Defines a default (non-argument) constructor method to create default triangle objects (with default sides). 3. Defines a second constructor to allow the user to create triangle objects with user-specific input values for all sides. 4. Defines three access (get) methods, one for each variable, named as getSide1(), getSide2(), and getSide3() 5. Defines method getArea () that computes and returns the area of a triangle object. Here is the math (Heron's formula) for the area computation: double s = (sidel + side2 + side3) /2.0 double Area = Sqrt (s (s-sidel) (s-side2) (s-side3) ) 6. Defines method getPerimeter () that computes and returns the perimeter of a triangle object. Here is the math for perimeter computation: Perimeter = (sidel + side2 + side3) 7. Defines method toString () that returns a meaningful description of a triangle object including its name, sides, area, and perimeter in the following format (the values below are just an example for illustration purposes) Triangle : myTriangle Side 1: 4.0 Side 2: 5.0 Side 3: 6.0 Area : 9. 921567416492215 Perimeter : 15.0 Color : White Is Filled: true Write a test program in a separate file, named testTriangle, to create couple triangle objects (one default and one non-default) and test all of the class methods listed above on those 2 objects. Add proper and meaningful labels to your outputs. Document your code, use good coding practices, use proper prompts for input, format outputs as shown, do not hard-code inputs for non-default objects, allow program re-runs using sentinel loop, and test your code thoroughly

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions