Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Question #1 Write a program that creates two classes - Circle and Trapezoid. For each class, provide method getters and setters, method area() that

image text in transcribed

Java

Question \#1 Write a program that creates two classes - Circle and Trapezoid. For each class, provide method getters and setters, method area() that will calculate the area of the shape, and method toString( that will display the class name. Use private data fields. The constructor of each class should set a default value for each shape. For class Circle, set the default radius to 4 inches. For class Trapezoid set the default values to 15 inches for Base ' a ', 5 inches for Base ' b ', and 25 inches for the height (see diagram below as an example) Trapezoid Solve for area - A=2a+bh a Baso b Base h Height Using the Java ArrayList class and the loop concept, create five objects of the given shapes above. Which object to create and load into an array depends on your random number generator between 1 to 2 . If the random number is 1 , then using your default constructor create and load a Circle object into your ArrayList. If the random number is 2 , then using your default constructor create and load a Trapezoid object into your ArrayList. In your program, you are required to use Java ArrayList class to store your objects. Use the array declaration given below in your program: //Generic Arraylist with default capacity ArrayList arrayOfShapes = new ArrayList 0; 2 Using loop reiterates through your array of objects and call functions toString0 and area() to print the class name and its area. Use Math. random () to generate random numbers between 1 to 2

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions