Question

In: Computer Science

The solution should be written in Java. Your POSmain program should take three file names from...

The solution should be written in Java.

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 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 ShoppingCart objects. 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 POSmain program 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 students of CSIT111 and CSIT811 will print a different report for the day, which requires different design of your CashRegister class.

The output should be like this:-

One customer is checking out ...
========================================
Product Price Qty Subtotal
----------------------------------------
Bed $499.99 2 $999.98
Char $45.49 4 $181.96
TV $999.99 1 $999.99
Table $199.0 2 $398.0
-------------------------
Total $2579.93
========================================
One customer is checking out ...
========================================
Product Price Qty Subtotal
----------------------------------------
Bread $1.75 2 $3.5
Butter $2.84 1 $2.84
Ham $2.5 1 $2.5
Lettuce $1.0 1 $1.0
Milk $3.0 2 $6.0
Onions $0.54 3 $1.62
Tomato $0.76 5 $3.8
-------------------------
Total $21.26
========================================
Report for the day
========================================
Number of customers: 2
Total sale: $2601.19
List of products sold:
----------------------------------------
Product Qty
----------------------------------------
Bed 2
Bread 2
Butter 1
Char 4
Ham 1
Lettuce 1
Programming Fundamentals - 3/4 -
Milk 2
Onions 3
TV 1
Table 2
Tomato 5

Solutions

Expert Solution

class Global{
    public String[] productArr=new String[100];
    public int[] quantityArr=new int[100];
    public int tempSize=0;
    Global()
    {
        for(int i=0;i<100;i++)
        {
            quantityArr[i]=0;
        }
        tempSize=0;
    }
};
class Product
{
    private String product;
    private float price;
    public Product()
    {
        price=0;
        product="";
    }
    String getProduct()
    {
        return product;
    }
    float getPrice()
    {
        return price;
    }
    void setProduct(String product_)
    {
        product=product_;
    }
    void setPrice(float price_)
    {
        price=price_;
    }
};

class Cart
{
    private Product[] pList=new Product[100];
    private int[] qty=new int[100];
    private int size;
    public Cart()
    {
        size=0;
    }
    void addProduct(String name,float price,int qty_)
    {
        if(size<100)
        {
            pList[size]=new Product();
            pList[size].setProduct(name);
            pList[size].setPrice(price);
            qty[size]=qty_;
            size++;
            System.out.println("\nProduct Added into cart");
        }
        else
        {
            System.out.println("\nCart is full you have to checkout...");
        }
    }
    public Product getProductByName(String Name)
    {
        
        for(int i=0;i<=size;i++)
        {
            if(pList[i].getProduct()==Name)
            {
                return pList[i];
            }
        }
        System.out.println("\nNo product found");
        return null;
    }
    public Product getProductByIndex(int index)
    {
        
        if(index<=size&&index>=0)
        {
            return pList[index];
        }
        System.out.println("\nNo product found");
        return null;
    }
    public int getSize()
    {
        return size;
    }
    public void setSize(int size_)
    {
        size=size_;
    }
    public int getQtyByName(String Name)
    {
        for(int i=0;i<=size;i++)
        {
            if(pList[i].getProduct()==Name)
            {
                return qty[i];
            }
        }
        System.out.println("\nNo product found");
        return -1;
    }
    public int getQtyByIndex(int index)
    {
        if(index<=size&&index>=0)
        {
            return qty[index];
        }
        System.out.println("\nNo Quantity for product (at this index) found");
        return 0;
    }
    public float checkOut(Global obj)
    {
        float sum=0;
        System.out.println("\nOne customer is checking out...");
        System.out.println("\nProduct\t\tPrice\tQuantity\tSubTotal\n----------------------------------------------------------");
        for(int i=0;i<size;i++)
        {
            boolean flag=true;
            System.out.println(""+pList[i].getProduct()+"\t"+pList[i].getPrice()+"\t"+qty[i]+"\t\t\t$"+(pList[i].getPrice()*qty[i]));
            
            sum+=pList[i].getPrice()*qty[i];
            for(int j=0;j<obj.tempSize;j++)
            {
                if(pList[i].getProduct()==obj.productArr[i])
                {
                    obj.quantityArr[i]+=qty[i];
                    flag=false;
                    break;
                }
            }
            if(flag==true)
            {
                obj.productArr[obj.tempSize]=pList[i].getProduct();
                obj.quantityArr[obj.tempSize]=qty[i];
                obj.tempSize++;
            }
        }
        System.out.println("Total &"+sum);
        return sum;
    }
};
class Manage
{
    public Cart[] customer=new Cart[10];
    public int size;
    int customerNumber;
    float sum;
    public Manage()
    {
        size=0;
        sum=0;
    }
    public void addCustomer()
    {
        if(size<100)
        {
            customer[size]=new Cart();
            size++;
            customerNumber=size;
        }
    }
    public void addProduct(String name,float price,int qty,int index)
    {
        if(index>=0&&index<=size)
        {
            customer[index-1].addProduct(name,price,qty);
        }
        else
        {
            System.out.println("\nInvalid index");
        }
    }
    public void checkoutCustomer(Global obj,int index)
    {
        if(index>=0&&index<=size)
        {
            sum+=customer[index-1].checkOut(obj);
            customer[index-1]=customer[size-1];
            size--;
            
        }
        else
        {
            System.out.println("\nInvalid index");
        }
    }
    public void dailyReport(Global obj)
    {
        System.out.println("\nDaily Report\n--------------------");
        System.out.println("\nNumber of customer:"+customerNumber);
        System.out.println("\nTotal Sale:$"+sum);
        System.out.println("\nList of product sold:\n---------------------");
        System.out.println("\nProduct\tQuantity");
        System.out.println("\n---------------------");
        for(int i=0;i<obj.tempSize;i++)
        {
            System.out.println(""+obj.productArr[i]+"\t"+obj.quantityArr[i]);
        }
    }
    
};


public class MyClass
{
    public static void main(String[] args)
    {
        Global global_obj=new Global();
        Manage obj=new Manage();
        
        obj.addCustomer();
        obj.addProduct("Product-1",10,2,1);
        obj.addProduct("Product-2",10,2,1);
        obj.addProduct("Product-3",10,2,1);
        obj.checkoutCustomer(global_obj,1);
        
        obj.addCustomer();
        obj.addProduct("Product-1",10,2,1);
        obj.addProduct("Product-2",10,2,1);
        obj.addProduct("Product-3",10,2,1);
        obj.checkoutCustomer(global_obj,1);
    
        
        obj.dailyReport(global_obj);
        
    }
}


Related Solutions

Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
Program should be written in Java b) The computer program should prompt the user (You are...
Program should be written in Java b) The computer program should prompt the user (You are the user) to enter the answers to the following questions: What is your city of birth? What is your favorite sport? If you could live anywhere in the world, where would you like to live? What is your dream vacation? Take this information and create a short paragraph about the user and output this paragraph. You may use the Scanner class and the System.out...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
This program is written in Java and should be modularized in methods in one class. This...
This program is written in Java and should be modularized in methods in one class. This program will calculate the Gross Earnings, FICA tax (Medicare and Social Security taxes), Federal Tax Withheld, and Net Amount of the payroll check for each employee of a company. The output must contain numbers with 2 decimal places. The user input must be validated – if incorrect data is entered, send an error message to the user. INPUT The application must be able to...
Write a program in python to read from a file the names and grades of a...
Write a program in python to read from a file the names and grades of a class of students to calculate the class average, the maximum, and the minimum grades. The program should then write the names and grades on a new file identifying the students who passed and the students who failed. The program should consist of the following functions: a) Develop a getGrades() function that reads data from a file and stores it and returns it as a...
I need to update this java program to take input about each employee from a file...
I need to update this java program to take input about each employee from a file and write their information and salary/pay information to a file. use input file payroll.txt Kevin Yang 60 20 Trey Adams 30 15 Rick Johnson 45 10 Cynthia Wheeler 55 11.50 Sarah Davis 24 10 Muhammad Rabish 66 12 Dale Allen 11 18 Andrew Jimenez 80 15 import java.util.Scanner; public class SalaryCalcLoop { double Rpay = 0, Opay = 0; void calPay(double hours, double rate)...
I need to update this java program to take input about each employee from a file...
I need to update this java program to take input about each employee from a file and write their information and salary/pay information to a file. use input file payroll.txt import java.util.Scanner; public class SalaryCalcLoop { double Rpay = 0, Opay = 0; void calPay(double hours, double rate) { if (hours <= 40) { Rpay = hours * rate; Opay = 0; } else { double Rhr, Ohr; Rhr = 40; Ohr = hours - Rhr; Rpay = Rhr *...
java Write a recursive program to reverse a positive integer. . Your method should take a...
java Write a recursive program to reverse a positive integer. . Your method should take a non negative integer as a parameter and return the reverse of the number as an integer. e.g. if you pass 12345, your method should return 54321.
write a program in Java that can take a given text file and then compress it...
write a program in Java that can take a given text file and then compress it with Huffman coding due 20 october 2020 Huffman coding can be used to “zip” a text file to save space. You are required to write a program in Java that can take a given text file and then compress it with Huffman coding. Your program should be able to decompress the zipped files as well [4 marks]. In addition, show percentage gain in data...
This program should be written in Java language. Given the uncertainty surrounding the outbreak of the...
This program should be written in Java language. Given the uncertainty surrounding the outbreak of the Coronavirus disease (COVID-19) pandemic, our federal government has to work tirelessly to ensure the distribution of needed resources such as medical essentials, water, food supply among the states, townships, and counties in the time of crisis. You are a software engineer from the Right Resource, a company that delivers logistic solutions to local and state entities (schools, institutions, government offices, etc). You are working...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT