Question

In: Computer Science

Step 1: Create a new Java project named ContainerPartyProject --------- Step 2: Add a ContainerParty class...

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:

  • brand
  • height
  • color

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:

  • radius

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=πradius2height

---------

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:

  • width
  • length

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=lengthwidthheight

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.

---------

Solutions

Expert Solution

/***************************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 :)


Related Solutions

Step 1: Create a new Java project called Lab5.5. Step 2: Now create a new class...
Step 1: Create a new Java project called Lab5.5. Step 2: Now create a new class called aDLLNode. class aDLLNode { aDLLNode prev;    char data;    aDLLNode next; aDLLNode(char mydata) { // Constructor data = mydata; next = null;    prev = null;    } }; Step 3: In the main() function of the driver class (Lab5.5), instantiate an object of type aDLLNode and print the content of its class public static void main(String[] args) { System.out.println("-----------------------------------------");    System.out.println("--------Create...
1. Create a new Java project called L2 and a class named L2 2. Create a...
1. Create a new Java project called L2 and a class named L2 2. Create a second class called ArrayExaminer. 3. In the ArrayExaminer class declare the following instance variables: a. String named textFileName b. Array of 20 integers named numArray (Only do the 1st half of the declaration here: int [] numArray; ) c. Integer variable named largest d. Integer value named largestIndex 4. Add the following methods to this class: a. A constructor with one String parameter that...
JAVA PROJECT Step 1: Create an application named YourInitials_Project 3 that uses a class to convert...
JAVA PROJECT Step 1: Create an application named YourInitials_Project 3 that uses a class to convert number grades to letter grades and another class for data validation. Make comments including your name, date, and project name as well as appropriate comments throughout your application that include the step number. Step 2: Create code to print Titles Step 3: Create a variable to hold user’s choice. Remember that all variables must begin with your initials and should be descriptive. Step 4:...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class named Employee. In the Employee class: Add the following private instance variables: name (String) job (String) salary (double) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. (Refer to the Tutorial3 program constructor if needed to remember how to do this.) Add a public String method named getName (no parameter) that...
Create a Java project called 5 and a class named 5 Create a second new class...
Create a Java project called 5 and a class named 5 Create a second new class named CoinFlipper Add 2 int instance variables named headsCount and tailsCount Add a constructor with no parameters that sets both instance variables to 0; Add a public int method named flipCoin (no parameters). It should generate a random number between 0 & 1 and return that number. (Important note: put the Random randomNumbers = new Random(); statement before all the methods, just under the...
Create a new Java project called lab1 and a class named Lab1 Create a second class...
Create a new Java project called lab1 and a class named Lab1 Create a second class called VolumeCalculator. Add a static field named PI which = 1415 Add the following static methods: double static method named sphere that receives 1 double parameter (radius) and returns the volume of a sphere. double static method named cylinder that receives 2 double parameters (radius & height) and returns the volume of a cylinder. double static method named cube that receives 1 double parameter...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class,...
Java Language -Create a project and a class with a main method, TestCollectors. -Add new class, Collector, which has an int instance variable collected, to keep track of how many of something they collected, another available, for how many of that thing exist, and a boolean completist, which is true if we want to collect every item available, or false if we don't care about having the complete set. -Add a method addToCollection. In this method, add one to collected...
open up a new Java project on Eclipse named Review and create a new class called...
open up a new Java project on Eclipse named Review and create a new class called Review.java. Copy and paste the below starter code into your file: /** * @author * @author * CIS 36B */ //write your two import statements here public class Review {        public static void main(String[] args) { //don't forget IOException         File infile = new File("scores.txt");         //declare scores array         //Use a for or while loop to read in...
in java Create a class called Customer in three steps: • (Step-1): • Add a constructor...
in java Create a class called Customer in three steps: • (Step-1): • Add a constructor of the class Customer that takes the name and purchase amount of the customer as inputs. • Write getter methods getName and getPrice to return the name and price of the customer. You can write a toString() method which returns printed string of Customer name and its purchase. • (Step-2): Create a class called Restaurant. • Write a method addsale that takes customer name...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT