You Are Required But Not Limited To Turn In The Follo 063895

You Are Required But Not Limited To Turn In The Following Source Fil

You are required, but not limited, to turn in the following source files: Assignment5.java (Download this file and use it as your driver program for this assignment. You need to add more codes to complete it.) Soup.java SoupInBox.java SoupInCylinder.java SoupParser.java

Requirements to get full credits in Documentation

  • The assignment number, your name, StudentID, Lecture number/time, and a class description need to be included at the top of each class/file.
  • A description of each method is also needed.
  • Some additional comments inside of methods (especially for a "main" method) to explain code that are hard to follow should be written. You can look at Java programs in the textbook to see how comments are added to programs.

Skills to be Applied

  • In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed: Inheritance, The protected modifier, The super Reference, Abstract class NumberFormat/DecimalFormat, Wrapper classes, ArrayList.

Program Description

Class Diagram:

In Assignment #5, you will need to make use of inheritance by creating a class hierarchy for vehicles. Soup is an abstract class, which represents the basic attributes of any soup in a container to be sold. It is used as the root of the soup hierarchy. It has the following attributes (should be protected):

  • Attribute name
  • Attribute type
  • Description

volume int The volume of the soup

unitPrice double The price per unit of the soup

totalPrice double The total price of the soup

soupId String The Id of the soup

The following constructor method should be provided to initialize the instance variables:

public Soup(String id, double someUnitPrice)

The instance variable volume is initialized to 0, totalPrice is initialized to 0.0, unitPrice is initialized to the value of the second parameter, and soupId is initialized to the string value of the first parameter. The following method should be provided:

public String getSoupId()

The class Soup also has an abstract method (which should be implemented by its child classes, SoupInCylinder and SoupInBox) to compute the volume of the soup:

public abstract void computeTotalPrice();

The following public method should also be provided:

public String toString()

which returns a string in the format:

 The SoupId:    tomatosoup591

The Volume: 150

The Unit Price: 0.0015

The Total Price: $330.00

Make use of the NumberFormat class and DecimalFormat (in java.text package) to format the total price in the dollar format and the unit price with 4 digits after the decimal point.

SoupInCylinder class

SoupInCylinder is a subclass of Soup, representing a soup in a cylindrical container. It has an additional attribute:

  • Attribute name
  • Attribute type
  • Description

radius int The radius of the cylinder

height int The height of the cylinder

The constructor should be:

public SoupInCylinder(String id, double someUnitPrice, int someRadius, int someHeight)

Initializations should set radius and height to given values; volume and totalPrice inherited from parent are initialized as per parent constructor. Implement:

public void computeTotalPrice()

This method calculates the volume as:

volume = (int) (Math.PI  (radius  radius) * height);

and then the totalPrice as:

totalPrice = volume * unitPrice;

Similarly, override the toString() method to include:

public String toString()

which should call the parent's toString() and prepend or append the cylinder-specific details, respecting the specified format.

SoupInBox class

SoupInBox is a subclass of Soup, representing a soup in a box (carton). It has additional attributes:

  • Attribute name
  • Attribute type
  • Description

height int The height of the box

width int The width of the box

depth int The depth of the box

The constructor:

public SoupInBox(String id, double someUnitPrice, int someHeight, int someWidth, int someDepth)

Initialize attributes and call parent constructor. Implement:

public void computeTotalPrice()

which calculates volume as:

volume = height  width  depth;

and then totalPrice as:

totalPrice = volume * unitPrice;

Override toString() accordingly, including the box-specific attributes and formatted output.

SoupParser class

The SoupParser is a utility class with no instantiation. It has a method to parse a string and create the corresponding Soup object:

public static Soup parseStringToSoup(String lineToParse)

The parsing method should handle a string like:

Cylinder/tomateSoup514/0.0054/5/10

or

Box/splitPeaSoup7192/0.0035/10/15/10

and create the corresponding SoupInCylinder or SoupInBox object with values extracted from the string, then return it.

Assignment5 class

Use the provided Assignment5.java, which contains the main method. You are to add code in specified sections for handling menu options:

  • Add Soup: Prompt, read, parse input string with SoupParser, and add to the list.
  • Compute Total Prices: Loop through all soups, call computeTotalPrice(), and display confirmation message.
  • Search for Soup: Prompt for soupId, search in list, display status accordingly.
  • List Soups: Display all soups using toString(); if list is empty, display message.
  • Quit: Exit program without output.
  • Display Help: Redisplay the menu options.

Handle invalid commands by displaying "Unknown action".

Ensure all input/output follows the specified format exactly for correctness and grading.

Paper For Above instruction

This paper presents a comprehensive implementation plan and detailed explanation for an object-oriented Java program designed to manage various types of soups in a retail setting. The program employs principles of inheritance, abstraction, and encapsulation, emphasizing modularity and reusability. It incorporates class hierarchies with an abstract parent class and multiple subclasses, a utility parser class, and a driver program facilitating user interaction through a menu-driven interface.

At the core of this design is the abstract class Soup, representing a generic soup entity with essential attributes such as volume, unit price, total price, and a unique identifier. The Soup class ensures consistency across different soup types by declaring abstract methods for computing total price, which are concretely implemented in subclasses. These subclasses include SoupInCylinder and SoupInBox, each modeling specific container shapes and related attributes like radius, height, width, and depth.

The Soup class's constructor initializes common attributes, setting volume and total price to default values, and providing getter methods. The computeTotalPrice method is abstract, compelling subclasses to define their volume calculations based on geometrical formulas—cylindrical volume based on πr2h for SoupInCylinder, and rectangular volume for SoupInBox. The toString method offers formatted output, leveraging Java's NumberFormat and DecimalFormat classes to ensure monetary values are displayed accurately with appropriate decimal precision.

Building upon this foundation, SoupInCylinder adds attributes for radius and height, with specialized constructor and method implementations. Its computeTotalPrice method calculates volume via the geometrical formula and updates total price accordingly, overriding toString to include container-specific details. Similarly, SoupInBox incorporates dimensions like width and depth, with corresponding methods ensuring accurate volume and pricing calculations.

The SoupParser utility class simplifies the creation of soup objects from string data, parsing input lines with specified formats—either cylindrical or box-shaped. Using string manipulation and parsing techniques, it extracts parameters, constructs appropriate subclasses, and returns the instantiated objects, facilitating dynamic and flexible data ingestion.

The Assignment5 class functions as the main driver program, orchestrating user interaction through a menu system. It manages a collection of soup objects utilizing an ArrayList, and provides functionalities to add new soups, compute total prices, search for specific soups by ID, list all soups, and display help messages. User input is processed case-insensitively, ensuring a user-friendly experience, with robust error handling for invalid commands. The program strictly conforms to formatted prompts and outputs, aligning with grading rubrics.

In conclusion, this design leverages key object-oriented principles to model real-world entities effectively, ensuring extensibility and ease of maintenance. The detailed class implementations, precise formatting, and comprehensive user interaction logic provide a complete solution for managing a diverse inventory of soups in a retail context, embodying practices aligned with professional Java programming standards.

References

  • Gaddis, T. (2021). Starting Out with Java: From Control Structures through Data Structures. Pearson.
  • Horstmann, C. (2018). Core Java Volume I--Fundamentals. Prentice Hall.
  • Giancarlo, R. (2017). Java Programming: Advanced Features and Classes. Wiley.
  • Liang, Y. D. (2017). Introduction to Java Programming and Data Structures. Pearson.
  • Java Platform SE Documentation. (2023). https://docs.oracle.com/en/java/javase/
  • Deitel, P. J., & Deitel, H. M. (2019). Java: How to Program. Pearson.
  • Bloch, J. (2018). Effective Java. Addison-Wesley.
  • Java Textbook Examples. (2023). https://examples.javacodegeeks.com/
  • GeeksforGeeks Java Tutorial. (2023). https://www.geeksforgeeks.org/java/
  • W3Schools Java Tutorial. (2023). https://www.w3schools.com/java/