In: Computer Science
Step 1: Create a new Java project named ContainerPartyProject
---------
Step 2: Add a ContainerParty class to your project. It should contain:
- The date of the party
- A list of people attending
- A list of containers at the party
- The address of the party (this can be either a String or a Class)
---------
Step 3: Add a Container class in your project. It should be an abstract class. Your Container class must be properly encapsulated and include the following attributes:
In addition to a constructor that allows you to set all of these values, it should include a getInfo() method and an abstract calculateVolume() method.
---------
Step 4: Add a CircularContainer class to your project. Your CircularContainer must be a subclass of your Container class. In addition to the attributes that it inherits from Container, CircularContainer should add the following attributes:
It should include a getInfo() method and a calculateVolume() method that override the versions of these methods from your parent class. You may use the following formula for volume:
volume=π⋅radius2⋅height
---------
Step 5: Add a RectangularContainer class to your project. Your RectangularContainer must be a subclass of your Container class. In addition to the attributes that it inherits from Container, RectangularContainer should add the following attributes:
It should include a getInfo() method and a calculateVolume() method that override the versions of these methods from your parent class. You may use the following formula for volume:
volume=length⋅width⋅height
Important: In steps 3 and 4, your getInfo() methods must use the super keyword to leverage the getInfo() method of its superclass (Container). Remember DRY - Don’t Repeat Yourself! You should not unnecessarily duplicate any code between getInfo() in your subclass and superclass!
---------
Step 6: Create a Person class with 3 attributes of your choice. Create attributes, methods, and constructors as necessary to complete the assignment.
---------
/***************************ContainerParty.java**********************/
import java.util.ArrayList;
/**
* The Class ContainerParty.
*/
public class ContainerParty {
/** The date. */
private String date;
/** The peoples. */
private ArrayList<Person> peoples;
/** The containers. */
private ArrayList<Container> containers;
/** The address. */
private String address;
/**
* Instantiates a new container party.
*
* @param date the date
* @param peoples the peoples
* @param containers the containers
* @param address the address
*/
public ContainerParty(String date,
ArrayList<Person> peoples, ArrayList<Container>
containers, String address) {
super();
this.date = date;
this.peoples = peoples;
this.containers = containers;
this.address = address;
}
/**
* Gets the date.
*
* @return the date
*/
public String getDate() {
return date;
}
/**
* Sets the date.
*
* @param date the new date
*/
public void setDate(String date) {
this.date = date;
}
/**
* Gets the peoples.
*
* @return the peoples
*/
public ArrayList<Person> getPeoples() {
return peoples;
}
/**
* Sets the peoples.
*
* @param peoples the new peoples
*/
public void setPeoples(ArrayList<Person>
peoples) {
this.peoples = peoples;
}
/**
* Gets the containers.
*
* @return the containers
*/
public ArrayList<Container> getContainers()
{
return containers;
}
/**
* Sets the containers.
*
* @param containers the new containers
*/
public void setContainers(ArrayList<Container>
containers) {
this.containers = containers;
}
/**
* Gets the address.
*
* @return the address
*/
public String getAddress() {
return address;
}
/**
* Sets the address.
*
* @param address the new address
*/
public void setAddress(String address) {
this.address = address;
}
}
/*******************************Container.java************************/
/**
* The Class Container.
*/
public abstract class Container {
/** The brand. */
private String brand;
/** The height. */
private double height;
/** The color. */
private String color;
/**
* Instantiates a new container.
*
* @param brand the brand
* @param height the height
* @param color the color
*/
public Container(String brand, double height, String
color) {
super();
this.brand = brand;
this.height = height;
this.color = color;
}
/**
* Gets the brand.
*
* @return the brand
*/
public String getBrand() {
return brand;
}
/**
* Gets the height.
*
* @return the height
*/
public double getHeight() {
return height;
}
/**
* Gets the color.
*
* @return the color
*/
public String getColor() {
return color;
}
/**
* Calculate volume.
*
* @return the double
*/
public abstract double calculateVolume();
/**
* Gets the info.
*
* @return the info
*/
public String getInfo() {
return "Brand: " + brand +
"\nHeight: " + height + "\nColor: " + color;
}
}
/*************************************CircularContainer.java*****************************/
/**
* The Class CircularContainer.
*/
public class CircularContainer extends Container {
/** The radius. */
private double radius;
/**
* Instantiates a new circular container.
*
* @param brand the brand
* @param height the height
* @param color the color
* @param radius the radius
*/
public CircularContainer(String brand, double height,
String color, double radius) {
super(brand, height, color);
this.radius = radius;
}
/**
* Gets the radius.
*
* @return the radius
*/
public double getRadius() {
return radius;
}
/*
* (non-Javadoc)
*
* @see Container#calculateVolume()
*/
@Override
public double calculateVolume() {
return Math.PI * radius *
radius;
}
/*
* (non-Javadoc)
*
* @see Container#getInfo()
*/
@Override
public String getInfo() {
return super.getInfo() +
"\nRadius: " + radius;
}
}
/*********************************RectangularContainer.java********************************/
/**
* The Class RectangularContainer.
*/
public class RectangularContainer extends Container {
/** The width. */
private double width;
/** The length. */
private double length;
/**
* Instantiates a new rectangular container.
*
* @param brand the brand
* @param height the height
* @param color the color
* @param width the width
* @param length the length
*/
public RectangularContainer(String brand, double
height, String color, double width, double length) {
super(brand, height, color);
this.width = width;
this.length = length;
}
/**
* Gets the width.
*
* @return the width
*/
public double getWidth() {
return width;
}
/**
* Gets the length.
*
* @return the length
*/
public double getLength() {
return length;
}
/*
* (non-Javadoc)
*
* @see Container#calculateVolume()
*/
@Override
public double calculateVolume() {
return length * width *
getHeight();
}
/*
* (non-Javadoc)
*
* @see Container#getInfo()
*/
@Override
public String getInfo() {
return super.getInfo() +
"\nWidth: " + width + "\nLength: " + length;
}
}
/*******************************Person.java***********************/
/**
* The Class Person.
*/
public class Person {
/** The id. */
private String id;
/** The name. */
private String name;
/** The age. */
private int age;
/**
* Instantiates a new person.
*
* @param id the id
* @param name the name
* @param age the age
*/
public Person(String id, String name, int age) {
super();
this.id = id;
this.name = name;
this.age = age;
}
/**
* Gets the id.
*
* @return the id
*/
public String getId() {
return id;
}
/**
* Sets the id.
*
* @param id the new id
*/
public void setId(String id) {
this.id = id;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the age.
*
* @return the age
*/
public int getAge() {
return age;
}
/**
* Sets the age.
*
* @param age the new age
*/
public void setAge(int age) {
this.age = age;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return id + ", " + name + ", " +
age + "Years";
}
}
Please let me know if you have any doubt or modify the answer, Thanks :)