Concept explainers
Geometry Calculator
Design a Geometry class with the following methods:
- A static method that accepts the radius of a circle and returns the area of the circle. Use the following formula:
Area = πr2
Use Math.PI for π and the radius of the circle for r.
- A static method that accepts the length and width of a rectangle and returns the area of the rectangle. Use the following formula:
Area = Length × Width
- A static method that accepts the length of a triangle’s base and the triangle’s height. The method should return the area of the triangle. Use the following formula:
Area = Base × Height × 0.5
The methods should display an error message if negative values are used for the circle’s radius, the rectangle’s length or width, or the triangle’s base or height.
Next, write a program to test the class, which displays the following menu and responds to the user’s selection:
Geometry Calculator
- 1. Calculate the Area of a Circle
- 2. Calculate the Area of a Rectangle
- 3. Calculate the Area of a Triangle
- 4. Quit
Enter your choice (1-4):
Display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the menu.
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Additional Engineering Textbook Solutions
Starting out with Visual C# (4th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Software Engineering (10th Edition)
Digital Fundamentals (11th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- 10arrow_forwardTrue or False: When passing multiple arguments to a method, the order in which the arguments are passed is not important.arrow_forwardPython Class and Objects Create a class named "Account" and “Bank” The class “Account” should have a parameter of id - integer type name - string type balance - float type # (Optional) You may add more parameters for your convenience 3. Create a method for “Account” class: checkBalance(self) - this will show the Account's remaining balance or money withdraw(self, amount) - this will withdraw an amount from the Account deposit(self, amount) - this will deposit an amount from the Account # (Optional) You may add more methods like sendMoney() etc. 4. Create a method for “Bank” class: addAccount(self, account) – used to register an account to the bank # (Optional) You may add more methods for your convenience 4. Create 3 Account objects with the following attributes in the main method account1 - id=(any number), name=(Any Name You Want), balance=7000 (strictly use this value) account2 - id=(any number), name=(Any Name You Want), balance= (any amount) account3 -…arrow_forward
- python Cylinder class: Instance variables: Make instance variables appropriately to accomplish the tasks you need. Methods: ?_init_ :: constructor, initializes instance variables o Additional Parameters: diameter and height (in that order) o Assumption: diameter and height will always be numbers which represent measurements in millimeters o Temporary Assumption (we will fix this later): diameter will never be negative and height wilI always be positive number above o ? get_volume : returns the volume of the cylinder based on its height o Additional Parameters: No additional parameters (just self). .0 Note: Use pi from the math module ?_str__ :: returns string representation with this format: "Cylinder (radius: 20.25mm, thickness: 6.10mm, volume: 7858.32mm^3)" o Additional Parameters: No additional parameters. o Notes: ? The quotes in the example are just our string boundaries! The first character in the above example is C. ? This method reports the radius (NOT the diameter). ? All…arrow_forwardC# LANGUAGE Create a method named getCircleDiameter that takes a radius of double type as the parameter. The method should return the diameter of a circle. To compute the diameter of a circle, multiply the radius by 2.arrow_forwardAssignment: Dice Rolling Program Objective: Create a Java program that rolls two dice and displays the results. The program should have two Java classes: one for a single die and another for a pair of dice. Assignment Details: User Input: Ask the user to specify the number of sides they want on each die. Ensure that the user's input is within a reasonable range. Dice Rolling: Simulate rolling the dice using Math.random() based on the user's chosen number of sides. Display the sum of the values rolled, e.g., "5 + 3 = 8." Special Combinations: If the dice roll results in combinations of 2, 7, or 12, print special messages: "1 + 1 = 2 snake eyes!" "3 + 4 = 7 craps!" "6 + 6 = 12 box cars!" Main Method: In the main method, create a pair of dice, roll them, and display the results. Allow the user to decide whether to continue rolling the dice or exit the program. Additional Features: You are welcome to add more features or enhancements to the program if desired. In…arrow_forward
- In PYTHON Design a class named Car that has the following fields: yearModel: The yearModel field is an integer that holds the car's year model (e.g, 1959). speed: The speed field is an integer that holds the car's current speed. In addition, the class should have the following constructor and other methods: Constructor: The constructor should accept the car's year model and speed as arguments. These values should be assigned to the object's yearModel and speed fields.The constructor should also assign 0 to the speed field. Accessors: Design appropriate accessor methods to get the values stored in an object's yearModel and speed fields. accelerate: The accelerate method should add 5 to the speed field each time is called. brake: The brake method should subtract 5 from the speed field each time it is called. Next, design a program that creates a Car object, and then calls the accelerate method five times. After each call to the accelerate method, get the current speed ofthe car and…arrow_forwardRetail StoreSuppose you have been consulted by a retail shop around your area to build a simple calculator. The calculator must be able to perform arithmetic operations (+, -, *, /) on integers. The program receives an expression from the user. The expression is structured as follows: integer input followed by an operator and another integer input from user prior to displaying the final result. Write a Java application that can perform the above expression. Create a method that takes two parameters and performs an arithmetic operation on the passed values. Your final output should consist of the expression and the result.arrow_forwardTrue or False: During method calls, the value of a local variable is preserved.arrow_forward
- Value-returning methods must pass parameters. -True or -Falsearrow_forwardQuestionarrow_forwardDesign the worst calculator ever: an application that accepts two numbers from the user and, when a button is pushed, performs a single operation and displays the results. You may choose: Multiplication, Division, Subtraction, square root, or raising the first number to the exponent of the second number. Don't use addition as we already did that in class. The result must be displayed to the user only when an appropriately labeled button is pushed.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,