Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete ManageWarehouse Application (Combining Part, AssembledPart, RetailCustomer and WholesaleCustomer objects) Overview : This section requires you to extend the Part and Assembled subclass to create

Complete ManageWarehouse Application

(Combining Part, AssembledPart, RetailCustomer and WholesaleCustomer objects)

Overview: This section requires you to extend the Part and Assembled subclass to create a Parts Warehouse application. The Parts warehouse application must take into account discounts applicable to wholesale and retail customers when performing transactions and allow all the data to be persisted in files.

You are required to extend the Part and derived classes to handle exceptions as well as develop three other classes and outlined below (details follow).

Part ICreate the Customer abstract class and its subclasses

Part IIAn Exception class named PartShortException for handling parts shortage

Part III An application class named ManageWarehouse combining Part, Customer and Exception classes to implement the required functionality.

Part IIIIReport

Report ( 2 page report ) : explain and demonstrate your code using the submitted assignment

describe ways in which it can be extended to handle new requirements

Learning Objective: This application provides the context to use an abstract class (for Customer), creating classes and methods for exception handling and file storage and writing a controller class that allow different objects to interact together to carry out the business rules.

Part I:Customer and subclasses

Customer class (abstract)

All customers have a unique ID and name. All customers are offered discounts based on the value of transactions though the method of computing discount differs for retail and wholesale customers. In this part you are required to write the abstract class named Customer with:

(i)Instance variables ID and name

(ii)Constructor taking as arguments the value for ID and name

(iii)An abstract method named getDiscount() to take as argument a double value for amount and to return a double (value for discount offered).

(iv)Appropriate accessors for the instance variables.

Subclass RetailCustomer

All retail customers are offered a discount based on a flat rate, which may vary from one to another reflecting the relationship with the customer. For example, if the rate is 0.04 (4%) then the discount offered for a sale of $5000 is

$200 ( 5000 * 0.04 ). In this part you are required to write the class RetailCustomer (extending Customer) with:

(i)Instance variable for rate of discount

(ii)Constructor taking as arguments values for ID, name and rate

(iii)Implementation for the method getDiscount() method which takes a double value (the transaction amount) and to returns a double (the discount offered), declared in the superclass Customer

(iv)Appropriate accessors for the instance variables.

Subclass WholesaleCustomer

All wholesale customers are offered a discount based on two rates, one for amounts up to $1,000 (inclusive) and one for the amounts exceeding 1,000. These rates may vary from one to another reflecting the relationship with the customer. For example, if the rate for amount exceeding $1000 is 0.08 (8%) then the discount offered for a sale of

$5000 is $400 ( 5000 * 0.08 ). In this part you are required to write the class WholesaleCustomer extending Customer

with:

(i)Instance variables for discount rates rate1 and rate2.

(ii)Constructor taking as arguments values for ID, name and the rates.

(v)Implementation for the method getDiscount() method which takes a double value (the transaction amount) and to returns a double (the discount offered), declared in the superclass Customer.

(iv)Appropriate accessors for the instance variables.

Part II: Exception class PartShortException

A PartShortException must be thrown when the quantity required exceeds the maximum number of items that can be supplied. This class should have instance variables for storing the quantity-available (current stock-level) and the error- message. The constructor for this class should allow users to pass the error-message (a String) and the quantity-available (current stock-level) as arguments.

(i)Create a class named PartShortException extending the Exception class with instance variables for error- message and quantity-available.

(ii)Provide a constructor taking as arguments, values for the error-message, and the actual quantity available.

(iii)Provide appropriate accessors for these instance variables.

(iv)Modify the supply method (in Part and its subclass developed in your previous assignment) to throw this exception (instead of returning -1) when an attempt is made to supply more items than are available. You are also expected to catch the exception and report the error message.

Part III: Controller class for Managing Warehouse operations

In addition, ManageWarehouse must save Part and Customer objects in files before exiting, and recreate them when restarting the program. All the Customer (and subclass) objects should be stored in a file named customers.txt and all the Part (and subclass) objects should be stored in a file named parts.txt. ManageTransactions must also incorporate exception handling.

1.Add-Part

Users should be prompted to enter the Part details. Depending on user input a new Part or AssembledPart object should be created and added to the array of Part objects. Ensure no two parts have the same ID.

2.Add new Customer

User should be prompted to enter the details of new customers. In response a new Customer (either Retail or Wholesale) subclass object should be created and added to the array storing Customer objects. Ensure no two customers have the same ID.

3.Perform Transactions

The users should be allowed to perform the following transactions. You may write separate methods for each of this activity. The transactions should capture the transaction ID (can be auto generated), date of transaction, type of transaction and the number of items replenished or supplied. If the transaction type is supply, the discount and cost after discount should be captured.

a.Replenish stock for specified part

b.Supply required number of parts to specified customer

Option for replenishing stock should prompt user to enter the ID and quantity. Option for supplying should request user to enter the ID for Part, the ID for Customer and the quantity to be supplied. The amount to be charged must take into account the discount available for the given customer and must be displayed in the console. To check the stock-level users must be prompted to enter the Part ID.

Input validation must be performed printing appropriate error messages for incorrect ID, etc. Exceptions relating to insufficient stock must be caught and handled. When exiting the program, all valid replenish and supply transaction details must be appended to a file named transactions.txt in the format below, for auditing purpose.

4.View Submenu

This submenu should provide an option to view details of all the parts, customers and transactions. Secondly this submenu should also allow specific part, customer or transaction details to be viewed based on ID. Thirdly it should allow viewing of all transactions by specific customers between the user supplied dates.

5.Reading and Writing

This option should be called automatically before exiting the program to allow objects (both Customer and Part) stored in arrays (main memory) to be saved to a text file. When the program is launched again, the objects must be recreated from the information in the same text file. This may require you to write the IDs of base Parts for assembled Parts when storing the data. You may also choose to write Customer and Part objects to separate files.

4.Submission

Submit one file ProgFunAssignment.java showing the final version of your program via. It is the responsibility of the student to correctly submit their files. Please verify that your submission is correctly submitted by downloading what you have submitted to see if the files include the correct contents.

Code must be compiled under command line with no error,

>javac ManageWarehouse.java

and runnable under command line

> java ManageWarehouse

Report ( 2 page report )

explain and demonstrate your code using the submitted assignment

describe ways in which it can be extended to handle new requirements.

I.Assignment (Weeks 1-12)

A.Functional Aspects

All the required functionality for the Part, AssembledPart, Customer, RetailCustomer, WholesaleCustomer, PartShortException and ManageWarehouse (implementing all the required functionality) together will be awarded 28 marks.

B.Non-functional Aspects

Appropriate Identifiers, Good Modularity (avoiding repetitive code) and Adequate Documentation

Appropriate prompts, Adequate exception handling and Thorough Input Validation

Brief Report on Strengths and Weaknesses of Procedural and Object-Oriented Programming for extensibility, maintainability and reusability.

Complete ManageWarehouse Application

(Combining Part, AssembledPart, RetailCustomer and WholesaleCustomer objects)

Overview: This section requires you to extend the Part and Assembled subclass to create a Parts Warehouse application. The Parts warehouse application must take into account discounts applicable to wholesale and retail customers when performing transactions and allow all the data to be persisted in files.

You are required to extend the Part and derived classes to handle exceptions as well as develop three other classes and outlined below (details follow).

Part ICreate the Customer abstract class and its subclasses

Part IIAn Exception class named PartShortException for handling parts shortage

Part III An application class named ManageWarehouse combining Part, Customer and Exception classes to implement the required functionality.

Part IIIIReport

Report ( 2 page report ) : explain and demonstrate your code using the submitted assignment

describe ways in which it can be extended to handle new requirements

Learning Objective: This application provides the context to use an abstract class (for Customer), creating classes and methods for exception handling and file storage and writing a controller class that allow different objects to interact together to carry out the business rules.

Part I:Customer and subclasses

Customer class (abstract)

All customers have a unique ID and name. All customers are offered discounts based on the value of transactions though the method of computing discount differs for retail and wholesale customers. In this part you are required to write the abstract class named Customer with:

(i)Instance variables ID and name

(ii)Constructor taking as arguments the value for ID and name

(iii)An abstract method named getDiscount() to take as argument a double value for amount and to return a double (value for discount offered).

(iv)Appropriate accessors for the instance variables.

Subclass RetailCustomer

All retail customers are offered a discount based on a flat rate, which may vary from one to another reflecting the relationship with the customer. For example, if the rate is 0.04 (4%) then the discount offered for a sale of $5000 is

$200 ( 5000 * 0.04 ). In this part you are required to write the class RetailCustomer (extending Customer) with:

(i)Instance variable for rate of discount

(ii)Constructor taking as arguments values for ID, name and rate

(iii)Implementation for the method getDiscount() method which takes a double value (the transaction amount) and to returns a double (the discount offered), declared in the superclass Customer

(iv)Appropriate accessors for the instance variables.

Subclass WholesaleCustomer

All wholesale customers are offered a discount based on two rates, one for amounts up to $1,000 (inclusive) and one for the amounts exceeding 1,000. These rates may vary from one to another reflecting the relationship with the customer. For example, if the rate for amount exceeding $1000 is 0.08 (8%) then the discount offered for a sale of

$5000 is $400 ( 5000 * 0.08 ). In this part you are required to write the class WholesaleCustomer extending Customer

with:

(i)Instance variables for discount rates rate1 and rate2.

(ii)Constructor taking as arguments values for ID, name and the rates.

(v)Implementation for the method getDiscount() method which takes a double value (the transaction amount) and to returns a double (the discount offered), declared in the superclass Customer.

(iv)Appropriate accessors for the instance variables.

Part II: Exception class PartShortException

A PartShortException must be thrown when the quantity required exceeds the maximum number of items that can be supplied. This class should have instance variables for storing the quantity-available (current stock-level) and the error- message. The constructor for this class should allow users to pass the error-message (a String) and the quantity-available (current stock-level) as arguments.

(i)Create a class named PartShortException extending the Exception class with instance variables for error- message and quantity-available.

(ii)Provide a constructor taking as arguments, values for the error-message, and the actual quantity available.

(iii)Provide appropriate accessors for these instance variables.

(iv)Modify the supply method (in Part and its subclass developed in your previous assignment) to throw this exception (instead of returning -1) when an attempt is made to supply more items than are available. You are also expected to catch the exception and report the error message.

Part III: Controller class for Managing Warehouse operations

In addition, ManageWarehouse must save Part and Customer objects in files before exiting, and recreate them when restarting the program. All the Customer (and subclass) objects should be stored in a file named customers.txt and all the Part (and subclass) objects should be stored in a file named parts.txt. ManageTransactions must also incorporate exception handling.

1.Add-Part

Users should be prompted to enter the Part details. Depending on user input a new Part or AssembledPart object should be created and added to the array of Part objects. Ensure no two parts have the same ID.

2.Add new Customer

User should be prompted to enter the details of new customers. In response a new Customer (either Retail or Wholesale) subclass object should be created and added to the array storing Customer objects. Ensure no two customers have the same ID.

3.Perform Transactions

The users should be allowed to perform the following transactions. You may write separate methods for each of this activity. The transactions should capture the transaction ID (can be auto generated), date of transaction, type of transaction and the number of items replenished or supplied. If the transaction type is supply, the discount and cost after discount should be captured.

a.Replenish stock for specified part

b.Supply required number of parts to specified customer

Option for replenishing stock should prompt user to enter the ID and quantity. Option for supplying should request user to enter the ID for Part, the ID for Customer and the quantity to be supplied. The amount to be charged must take into account the discount available for the given customer and must be displayed in the console. To check the stock-level users must be prompted to enter the Part ID.

Input validation must be performed printing appropriate error messages for incorrect ID, etc. Exceptions relating to insufficient stock must be caught and handled. When exiting the program, all valid replenish and supply transaction details must be appended to a file named transactions.txt in the format below, for auditing purpose.

4.View Submenu

This submenu should provide an option to view details of all the parts, customers and transactions. Secondly this submenu should also allow specific part, customer or transaction details to be viewed based on ID. Thirdly it should allow viewing of all transactions by specific customers between the user supplied dates.

5.Reading and Writing

This option should be called automatically before exiting the program to allow objects (both Customer and Part) stored in arrays (main memory) to be saved to a text file. When the program is launched again, the objects must be recreated from the information in the same text file. This may require you to write the IDs of base Parts for assembled Parts when storing the data. You may also choose to write Customer and Part objects to separate files.

4.Submission

Submit one file ProgFunAssignment.java showing the final version of your program via. It is the responsibility of the student to correctly submit their files. Please verify that your submission is correctly submitted by downloading what you have submitted to see if the files include the correct contents.

Code must be compiled under command line with no error,

>javac ManageWarehouse.java

and runnable under command line

> java ManageWarehouse

Report ( 2 page report )

explain and demonstrate your code using the submitted assignment

describe ways in which it can be extended to handle new requirements.

I.Assignment (Weeks 1-12)

A.Functional Aspects

All the required functionality for the Part, AssembledPart, Customer, RetailCustomer, WholesaleCustomer, PartShortException and ManageWarehouse (implementing all the required functionality) together will be awarded 28 marks.

B.Non-functional Aspects

Appropriate Identifiers, Good Modularity (avoiding repetitive code) and Adequate Documentation

Appropriate prompts, Adequate exception handling and Thorough Input Validation

Brief Report on Strengths and Weaknesses of Procedural and Object-Oriented Programming for extensibility, maintainability and reusability.

********************************************************************************************

Code is as follows:

Part.java

AssembledPart.java

TestAssembledPart.java

Explanation:

Part.java

***********************************************************************************************************************

public class Part {

private String ID; //private instance variables as given

private String name;

private int stockLevel;

private double unitPrice;

//Constructor as mentioned in question

public Part(String iD, String name, int stockLevel, double unitPrice) {

ID = iD;

this.name = name;

this.stockLevel = stockLevel;

this.unitPrice = unitPrice;

}

//accessors for every instance

public String getID() {

return ID;

}

public String getName() {

return name;

}

public int getStockLevel() {

return stockLevel;

}

public double getUnitPrice() {

return unitPrice;

}

//method replenish

public void replenish(int qty) {

this.stockLevel += qty; //add the qty in the stock level

}

//method supply

public double supply(int qty) {

if(qty<=stockLevel) { //if qty less than or equal to stockLevel

stockLevel -= qty; //decrease the qty

return qty*unitPrice; //return the supply amount

}

return -1; //else return -1

}

}

***********************************************************************************************************************

AssembledPart.java

***********************************************************************************************************************

public class AssembledPart extends Part {

private Part part1; //two additional instance variables for Part reference

private Part part2;

//constructor with id ,name,items,cost and two reference

public AssembledPart(String iD, String name, int existingAssembledItems, double assemblyCost,Part part1,Part part2) {

super(iD,name,existingAssembledItems,assemblyCost+part1.getUnitPrice()+part2.getUnitPrice()); //call super class constructor

this.part1 = part1; //initialize part objects

this.part2 = part2;

}

//method getAvail for assembly

public int getAvailForAssembly() {

if(part1.getStockLevel()

return part1.getStockLevel();

}

return part2.getStockLevel();

}

public double getCost() {

return this.getUnitPrice(); //get the cost of the assembled part

}

@Override

public double supply(int qty) { //override supply method

double supply = super.supply(qty); //first call the superclass method and if supply is -1

if (supply == -1) {

int stockLevel = super.getStockLevel(); //get the stock level

if(qty<=getAvailForAssembly()+stockLevel) { //if quantity is less than sum of avialable for assembly and stock level

part1.supply(qty-stockLevel); //suply from part1

part2.supply(qty-stockLevel); //supply from part2

return super.supply(stockLevel) + (qty-stockLevel)*this.getUnitPrice(); //return the sum of stock price and additonal that is assembled

}

else {

return -1; //else return -1

}

}

else {

return supply; //else return supply

}

}

}

TestAssembledPart.java

***********************************************************************************************************************

//Test class

public class TestAssembledPart {

public static void main(String args[]) {

// Constructing two Part objects (the base parts)

Part part0 = new Part("p101", "Crank", 218, 12.20);

Part part1 = new Part("p102", "Pedal", 320, 14.30);

// Constructing AssembledPart object assembled from p101 & p102

AssembledPart part2 = new AssembledPart("p183", "Crank & Pedal", 80, 3.50, part0, part1);

System.out.println("Unit Cost of " + part2.getID() + " = " + part2.getCost());

// replenishing stock by 100 items

part2.replenish(100);

// Supplying the maximum possible assembled parts - combination

// of existing parts and base parts available for assembly

System.out.println("Supplying max number of (assembled) parts");

int totalAvail = part2.getStockLevel() + part2.getAvailForAssembly();

double cost = part2.supply(totalAvail);

if (cost > 0)

System.out.println(part2.getID() + " Total cost for " + totalAvail + " items = " + cost);

else

System.out.println(part2.getID() + " Insufficient parts to supply " + totalAvail);

// printing the stock level for assembled and base parts

System.out.println(part0.getID() + " (base part) Available qty=" + part0.getStockLevel());

System.out.println(part1.getID() + " (base part) Available qty=" + part1.getStockLevel());

System.out.println(part2.getID() + " (assembled) Available qty=" + part2.getStockLevel());

// Attempting to supply another 10 items (bound to fail)

System.out.println("Trying to supply another 10 parts");

int qty = 10;

cost = part2.supply(qty);

if (cost > 0)

System.out.println(part2.getID() + " Total cost for " + qty + " items = " + cost);

else

System.out.println(part2.getID() + " Insufficient parts to supply " + qty);

}

}

***********************************************************************************************************************

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managerial Accounting

Authors: Susan V. Crosson, ‎ Belverd E. Needles

11th Edition

0538742801, 978-0538742801

More Books

Students also viewed these Accounting questions