Question

In: Computer Science

You need to create a Java class library to support a program to simulate a Point-...

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

  1. 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.

Solutions

Expert Solution

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.


Related Solutions

Program Requirements: This assignment requires you to create one program in Java to simulate a Point-of-Sale...
Program Requirements: This assignment requires you to create one program in Java to simulate a Point-of-Sale (POS) system. The solution must be in JAVA language. You create the main program called POSmain.java and two classes: ShoppingCart and CashRegister. Your POSmain program should take 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...
JAVA program Create a class called Array Outside of the class, import the Scanner library Outside...
JAVA program Create a class called Array Outside of the class, import the Scanner library Outside of main declare two static final variables and integer for number of days in the week and a double for the revenue per pizza (which is $8.50). Create a method called main Inside main: Declare an integer array that can hold the number of pizzas purchased each day for one week. Declare two additional variables one to hold the total sum of pizzas sold...
I need to create a program that will simulate an ATM. The program has to be...
I need to create a program that will simulate an ATM. The program has to be written in JAVA that uses JOptionaPane to pop up the messages. It will need to simulate to get ** balance **withdraw **Deposit **exit the atm ** need to have a method that shows a receipt of everything that was done during the transaction
1.Create full program in Java that will simulate a Rock Paper Scissors Game You will create...
1.Create full program in Java that will simulate a Rock Paper Scissors Game You will create the code so that when the program is run the user will see in the console the following: We are going to play rock paper scissors. Please choose 1 for Rock 2 for Paper or 3 for scissors. The program will have your choice which is the integer-valued typed in by the user and compChoice which will be the randomly generated value of either...
NEED IN JAVA Problem statement. This application will support the operations of a technical library for...
NEED IN JAVA Problem statement. This application will support the operations of a technical library for an R&D organization. This includes the searching for and lending of technical library materials, including books, videos, and technical journals. Users will enter their company ids in order to use the system; and they will enter material ID numbers when checking out and returning items.   Each borrower can be lent up to five items. Each type of library item can be lent for a...
Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment...
Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment Create a class GradesGraph that represents a grade distribution for a given course. Write methods to perform the following tasks: • Set the number of each of the letter grades A, B, C, D, and F. • Read the number of each of the letter grades A, B, C, D, and F. • Return the total number of grades. • Return the percentage of...
Java question, not sure how to do this... You need to create a base class that...
Java question, not sure how to do this... You need to create a base class that should have the following functionality. - Calculate avg. Students grade. Input parameter to this method is an array that shows grades for at least ten courses. You need to create a child class that inherits the base class. The child class should have a method to calculate max grade from 10 courses. You need to write a demo class. The demo class should have...
in java we need to order a list , if we create a program in java...
in java we need to order a list , if we create a program in java what  are the possible ways of telling your program how to move the numbers in the list to make it sorted, where each way provides the required result. list the name of sorting with short explanation
write the program in java. Demonstrate that you understand how to use create a class and...
write the program in java. Demonstrate that you understand how to use create a class and test it using JUnit Let’s create a new Project HoursWorked Under your src folder, create package edu.cincinnatistate.pay Now, create a new class HoursWorked in package edu.cincinnatistate.pay This class needs to do the following: Have a constructor that receives intHours which will be stored in totalHrs Have a method addHours to add hours to totalHrs Have a method subHours to subtract hours from totalHrs Have...
Create a Java program. The class name for the program should be 'EncryptText'. In the main...
Create a Java program. The class name for the program should be 'EncryptText'. In the main method you should perform the following: You should read a string from the keyboard using the Scanner class object. You should then encrypt the text by reading each character from the string and adding 1 to the character resulting in a shift of the letter entered. You should output the string entered and the resulting encrypted string. Pseudo flowchart for additional code to be...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT