Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Assignment 1 – Point Of Sale POS using java

0360 -322

Part 1:
Assuming the following familiar scenario in any grocery shopping Assuming the following familiar 1. Customer arrives at POS checkout with goods and/or services to purchase.
2. Cashier starts a new sale.
3. Cashier enters item identifier.
4. System records sale line item and presents item description, price, and running total. Price calculated from a set of price rules.
Cashier repeats steps 3-4 until indicates done.
5. System presents total with taxes calculated.
6. Cashier tells Customer the total, and asks for payment.
7. Customer pays and System handles payment.
8. System logs completed sale and sends sale and payment information to the external Accounting system (for accounting and commissions) and Inventory system (to update inventory).
9. System presents receipt.
10. Customer leaves with receipt and goods (if any).
Suppose you are asked to write a program to automate the above steps.
Your assignment 1 is to write such a program in Java. You are not required to use sophisticated GUI for user interaction but to use simple console text interaction.
For anything that is not clear from the steps above, please make your own reasonable assumptions and clearly state it in your submission.
The submission of your assignment 1 consists of possibly two documents for this part.
Doc. 1 is a working Java program that automates the above steps with comments. Upload your Java source code.
Doc. 2 is a document that states anything that could not be put in comments in your source code, such as the assumptions you make, if applicable.

Answer:

Food class

public class Rice extends Food {

	public Rice(String name, String measurement, double price, double stock) {
		super(name, measurement, price, stock);
	}
	
	public String toString() {
		return "Rice: " + super.toString();
	}
}

meat class

public class meat extends Food {

	public meat(String name, String measurement, double price, double stock) {
		super(name, measurement, price, stock);
	}
	
	public String toString() {
		return "meat: " + super.toString();
	}

}

Grocery class

import java.util.Scanner;
import java.util.StringTokenizer;

public class Grocery {

	public static final int maxFoodItems = 10;
	public static final int bitems = 10;
	static String name;
	static double amount;
	private static Food[] foodItems = new Food[maxFoodItems]; // Keep track of the store's inventory
	private static String[] buy = new String[bitems];
	private static int totalFoodItems = 0;
	
	public static void main(String[] args) {
		
		// Accepting input
		Scanner keyboard = new Scanner(System.in);
		String input;
		StringTokenizer inputTokenizer;
		
		// Stock up on items
		Grocery inventory = new Grocery();
		
		/************************************* Name       unit 		price 	stock **/ 
		inventory.addFoodItem(new Fruit(       "apple",   "kg",		1.89, 	200.35));
		inventory.addFoodItem(new Fruit(       "orange",  "dozen",	2.36,  	38));
		inventory.addFoodItem(new Rice("rice",    "kg", 	2.99,  	20));
		inventory.addFoodItem(new meat(    "chicken", "kg",		5.49, 	538.32));
		inventory.addFoodItem(new meat(    "lamb",    "kg",		4.32, 	134.62));
		inventory.addFoodItem(new meat(    "shrimp",  "kg",		9.65,  	74.52));
		
		System.out.println("Items available in the Windsor Grocery Store:");
		System.out.println("");
		inventory.printInventory();
		System.out.println("");		
		
		System.out.println("Enter <item> <amount> to buy followed by ENTER");
		System.out.println("When you are done please Type \"done\" to finish");
		System.out.println("");
		
		double totalPrice = 0;
		double numOfItems = 0;
		// Keep parsing through input
		int j=0;
		while( !(input = keyboard.nextLine()).equals("done") ) {
			
			inputTokenizer = new StringTokenizer(input);
			
			 name = inputTokenizer.nextToken();
			 amount = Double.parseDouble(inputTokenizer.nextToken());
			 buy[j]=name+"		"+inventory.foodItems[j].getPrice()+"			"+amount;
			// Check if it matches any of the items in the inventory

			for(int i = 0; i < inventory.totalFoodItems; i++) {
				
				if(inventory.foodItems[i].getName().equals(name)) {
					
					inventory.foodItems[i].decreaseStock(amount);
					totalPrice += amount * inventory.foodItems[i].getPrice();
					break;
				}				
			}
			numOfItems++;
			j++;
		}
		
		System.out.println("Dear Customer your payment information is as follow:");
		System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
		System.out.println("The total before taxes is $ " + (int)(totalPrice * 100) / 100.0);
		double tax = ((totalPrice ) * 0.13);
		double finalCost = totalPrice +  tax;
		System.out.println("Tax is $ " + (int)(tax* 100) / 100.0);
		System.out.println("Your total payment is $ " + (int)(finalCost * 100) / 100.0);
		
		// Print results
		System.out.println("\nDo you want to proceed (y/n) ? ");
		Scanner input1 = new Scanner(System.in);
		 String cInput = input1.next();
	     char cClub = cInput.charAt(0);   

	     if (cClub == 'y' || cClub == 'Y'){
      
			System.out.println("\n");
			System.out.println("Updated Inventory:");
			System.out.println("~~~~~~~~~~~~~~~~~");
			inventory.printInventory();
			
			System.out.println("\nPlease enter 'y' for a Receipt ? ");
			Scanner input2 = new Scanner(System.in);
			String dInput = input2.next();
		    char dClub = dInput.charAt(0);  

		    if (dClub == 'y' || dClub == 'Y'){
				System.out.println("\n\n");
				System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
				System.out.println("           Windsor Grocery Store\n");
				System.out.println("                   RECEIPT");
				System.out.println("                  ~~~~~~~~~\n");
				System.out.println("Item		"+"Unit Price		"+"Amount");
				System.out.println("______________________________________________\n");
				for(int i = 0; i < numOfItems; i++) {
					System.out.println(buy[i].toString());
				}
				System.out.println("\nTotal number of items purchased : "+numOfItems);
				System.out.println("\nThe subtotal is $ " + (int)(totalPrice * 100) / 100.0);
				System.out.println("Sales Tax $ " + (int)(tax* 100) / 100.0);
				System.out.println("\nFinal price including the Tax $ " + (int)(finalCost * 100) / 100.0);
				System.out.println("\n               End of Receipt");
				System.out.println("\nThank you for shopping with  Windsor Grocery Store");
				System.out.println("             Please come back again");
				System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
		    }
		    input2.close();
	     }
	     else{
	    	 
	    	 System.out.println("Thank you and we wish to serve you better next time"); 
	     }
	     keyboard.close();
	     input1.close();
	    
	}
	
	
	
	// Add a food item to the inventory
	public boolean addFoodItem(Food f) {		
		// List is full
		if(totalFoodItems >= maxFoodItems) {
			return false;
		}
		
		foodItems[totalFoodItems] = f;
		totalFoodItems++;
		
		return true;		
	}
	
	public void printInventory() {
		for(int i = 0; i < totalFoodItems; i++) {
			System.out.println(foodItems[i].toString());
		}
	}
	
}


Fruit class

public class Fruit extends Food {
	
	public Fruit(String name, String measurement, double price, double stock) {
		super(name, measurement, price, stock);
	}
	
	public String toString() {
		return "Fruit: " + super.toString();
	}

}

Food class

public abstract class Food {

	private String name;        // name of the item (ex: Apple, Orange, Chicken, ...)
	private String measurement; // Unit of measurement (ex. kg)
	private double price;       // Price per unit of measurement (ex. $1.50/kg)
	private double stock;       // amount of item the store has in stock
	
	public Food(String name, String measurement, double price, double stock) {
		this.name = name;
		this.measurement = measurement;
		this.price = price;
		this.stock = stock;
	}
	
	public String getName() {
		return name;
	}
	
	public double getPrice() {
		return price;
	}
	
	// Decrease the stock in a safe manner
	// true = success, false = failure
	public boolean decreaseStock(double amount) {
		if(amount <= stock) {
			stock -= amount;
			return true;
		}
		
		return false;
	}
	
	public String toString() {
		return name + ", " +
	           "$" + price + "/" + measurement + ", " +
		       stock + " " + measurement + " in stock";
	}
	
}

Part 2
You should form a project team for course project. The size of your team is up to 4 students. Please have one student in your team as the team leader who will be communicating with me on matters concerning the project.
You should also propose a project that is similar to the case study discussed in Ch. 3.3 and Ch. 6.8. Ch. 3.3 discusses in general the scope of the project and Ch. 6.8 presents a very important use case for the project (from which all OOAD techniques and skills are discussed in the subsequent chapters).
Parallel to Ch. 3.3 and Ch. 6.8, in this part of your Assignment, I would like each team to propose a project similar to the project proposed in Ch. 3.3 in term of size and complexity. The project proposed should not be too big and too complex to complete. I would also like to know a few important use cases from your project. These important use cases (to be approved by the instructor) will be the basis for all subsequent assignments.
The submission of this part 2 of your assignment requires one document containing
1. Team membership (team member name, SID, and email address)
2. Team leader information
3. Project scope (as in Ch. 3.3).
4. Brief use cases (as in Ch. 6.8 but in brief format).
Please have the team leader submit this document for part 2.
The case study in Ch. 3.3 and Ch 6.8 are good examples of a suitable project for this course. For example, you can propose a project to provide software for ATM to carry out every day banking transactions. I will be your team’s client who “hires” your team to do the project for me.

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!