In: Computer Science
You need to create a Java class library to support a program to simulate a Point- of-Sale (POS) system.
General Requirements:
You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand;
You should create identifiers with sensible names;
You should make comments to describe your code segments where they are necessary for
readers to understand what your code intends to achieve.
Logical structures and statements are properly used for specific purposes.
Program Requirements
You create three classes: ProductPrices, ShoppingCart and CashRegister in the filePOSLib.java to support a POS system implemented in the program POSmain.java, which is provided.
The POSmain program takes three file names from command line arguments. The first file contains a list of products and their prices; the second and third files are lists of items in two shopping carts of two customers. The POSmain program should first read the price file, then read each of the cart files to load a list of items in a shopping cart and store them in a ShoppingCartobjects. The price file may contain a variable number of products and the cart files may contain a variable number of items.
POSmain then will create a CashRegister object by passing the price list to it. The POSmainprogram then will use the CashRegister object to scan items in a cart and print a receipt for each shopping cart one by one. At last, POSmain will use the CashRegister object to print a report for the day.
The three classes you will create are described in the following UML design class diagrams. You must implement all specified fields and methods in the classes. You are free to add private fields and methods to CashRegister class if appropriate.
ProductPrices |
-products: ArrayList<String> -prices: ArrayList<Double> +put(String product, double price) +get(String product): double |
The put method will store the price for the product in the products and prices fields, respectively;
The get method will return the price for the product.
ShoppingCart |
-items: ArrayList<String> |
+addItem(String): void +getAllItems(): ArrayList<String> |
The addItem method will add the product to the shopping cart;
The getAllItems method will return all items in the shopping cart.
CashRegister |
-productPrices: ProductPrices ...... |
+CashRegister(ProductPrices) +scanAllItemsInCart(ShoppingCart): void +printReceipt(): void +printReportForTheDay(): void ...... |
The constructor will initialise the CashRegister object with the product prices;
The scanAllItemsInCart will examine all items in the shopping cart and prepare to
print the receipt for the shopping cart and report for the day;
The printReceipt method will print the product name, price, quantity, subtotal, and
total purchase for a shopping cart in the alphabetical order of the product names. Refer to the Testing section for the receipt format;
• The printReportForTheDay method will print a report for the day in the alphabetical order of the product names for the cash register. Refer to the Testing section for the report format.
You need to understand the POSmain program and observe the sample output in the Testing section to understand more how the program will work with the classes.
import java.util.ArrayList;
import java.util.*;
import java.util.Arrays;
import java.util.Scanner;
public class ProductPrices{
private ArrayList<String> products = new ArrayList<String>();
private ArrayList<Double> prices = new ArrayList<Double>();
// List<String> prices = new ArrayList<>();
public void put(String product, double price){
products.add(product);
prices.add(price);
// this.price = price;
}
public double get(String product){
int a = products.indexOf(product);
return prices.get(a);
}
public static void main(String []args){
System.out.println("Hello World");
Scanner sc = new Scanner(System.in);
// String str = sc.next();
}
}
// import java.util.ArrayList;
// import java.util.*;
// import java.util.Arrays;
class ShoppingCart{
private ArrayList<String> items = new ArrayList<String>();
public void addItem(String item){
items.add(item);
}
// +addItem(String): void
public ArrayList<String> getAllItems(){
// : ArrayList<String>
return items;
}
}
class CashRegister
{
public ProductPrices productPrices = new ProductPrices();
// = new ProductPrices();
public CashRegister(ProductPrices productPrices)
{
this.productPrices = productPrices;
}
public void scanAllItemsInCart(ShoppingCart shoppingCart)
{
// ShoppingCart item = new ShoppingCart();
ArrayList<String> items = shoppingCart.getAllItems();
for(int i = 0; i<items.size(); i++)
{
items.get(i);
}
// Scanner sc = new Scanner(System.in);
// while(sc.hasNext()) {
// items.get(sc.next());
// this.items = ShoppingCart.getAllItems();
// public void printReceipt()
// {
// }
// +printReportForTheDay(): void
}
}
Note- Since there are no values for the files or the objects, I
don't understand what shuould be given in both the print methods.
If you provide me sample inputs, I might be able to help with the
last two methods too. I hope this is helpful.