Computers and Technology

In this lab exercise you will develop a class hierarchy of shapes and write a program that computes the amount of paint needed to paint different objects. The hierarchy will consist of a parent class Shape with three derived classes - Sphere, Rectangle, and Cylinder. For the purposes of this exercise, the only attribute a shape will have is a name and the method of interest will be one that computes the area of the shape (surface area in the case of three-dimensional shapes). Do the following. 1. Write an abstract class Shape with the following properties:
An instance variable shapeName of type String
An abstract method area()
A toString() method that returns the name of the shape
2. The file Sphere. java contains a class for a sphere which is a descendant of Shape.
A sphere has a radius and its area (surface area) is given by the formula 4*PI*radius^2.
Define similar classes for a rectangle and a cylinder. Both the Rectangle class and the Cylinder class are descendants of the Shape class.
A rectangle is defined by its length and width and its area is length*width.
A cylinder is defined by a radius and height and its area (surface area) is PI*radius^2*height.
Define the toString() method in a way similar to that for the Sphere class.
3. The file Paint. java contains a class for a type of paint (which has a "coverage" and a method to compute the amount of paint needed to paint a shape). Correct the return statement in the amount() method so the correct amount will be returned. Use the fact that the amount of paint needed is the area of the shape divided by the coverage for the paint. (NOTE: Leave the print statement - it is there for illustration purposes, so you can see the method operating on different types of Shape objects.)
4. The file PaintThings. java contains a program that computes the amount of paint needed to paint various shapes. A paint object has been instantiated. Add the following to complete the program:
Instantiate the three shape objects:
o deck to be a 20 by 35 foot rectangle,
o bigBall to be a sphere of radius 15, and
o tank to be a cylinder of radius 10 and height 30.
Make the appropriate method calls to assign the correct values to the three amount variables.
Run the program and test it. You should see polymorphism in action as the amount method computes the amount of paint for various shapes.

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 15:30, alexdub9649
What is a costume plot? why is it important to a film or theater production?
Answers: 2
image
Computers and Technology, 22.06.2019 20:00, hannahliebl2000
Need asap write a short paper describing the history and differences between six sigma, waterfall, agile, and scrum models. understanding these models can give you a good idea of how diverse and interesting it development projects can be. describe what the rationale for them is and describe their key features. describe the history behind their development. at least 400 words
Answers: 1
image
Computers and Technology, 22.06.2019 23:30, riah133
Creating "smart interfaces" in all sectors of industry, government, and the public arena is one of the fastest growing hct areas. these interfaces model, interpret, and analyze such human characteristics as speech, gesture, and vision. the field of biometrics, in which humans authenticate themselves to machines, is an area of considerable interest to hct practitioners. fingerprint scans are one of the most frequently used biometric options, and this article, biometric student identification: practical solutions for accountability & security in schools, makes a case for the implementation of fingerprint scans in schools. critique the article, and answer the following questions: according to the author, what are the main benefits of adopting fingerprint scans in schools for student identification? according to the author, what are the main drawbacks of adopting fingerprint scans in schools for student identification? do you agree with the author's assessment of the pl
Answers: 2
image
Computers and Technology, 24.06.2019 03:30, ava1018
The footer area of a web page generally houses which website feature? terms of use web page content business name or title menu headings
Answers: 1
Do you know the correct answer?
In this lab exercise you will develop a class hierarchy of shapes and write a program that computes...

Questions in other subjects:

Konu
Mathematics, 26.03.2020 20:32
Konu
Mathematics, 26.03.2020 20:32