Question

In: Computer Science

Problem statement: You are tasked with writing a simple program that will keep track of items...

Problem statement:

You are tasked with writing a simple program that will keep track of items sold by a retail store. We need to keep track of the stock (or number of specific products available for sale).

Requirements:

  • The Food and Book items should inherit all the properties of the Product item in the previous assignment.

  • Foods cannot be added to the inventory without an expiration date.

  • Implement a toString method for Product, Food, and Book.

Grading details:

  • Correct usage of OOP concepts (80%)

    • Correct class design and usage of class instances (25%)

    • Correct implementation and usage of inheritance(25%)

    • Other supporting code/logic (30%)

  • Program runs/correct results (10%)

  • Formatting/Indentation (10%)


Starter code:

public class RetailInventory {
    public static void main(String[] args) {
        Product computer = new Product("Computer", 1400);
        Product iPhone = new Product("iPhone XR", 400, 600);
        Product Galaxy10 = new Product("Samsung Galaxy S10", 700, 900, "Phone with 128GB memory.");

        Product book = new Book("Starting out with C++", 150.00);

        Product apple = new Food("Fuji Apples", 3.50, "Dec. 1, 2019");

        Product[] inventory = {computer, iPhone, Galaxy10, book, apple};

        System.out.println("Viewing Store Products:");
        for (Product item: inventory) {
            System.out.println(item);
        }
    }
}


Sample output:


Viewing Store Products:



name: Computer, description: No description entered., wholesalePrice: $1400.00, retailPrice: $1540.00

name: iPhone XR, description: No description entered., wholesalePrice: $400.00, retailPrice: $440.00

name: Samsung Galaxy S10, description: Phone with 128GB memory., wholesalePrice: $700.00, retailPrice: $770.00

name: Starting out with C++, description: No description entered., wholesalePrice: $150.00, retailPrice: $165.00, author: Author_Placeholder

name: Fuji Apples, description: No description entered., wholesalePrice: $3.50, retailPrice: $3.85, expiration: Dec. 1, 2019

Solutions

Expert Solution

Given problem will have below 4 files as solution where each class has its own file (for a better understanding and encapsulation)

PROGRAM: There are below files in solution:

i. RetailInventory.java: Same as shared in problem, no change in it

ii. Product.java: parent class for products

iii. Food.java: Subclass for Product type food.

iv. Book.java: subclass for product type book.

Product.java:

public class Product {

                private String name;

                private String description;

                private double wholeSalePrice;

                private double retailPrice;

                public Product() {//default constructor

                               

                }

                public Product(String name, double wholeSalePrice) {//constructor with name and price

                                this.name = name;//set the instance variables as per the value passed

                                this.wholeSalePrice= wholeSalePrice;

                }

                public Product(String name, double       wholeSalePrice, double retailPrice) {//constructor with name and price

                                this.name = name;//set the instance variables as per the value passed

                                this.wholeSalePrice= wholeSalePrice;

                                this.retailPrice=retailPrice;

                }

                public Product(String name, double       wholeSalePrice, double retailPrice, String description) {//constructor with name and price

                                this.name = name;//set the instance variables as per the value passed

                                this.wholeSalePrice= wholeSalePrice;

                                this.retailPrice=retailPrice;

                                this.description=description;

                }

               

                private double getRetailPrice() {//this method will return the retailPrice as per the sample outpu

                               

                                retailPrice= wholeSalePrice+(wholeSalePrice*.10);//output shows that retailPrice is 10% addition to wholesaleprice

                                return retailPrice;

                }

               

                public String toString() {//print object details

                                if(description==null) {//if description is null, then print a message for description

                                                return "\nname: "+name+" , description: No description entererd., wholesalePrice: $"+wholeSalePrice+", retailPrice $"+getRetailPrice();

                                }

                                else {//otherwise print description value

                                return "\nname: "+name+" , description: "+description+", wholesalePrice: $"+wholeSalePrice+", retailPrice $"+getRetailPrice();

                                }//end else

                }//end toString                

}//end class

SCRENSHOT for indentation:

Book.java:

public class Book extends Product {

               

                private String author;

               

                public Book(String name, double wholeSalePrice) {// constructor gets name , price

                                super(name, wholeSalePrice);//pass the name and price to the super class product

                                author="Author_Placeholder";

                }

                public String toString() {

                                return super.toString()+", Author: "+author;//super will return the product details and author is added here

                }//end toString

}//end class

SCREENSHOT for indentation:

Food.java:

public class Food extends Product {

                private String date;

                public Food(String name, double wholeSalePrice, String date) { // constructor gets name , price and date

                                super(name, wholeSalePrice);//pass name and wholesale price to super class

                                this.date = date;//set date for local class instance variable date

                }

                public String toString() {//return the food details

                                return super.toString()+", expiration: "+date;//super will return the product details and expiration is added here

                }

}

SCREENSHOT for indentation

OUTPUT

Kindly comment, if you face issue in understanding code flow.


Related Solutions

Problem statement: You are tasked with writing a simple program that will keep track of items...
Problem statement: You are tasked with writing a simple program that will keep track of items sold by a retail store. We need to keep track of the stock (or number of specific products available for sale). Requirements: The program will now be broken up into methods and store all the inventory in an ArrayList object. The program will be able to run a report for all inventory details as well as a report for items that are low in...
You are tasked to design an application to keep track of sales for your company. Sales...
You are tasked to design an application to keep track of sales for your company. Sales should be tracked for two types of accounts: supplies and services. Complete the following:     Create a UML class diagram for the Account inheritance hierarchy. Your subclasses should be Supplies and Services.     All sales accounts will have an account ID (accountId).     You will need attributes to keep track of the number of hours (numberOfHours) and rate per hour of services provided (ratePerHour)....
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem...
PROGRAM LANGUAGE IN C, PLEASE KEEP IT SIMPLE EVEN IF IT IS REDUNDANT In this problem you will take a list of names from the user and sort them alphabetically using selection sort. The code for selection sort for integer is available in the "Lab and Weekly Coding Solution module" in webcourses. Ask the user how many names the user wants to input. Let's say the number be N. Then take N number of names and put them in an...
This is a simple list table of a company trying to keep track of parts that...
This is a simple list table of a company trying to keep track of parts that they sell and orders that came in purchasing those parts (in other words, not a database but a flat one table file). You will design a database for this company so that they won’t be relying on a simple 1 table list system to keep track of their data. Looking at the table below, produce the 3NF of the data. OrderNum OrderDate PartNum Description...
You will design a program to keep track of a restaurants waitlist using a queue implemented...
You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list. Make sure to read pages 1215-1217 and 1227-1251 1. Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables. 2. Add the following operations to your program: a. Return the first person in the queue b. Return the last person in the queue c. Add a person to...
You are going to create a console based program to keep track of a small business...
You are going to create a console based program to keep track of a small business that sells Doodads. First you will need to create a class Doodad that keeps track of two integers and two Strings. Next, create a constructor for the Doodad. Next, add getters and setters for each of the fields (two integers and two Strings). You need to use Doodad.java (see the starter code) Inside your main method ask the user to read in the two...
In this assignment, the program will keep track of the amount of rainfall for a 12-month...
In this assignment, the program will keep track of the amount of rainfall for a 12-month period. The data must be stored in an array of 12 doubles, each element of the array corresponds to one of the months. The program should make use of a second array of 12 strings, which will have the names of the months. These two arrays will be working in parallel. The array holding the month names will be initialized when the array is...
In python make a simple code. You are writing a code for a program that converts...
In python make a simple code. You are writing a code for a program that converts Celsius and Fahrenheit degrees together. The program should first ask the user in which unit they are entering the temperature degree (c or C for Celcius, and f or F for Fahrenheit). Then it should ask for the temperature and call the proper function to do the conversion and display the result in another unit. It should display the result with a proper message....
Write a c++ program for the Sales Department to keep track of the monthly sales of...
Write a c++ program for the Sales Department to keep track of the monthly sales of its salespersons. The program shall perform the following tasks: Create a base class “Employees” with a protected variable “phone_no” Create a derived class “Sales” from the base class “Employees” with two public variables “emp_no” and “emp_name” Create a second level of derived class “Salesperson” from the derived class “Sales” with two public variables “location” and “monthly_sales” Create a function “employee_details” under the class “Salesperson”...
ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a...
ASSIGNMENT: Write a program to keep track of the total number of bugs collected in a 7 day period. Ask the user for the number of bugs collected on each day, and using an accumulator, keep a running total of the number of bugs collected. Display the total number of bugs collected, the count of the number of days, and the average number of bugs collected every day. Create a constant for the number of days the bugs are being...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT