Starting from:

$35

Programming Assignment #3 Solution




This assignment will give you practice with interactive programs, if/else statements and methods that return values. Your program will prompt the user for information about two figures and compute area for each figure.




The sample log of execution indicates how your program is to behave. For each figure, we prompt for width, height (rectangle) and base, height (triangle) and radius (circle). After obtaining area for each figure, the program reports how they compare.




Notice that the program asks for each figure whether to enter rectangle, triangle and circle. You have to choose two figures among them. In the case of rectangle, the user is prompted for width, and height. In the case of triangle, the user is prompted for base and height. In the case of circle, the user is prompted for radius. These areas are calculated using the following formulas:

Rectangle:
= hw
h: height, w:width
Triangle:
=



b: base, ℎ : height




2




Circle:
= πr2
π: 3.14159, r: radius



As indicated in the sample log of execution, your program is to report the area for each figure. In addition to reporting the area for each figure, the program should also produce whichever of the following messages is appropriate:




The rectangle seems to be bigger than the triangle.




The triangle seems to be bigger than the rectangle.




The triangle and rectangle seem to be equal.




You should use static methods to eliminate redundant code and to break the problem up into logical subtasks. Your main method should be short so that a person can easily see the overall structure of the program. You are to introduce at least five static methods other than main. In this program, none of your methods should have more than 12 lines of code in the body of the method (not counting blank lines or lines with just curly braces on them). The 12-line limitation is a special requirement for this assignment because I want you to practice breaking up a program into methods. Be sure to once again include a short comment at the beginning of your program as well as a short comment for each method describing what it does.




Name your program Area.java and to access Scanner include the following at the beginning of your program:




import java.util.*;







Sample log of execution (user input bold and underlined)




This program is ….
your fist name / last name



Information for figure 1:




Type 1) rectangle 2) triangle 3) circle 1




height? 5.0




width? 60.0




Information for figure 2:




Type 1) rectangle 2) triangle 3) circle 2 base? 20.4




height? 5.5




rectangle area = 300.0




triangle area = 56.1




The rectangle seems to be bigger.

More products