Write a Java program with the following requirements:
Rectangle that implements Shape2D
- instance variables height, width
Block that implements Shape3D
- instance variables height, width, depth
Add appropriate parameterized constructors for each class.
Implement the abstract methods to make each class a Shape2D,
Shape3D, or both.
Make the main method use each of these to print out the area of
a rectangle, and the
area and volume of a block.
abstract class Shape
{
abstract void Shapes();
Shape()
{
System.out.println("Inside cosntructor of class Shape");
}
}
class Rectangle extends Shape
{
int height,width;
Rectangle(int h,int w)
{
System.out.println("Inside comstructor of class Rectangle");
height=h;
width=w;
}
void Shapes()
{
System.out.println("This is a 2D Shape ");
}
void Shape2D()
{
System.out.println("Area of 2D shape is "+(height*width));
}
}
class Block extends Shape
{
int height,width,depth;
void Shapes(){
System.out.println("This is a 3d Shape ");}
Block(int h,int w,int d)
{
height=h;width=w;depth=d;
System.out.println("Inside constructor of class Block");
}
void Shape3D()
{
System.out.println("Area of 3D shape is "+(height*width*depth));
}
}
public class Main {
public static void main(String[] args) {
Rectangle r=new Rectangle(10,5);
r.Shape2D();
Block b=new Block(10,5,2);
b.Shape3D();
}
}


Please upvote... Thanks
Write a Java program with the following requirements: Rectangle that implements Shape2D - instance variables height,...
IN JAVA For the following questions, “define a class” means the following: • Create an appropriately-named file containing the Java class definition, including the following: – A block comment describing the file (and hence the class), as always – Any instance variables, as required by the question – Accessor (getter) and mutator (setter) methods for any instance variables – Constructors as appropriate or as required by the question – A toString method that prints instances of the class informatively –...
Create a class called Retangle.java that contains two double-precision instance variables named width and height. The class should include all kinds of overloaded constructors. Additionally, there should be two accessor methods, mutator methods, class method named area() that returns the area of a Rectangle object. Inside main(),fully test all methods.
Within NetBeans, write a Java program for EACH of the following problems. (The Rectangle class) Following the example of the Circle class in Section 9.2, design a class named Rectangle to represent a rectangle. The class contains: · Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. · A no-arg constructor that creates a default rectangle. · A constructor that creates a...
****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...
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...
Write a program that meets the following requirements: Sandwich Class Create a class called Sandwich which has the following instance variables. No other instance variables should be used: - ingredients (an array of up to 10 ingredients, such as ham, capicola, American cheese, lettuce, tomato) -condiments (an array of up to 5 condiments, such as mayonnaise, oil, vinegar and mustard) Create a two argument constructor Write the getters and setters for the instance variables Override the toString method using the...
For this question you must write a java class called Rectangle and a client class called RectangleClient. The partial Rectangle class is given below. (For this assignment, you will have to submit 2 .java files: one for the Rectangle class and the other one for the RectangleClient class and 2 .class files associated with these .java files. So in total you will be submitting 4 files for part b of this assignment.) // A Rectangle stores an (x, y) coordinate...
JAVA
1. Write a class called Rectangle that represents a rectangular two-dimensional region. Your Rectangle objects should have the following fields and methods: int width, int height Where width and height are the dimensions of the rectangle. Write accessor methods (i.e. getWidth(), getHeight()) that retrieve the values stored in the fields above. And mutator methods (i.e. setWidthl), setHeight() ) that change the field's values. Finally create a method called getAreal) that returns the area of the rectangle. Like we did...
Language is JAVA.
Clarification for the Shape class (highlighted):
The following requirements specify what fields you are expected
to implement in your Shape class;
- A private String color that specifies the color of the
shape
- A private boolean filled that specifies whether the shape is
filled
- A private date (java.util.date) field dateCreated that
specifies the date the shape was created Your Shape class will
provide the following constructors;
- A two-arg constructor that creates a shape
with...
JAVA design a class named Rectangle to represent a rectangle. The class contains: A method named getPerimeter() that returns the perimeter. Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with the specified width and height. A method named getArea() that returns the area of this rectangle. design...