SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Shop {  static int number; objects
  4.     static String[] name = null;
  5.     static int[] amount = null;
  6.     static double[] price = null;
  7.     static int [] packdiscount = null;
  8.     static double discount;
  9.     static double rate;
  10.  
  11.  
  12. public static void Intro(){
  13.  
  14.     System.out.println("This system suppports 4 functions: ");
  15.     System.out.println("       1. Setup Shop");
  16.     System.out.println("       2. Buy");
  17.     System.out.println("       3. List Items");
  18.     System.out.println("       4. Checkout");
  19.  
  20.     System.out.print("Please choose the function you want: ");
  21.     }  
  22.  
  23. public static void Setup(Scanner input){
  24.  
  25.     System.out.print("Enter the number of items to setup shop: ");
  26.     number = input.nextInt();
  27.  
  28.     amount = new int[number];
  29.     name = new String[number];
  30.     price = new double[number];
  31.  
  32.     packdiscount = new int [number];
  33.  
  34.  
  35.     for (int i=0; i < number; i++){
  36.     System.out.print("Please enter the name of product " + i + ":");
  37.     name[i] = input.next();
  38.     System.out.print("Please enter the per package price of " + name[i]  + ":");
  39.     price[i] = input.nextDouble();
  40.  
  41.     System.out.print("Enter the number of packages ('x') to qualify for Special Discount (buy 'x' get 1 free) for " +
  42.             name[i] + ", or 0 if no Special Discount offered:"); // might need to fix
  43.     packdiscount[i] =  input.nextInt();
  44.     }
  45.  
  46.     System.out.print("Enter the dollar amount to qualify for Additional Discount (or 0 if none offered):");
  47.     discount = input.nextDouble();
  48.     if (discount > 0 ) {
  49.  
  50.         System.out.print("Please enter discount rate(0.1 for $10): " );
  51.         rate = input.nextDouble();
  52.  
  53.     if (rate < 0 || rate >= 0.5) {
  54.  
  55.         System.out.println("Invalid input. Enter a value > 0 and <= 0.5:");
  56.         rate = input.nextDouble();
  57.  
  58.     }  
  59.     }
  60. }
  61.  
  62.  
  63. public static void Buy(Scanner input){
  64.     for(int i=0; i < number; i++){
  65.     System.out.print("Enter amount of " + name[i]+" packages to buy: ");
  66.     amount[i] = input.nextInt();
  67.     }
  68.     }
  69.  
  70.  
  71. public static void ListItems(){
  72.     for(int i =0; i<number;i++){
  73.         if(amount[i] != 0){
  74.             System.out.println(amount[i] + " packages of " + name[i] + " @ $" + price[i] + " per pkg = $" + ((amount[i] * (price[i])) ));
  75.                     //"Total amount of " + name[i] + " is quanitity " + amount[i] + " priced at " + price[i]);
  76.         }
  77.  
  78.     }
  79.  
  80. }
  81.  
  82. public static void Checkout(){
  83.     double total=0;
  84.     double dscount=0;
  85.     double newdisc = 0;
  86.     double adddisc = 0;
  87.     for (int i=0;i<number;i++){
  88.         total +=amount[i]*price[i];
  89.     }
  90.     if (total > discount){
  91.         dscount = total*rate;
  92.     }
  93.  
  94.  
  95.     System.out.println("Original Subtotal: $" + total);
  96.     System.out.println("Special Discount: -" + dscount);
  97.      newdisc = (total-dscount) ;
  98.     System.out.println("New Sub Total: $" + newdisc );
  99.      adddisc = rate * newdisc;
  100.     System.out.println("Addional " + rate +"% Discount: -" + adddisc );
  101.  
  102.     System.out.println("Final Sub Total: " +  (newdisc - adddisc));
  103.     System.out.println("Thanks for coming!");
  104.  
  105. }
  106. public static void main(String[] args) {
  107.     Scanner input = new Scanner(System.in);
  108.     int function;
  109.  
  110.     boolean done = false;
  111.     boolean bought = false;
  112.  
  113.     while(true){
  114.         Intro();
  115.     function = input.nextInt();
  116.  
  117.     if(function == 1){
  118.         Setup(input);
  119.         done=true;
  120.     } else if(function == 2 && done !=true){
  121.         System.out.println("");
  122.         System.out.println("Shop has not been setup!");
  123.         System.out.println("");
  124.         }
  125.     else if(function == 2 && done == true){
  126.         System.out.println("");
  127.         Buy(input);
  128.         System.out.println("");
  129.  
  130.     } else if(function == 3 && done != true ){
  131.         System.out.println("No items were purchased.");
  132.  
  133.         }
  134.         }
  135.     else if(function == 3 && done == true){
  136.         System.out.println("");
  137.         ListItems();
  138.         System.out.println("");
  139.  
  140.  
  141.     } else if(function == 4 && done !=true){
  142.         System.out.println("Shop is not set up yet!");
  143.         }
  144.     else if(function == 4 && done == true){
  145.         System.out.println("");
  146.         Checkout();
  147.         System.out.println("");
  148.         return;
  149.     }
  150.     else
  151.  
  152.         System.out.println("System does not recognize option.");
  153. }
  154. }
  155. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top