Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Shop { static int number; objects
- static String[] name = null;
- static int[] amount = null;
- static double[] price = null;
- static int [] packdiscount = null;
- static double discount;
- static double rate;
- public static void Intro(){
- System.out.println("This system suppports 4 functions: ");
- System.out.println(" 1. Setup Shop");
- System.out.println(" 2. Buy");
- System.out.println(" 3. List Items");
- System.out.println(" 4. Checkout");
- System.out.print("Please choose the function you want: ");
- }
- public static void Setup(Scanner input){
- System.out.print("Enter the number of items to setup shop: ");
- number = input.nextInt();
- amount = new int[number];
- name = new String[number];
- price = new double[number];
- packdiscount = new int [number];
- for (int i=0; i < number; i++){
- System.out.print("Please enter the name of product " + i + ":");
- name[i] = input.next();
- System.out.print("Please enter the per package price of " + name[i] + ":");
- price[i] = input.nextDouble();
- System.out.print("Enter the number of packages ('x') to qualify for Special Discount (buy 'x' get 1 free) for " +
- name[i] + ", or 0 if no Special Discount offered:"); // might need to fix
- packdiscount[i] = input.nextInt();
- }
- System.out.print("Enter the dollar amount to qualify for Additional Discount (or 0 if none offered):");
- discount = input.nextDouble();
- if (discount > 0 ) {
- System.out.print("Please enter discount rate(0.1 for $10): " );
- rate = input.nextDouble();
- if (rate < 0 || rate >= 0.5) {
- System.out.println("Invalid input. Enter a value > 0 and <= 0.5:");
- rate = input.nextDouble();
- }
- }
- }
- public static void Buy(Scanner input){
- for(int i=0; i < number; i++){
- System.out.print("Enter amount of " + name[i]+" packages to buy: ");
- amount[i] = input.nextInt();
- }
- }
- public static void ListItems(){
- for(int i =0; i<number;i++){
- if(amount[i] != 0){
- System.out.println(amount[i] + " packages of " + name[i] + " @ $" + price[i] + " per pkg = $" + ((amount[i] * (price[i])) ));
- //"Total amount of " + name[i] + " is quanitity " + amount[i] + " priced at " + price[i]);
- }
- }
- }
- public static void Checkout(){
- double total=0;
- double dscount=0;
- double newdisc = 0;
- double adddisc = 0;
- for (int i=0;i<number;i++){
- total +=amount[i]*price[i];
- }
- if (total > discount){
- dscount = total*rate;
- }
- System.out.println("Original Subtotal: $" + total);
- System.out.println("Special Discount: -" + dscount);
- newdisc = (total-dscount) ;
- System.out.println("New Sub Total: $" + newdisc );
- adddisc = rate * newdisc;
- System.out.println("Addional " + rate +"% Discount: -" + adddisc );
- System.out.println("Final Sub Total: " + (newdisc - adddisc));
- System.out.println("Thanks for coming!");
- }
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int function;
- boolean done = false;
- boolean bought = false;
- while(true){
- Intro();
- function = input.nextInt();
- if(function == 1){
- Setup(input);
- done=true;
- } else if(function == 2 && done !=true){
- System.out.println("");
- System.out.println("Shop has not been setup!");
- System.out.println("");
- }
- else if(function == 2 && done == true){
- System.out.println("");
- Buy(input);
- System.out.println("");
- } else if(function == 3 && done != true ){
- System.out.println("No items were purchased.");
- }
- }
- else if(function == 3 && done == true){
- System.out.println("");
- ListItems();
- System.out.println("");
- } else if(function == 4 && done !=true){
- System.out.println("Shop is not set up yet!");
- }
- else if(function == 4 && done == true){
- System.out.println("");
- Checkout();
- System.out.println("");
- return;
- }
- else
- System.out.println("System does not recognize option.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement