Question

Exercise 1: A circle is defined by its radius (we are not interested in its center)....

Exercise 1:
A circle is defined by its radius (we are not interested in its center). A cylinder is defined by circle and height.
 Design and implement a class called Circle that has the necessary attributes to describe it and at least the following member methods: setRadius( ), getRadius( ), Circumference( ), Area( ), Display( ), and two constructors, one is parameterized constructor and another empty constructor with default zero value.  Design and implement a class called Cylinder that has the necessary attributes to describe it and at least the following member methods: setHeight( ), getHeight( ), setBase(), getBase(), Area( ), Volume( ), Display( ), and two constructors, one is parameterized constructor and another empty constructor with default zero values. Write a test program where you do the following:  Instantiate 2 different objects of type Circle with the following details: o circle1 attributes: 2.5 o circle2 attributes: no details given  Instantiate 2 different objects of type Cylinder with the following details: o cylinder1 attributes: 2.5, 5 o cylinder2 attributes: no details given  Set the data of the second circle to some new data to be read from the keyboard.  Set the data of the second cylinder to some new data to be read from the keyboard.  Print the details of circle1  Print the details of cylinder2  Two cylinders are equivalent if they can hold the same volume. Check if cylinder1 is equivalent to cylinder2.  Two cylinders are the same if they the same volume and the same area. Check if cylinder1 is same to cylinder2.
Hints: Circle area is:  radius2 (use Math.PI) Circle circumference is: 2  radius
Cylinder area is: 2  radius2 + 2  radius height =
2 * Circle area + Circle circumference * height Cylinder volume is:  radius2 height = Circle area * height
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*

*/
package circle;

import static javax.swing.Spring.height;

public class Circle {
int radius;
public int setRadius(){
return radius;
}
public int getRadius(){
return radius;
}
public float Circumference(float r){
return (float) (2*(Math.PI))*r;
}
public float Area(float radius){
return (float) (radius*radius*(Math.PI));
}
public static void Display(){
System.out.print(" ");
}

public static void main(String[] args) {
Circle c=new Circle();
c.Area((float) 2.5);
c.Circumference((float) 2.5);
Circle.Display();
}
public static class Cylinder{
int Height;
int Base;
public int setHeight(){
//int setHeight = 0;
return Height;
}
public int getHeight(){
return Height;
}
public int setBase(){
//int setBase = 0;
return Base;
}
public int getBase(){
return Base;
}

public float Area(float r,float h){
return (float) ((float) (2*(Math.PI))*r*r+(2*(Math.PI))*r*h);
}
public float Volume(float r,float h){
return h*(float)(Math.PI)*r*r;
}
public static void Display(){
System.out.println(" ");
}
public static void main(String []args){
Cylinder c1=new Cylinder();
c1.Area((float) 2.5, 5);
c1.Volume((float) 2.5, 5);
Cylinder.Display();

}
}
}

Add a comment
Know the answer?
Add Answer to:
Exercise 1: A circle is defined by its radius (we are not interested in its center)....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ code For each of the following classes create default constructor and parameterized constructors(calling parent(s) parameterized...

    C++ code For each of the following classes create default constructor and parameterized constructors(calling parent(s) parameterized constructors where it applies Add accessor and mutator function for the attribute inherent to the class Create a Base class called Shape2d with the protected floating point attribute area operator overload the + & - and operations to return the float respective to the area Derive from the Base class from called Shape2d called Rectangle with the additional floating-point attributes length & width Derive...

  • C++ Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add t...

    C++ Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in chapter 10.   Some of the...

  • Exercise 2: There can be several constructors as long as they differ in number of parameters...

    Exercise 2: There can be several constructors as long as they differ in number of parameters or data type. Alter the program so that the user can enter just the radius, the radius and the center, or nothing at the time the object is defined. Whatever the user does NOT include (radius or center) must be initialized somewhere. There is no setRadius function and there will no longer be a setCenter function. You can continue to assume that the default...

  • Using separate files, write the definition for a class called Point and a class called Circle. Th...

    Using separate files, write the definition for a class called Point and a class called Circle. The class point has the data members x (double) and y (double) for the x and y coordinates. The class has the following member functions: a) void set_x(double) to set the x data member b) void set_y(double) to set the y data member c) double get_x() to return the the x data member d) double get_y() to return the the y data member e)...

  • Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve...

    Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve breaking the problem down into multiple classes that can be tied together into a single solution. In this project, you are given the task of writing some classes that would work together for providing a solution to a problem involving some basic computations. Learning Objectives The focus of this assignment is on the following learning objectives: • Be able to identify the contents of...

  • Part 1: Use principles of inheritance to write code calculating the area, surface area, and volume...

    Part 1: Use principles of inheritance to write code calculating the area, surface area, and volume of rectangular objects. First, write an abstract super class RectangularShape, then write a subclass Rectangle that inherits from the super class to compute areas of rectangles, including squares if there is only one data. Finally, write another subclass Cuboid that inherits from its super class Rectangle above to compute surface areas and volumes of cuboids, including 3 equal sided cube. Must apply code-reusability in...

  • Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the c...

    C++ Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...

  • Project 7: Vehicles 1 Objective In the last couple projects, you’ve created and used objects in...

    Project 7: Vehicles 1 Objective In the last couple projects, you’ve created and used objects in interesting ways. Now you’ll get a chance to use more of what objects offer, implementing inheritance and polymorphism and seeing them in action. You’ll also get a chance to create and use abstract classes (and, perhaps, methods). After this project, you will have gotten a good survey of object-oriented programming and its potential. This project won’t have a complete UI but will have a...

  • Written in python using puTTy!! i'm having a lot of trouble with this, will upvote! also...

    Written in python using puTTy!! i'm having a lot of trouble with this, will upvote! also here is the address.csv file Name,Phone,Email,Year_of_Birth Elizi Moe,5208534566,[email protected],1978 Ma Ta,4345667345,[email protected],1988 Diana Cheng,5203456789,[email protected],1970 ACTIVITY I Implement in Python the Subscriber class modeled by the UML diagram provided below. Save in a file called MyClasses.py Subscriber name: string yearOfBirth: int phone: string email: string getName() getAge() getPhone() getEmail() Write a test program that does the following: Read the file addresses.csv. For each record, create an object...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT