The program will skip erroneous lines in the file. After the instances are created and stored...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The program will skip erroneous lines in the file. After the instances are created and stored in an ArrayList, the program will allow user to perform the following operations repeatedly: 1 Search by length 2 Search by height 3 Quit Option 1 The program will prompt the user to enter a number (length) and display all instances with length >= the length entered by the user. The program will display an appropriate message if there is no matching instance. The program must handle incorrect data input: non-numeric input and invalid length (0 or negative). Option 2 The program will prompt the user to enter a number (height) and display all instances with height >= the height entered by the user. The program will display an appropriate message if there is no matching instance. The program must handle incorrect data input: non-numeric input and invalid height (0 or negative). Program Structure You may include additional classes as you deem fit. public class Question 3 { public static void main(String[] argv) { // Your code ... } } class Rectangle { // Your code } class Cuboid ... { // Your code } class Pyramid ... ( // Your code ... } Question 3 Write a Java program to allow user to create instances of Rectangle, Cuboid and Pyramid; and search the instances by different criteria. The details of the classes are given as follows: class Instance variables Constructor Get and set methods getArea toString Rectangle Length and width of a rectangle. You may decide the type of each instance variable. You may include additional variables as you deem fit. A non default constructor that receives parameters and initialises the instance variables. Include get and set methods for all instance variables. Instance method to calculate and return the rectangle's area, which is length x width. Return a descriptive String of the instance. class Instance variables Constructor Get and set methods getArea getVolume toString Cuboid (subclass of Rectangle) Height of a cuboid. You may decide the type of each instance variable. You may include additional variables as you deem fit. A non default constructor that receives parameters and initialises the instance variables, including the instance variables of the base class. Include get and set methods for all instance variables. Instance method to calculate and return the surface area (6 sides) of a cuboid. Instance method to calculate and return the volume of a cuboid, which is base area x height. Return a descriptive String of the instance. class Instance variables Constructor Get and set methods getVolume toString Pyramid (subclass of Rectangle) Height of a pyramid. You may decide the type of each instance variable. You may include additional variables as you deem fit. A non default constructor that receives parameters and initialises the instance variables, including the instance variables of the base class. Include get and set methods for all instance variables. Instance method to calculate and return the volume of a pyramid, which is (base area x height) / 3. Return a descriptive String of the instance. Note: The Pyramid class does not override the getArea method. The program must read a text file containing the instance data, create an appropriate instance (Rectangle, Cuboid or Pyramid) for each data, and store it in an ArrayList for subsequent use. A sample of the text file is shown below. C, 10.5, 20.5,30 P, 5, 10, 15.3 R, 2,5.5 P,2,5,10 C,5,A,20 P, 0,10,-1 C,8,10,15 You may assume the following regarding the values in the text file: There can be any number of lines in the text file. • The first value is either R (rectangle), C (cuboid) or P (pyramid). • Rectangle will have 2 values: length and width after R. • Cuboid will have 3 values: length, width and height after C. • Pyramid will have 3 values: length, width and height after P. ⚫ Length, width and height may contain invalid values: 0, negative or non-numeric. The program will skip erroneous lines in the file. After the instances are created and stored in an ArrayList, the program will allow user to perform the following operations repeatedly: 1 Search by length 2 Search by height 3 Quit Option 1 The program will prompt the user to enter a number (length) and display all instances with length >= the length entered by the user. The program will display an appropriate message if there is no matching instance. The program must handle incorrect data input: non-numeric input and invalid length (0 or negative). Option 2 The program will prompt the user to enter a number (height) and display all instances with height >= the height entered by the user. The program will display an appropriate message if there is no matching instance. The program must handle incorrect data input: non-numeric input and invalid height (0 or negative). Program Structure You may include additional classes as you deem fit. public class Question 3 { public static void main(String[] argv) { // Your code ... } } class Rectangle { // Your code } class Cuboid ... { // Your code } class Pyramid ... ( // Your code ... } Question 3 Write a Java program to allow user to create instances of Rectangle, Cuboid and Pyramid; and search the instances by different criteria. The details of the classes are given as follows: class Instance variables Constructor Get and set methods getArea toString Rectangle Length and width of a rectangle. You may decide the type of each instance variable. You may include additional variables as you deem fit. A non default constructor that receives parameters and initialises the instance variables. Include get and set methods for all instance variables. Instance method to calculate and return the rectangle's area, which is length x width. Return a descriptive String of the instance. class Instance variables Constructor Get and set methods getArea getVolume toString Cuboid (subclass of Rectangle) Height of a cuboid. You may decide the type of each instance variable. You may include additional variables as you deem fit. A non default constructor that receives parameters and initialises the instance variables, including the instance variables of the base class. Include get and set methods for all instance variables. Instance method to calculate and return the surface area (6 sides) of a cuboid. Instance method to calculate and return the volume of a cuboid, which is base area x height. Return a descriptive String of the instance. class Instance variables Constructor Get and set methods getVolume toString Pyramid (subclass of Rectangle) Height of a pyramid. You may decide the type of each instance variable. You may include additional variables as you deem fit. A non default constructor that receives parameters and initialises the instance variables, including the instance variables of the base class. Include get and set methods for all instance variables. Instance method to calculate and return the volume of a pyramid, which is (base area x height) / 3. Return a descriptive String of the instance. Note: The Pyramid class does not override the getArea method. The program must read a text file containing the instance data, create an appropriate instance (Rectangle, Cuboid or Pyramid) for each data, and store it in an ArrayList for subsequent use. A sample of the text file is shown below. C, 10.5, 20.5,30 P, 5, 10, 15.3 R, 2,5.5 P,2,5,10 C,5,A,20 P, 0,10,-1 C,8,10,15 You may assume the following regarding the values in the text file: There can be any number of lines in the text file. • The first value is either R (rectangle), C (cuboid) or P (pyramid). • Rectangle will have 2 values: length and width after R. • Cuboid will have 3 values: length, width and height after C. • Pyramid will have 3 values: length, width and height after P. ⚫ Length, width and height may contain invalid values: 0, negative or non-numeric.
Expert Answer:
Answer rating: 100% (QA)
The below is the JAVA code for the above problem import javaioFile import javaioFileNotFoundException import javautilArrayList import javautilScanner Rectangel class class Rectangle private double len... View the full answer
Related Book For
Understanding Business Ethics
ISBN: 9781506303239
3rd Edition
Authors: Peter A. Stanwick, Sarah D. Stanwick
Posted Date:
Students also viewed these programming questions
-
A 14-foot piece of string is cut into two pieces so that the longer piece is 2 feet longer than twice the shorter piece. Find the lengths of both pieces. What is the lenath of the shorter oiece?1...
-
Tam Worldly's weekly gross earnings for the week ended April 22 were $2,000, and her federal income tax withholding was $372.02. Assuming that the social security rate is 6% and Medicare is 1.5% of...
-
In June 2012, Front Row Entertainment had the opportunity to expand its venue operations by purchasing five different venues. To finance this purchase, they issued $1,500,000 of 6 percent, 5-year...
-
You and your uncle are fishing. You are using 22-N fishing line, which means the line can support that much tension without breaking. Your uncle challenges you to catch the biggest fish you can land...
-
Smithson Company Keith Smithson is the CEO of the Smithson Company, a privately owned, medium-size computer services company. The company is 20 years old and, until recently, had experienced rapid...
-
Answer this question with respect to the Naive Bayes Excel file included with this test. You have an Excel table below indicating a) whether or not a customer clicked on a banner Ad b) if the...
-
X is a patient of Dr. Y who has been diagnosed with Stage 2 Breast Cancer. As her condition requires urgent medical attention, X consented to schedule immediate operation on June 02, 2019 right after...
-
To what extent has Google's strategy focused upon its resources and capabilities rather than specific customer needs?
-
It takes Ben 2 days to write 5 reports, and it takes Kato 3 days to writo 5 reports. Ben's rate, in reports per day, is how much greater than Kate's rate?
-
Should all organizations empower employees to the extent that Nordstrom's, Ritz-Carlton hotels, and Google empower their employees? Why or why not?
-
The value of a business's fixed asset life ratio has increased in each of the last three years. What conclusion could you draw from this?
-
Can offline stores drive online Please discuss the following questions: Which factors should we consider while choosing a location for physical stores? What does a physical store do for the shopping...
-
1. Suppose the data in the table was taken from the function f (x) = xcos(x) x sin(x). Find the truncation error for forward difference. www O 16.15 4.1 4.2 O 16.45 O 17.15 f(x) 3.5 3.7 3.9 O 17.45...
-
Differentiate. y = ln(3x + 1) ln(5x + 1)
-
Which of the seven deadly sins do you believe is the most serious to commit? Which of the seven deadly sins do you believe is the least serious to commit? Do you think certain sins have gained or...
-
Examine the compliance program of a publicly held company. Does the company have a mission statement related to ethics? Comment on the program.
-
Established in 1961 by the United Nations and headquartered in Rome, Italy, the World Food Programme (WFP) is the largest humanitarian organization dedicated to eliminating world hunger. It costs 25...
-
The marginal tax rate on a corporate income of \(\$ 87,000\) is closest to which of the following? a. 15 percent b. 20.5 percent c. 25 percent d. 34 percent
-
True or False: If the same amount of money is invested in something that can be expensed as in something that must be depreciated (and both provide the same annual returns) then you should choose the...
-
True or False: If investment capital is borrowed, the income tax rate equals \(40 \%\), the after-tax MARR is \(12 \%\), and the loan rate is \(10 \%\), then it is best to repay the loan using Plan 4.
Study smarter with the SolutionInn App