Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.61 KB | None | 0 0
  1.  
  2. /**
  3. * Made by Joni Bäckström 101970
  4. * date: 8.12.2011
  5. * BlueJ 3.0.5
  6. * Class 6, home assignment 2
  7. * The program works as intended. Has a lot of text that
  8. * could have been made clearer by having 2 classes
  9. * but had some troubles with that, so i put everything
  10. * into the same class.
  11. *
  12. */
  13.  
  14. import java.util.Scanner;
  15. public class store {
  16. public static void main (String args[]) {
  17. Scanner scn = new Scanner(System.in);
  18. int price=0;
  19. int buy1;
  20. int buy=0;
  21. int cont=1;
  22. // Each product has 3 different Integers.
  23. int item1=3; // int item1 tells the number of availiable products in the store
  24. int item1p=20; // item1p tells the price of the item
  25. int item1b=0; // here so the program can calculate the purchases
  26. int item2=2;
  27. int item2p=30;
  28. int item2b=0;
  29. int item3=5;
  30. int item3p=100;
  31. int item3b=0;
  32. int item4=13;
  33. int item4p=20;
  34. int item4b=0;
  35. int item5=7;
  36. int item5p=7;
  37. int item5b=0;
  38. int item6=15;
  39. int item6p=10;
  40. int item6b=0;
  41. int item7=99;
  42. int item7p=40;
  43. int item7b=0;
  44. int item8=1;
  45. int item8p=1020;
  46. int item8b=0;
  47. int item9=100;
  48. int item9p=1;
  49. int item9b=0;
  50. int item0=25;
  51. int item0p=5;
  52. int item0b=0;
  53.  
  54. while (cont==1) {
  55. System.out.println("");
  56. System.out.println(" INVENTORY");
  57. System.out.println(" *******************************************************");
  58. System.out.println("**Mathbooks "+item1+" available "+item1p+ "€ each. Item number 1**");
  59. System.out.println("**Cookingbooks "+item2+" available "+item2p+ "€ each. Item number 2**");
  60. System.out.println("**Toasters "+item3+" available "+item3p+ "€ each. Item number 3**");
  61. System.out.println("**Lamps "+item4+" available "+item4p+ "€ each. Item number 4**");
  62. System.out.println("**Wineglasses "+item5+" available "+item5p+ "€ each. Item number 5**");
  63. System.out.println("**Pillows "+item6+" available "+item6p+ "€ each. Item number 6**");
  64. System.out.println("**Blankets "+item7+" available "+item7p+ "€ each. Item number 7**");
  65. System.out.println("**Computers "+item8+" available "+item8p+ "€ each. Item number 8**");
  66. System.out.println("**Candy "+item9+" available "+item9p+ "€ each. Item number 9**");
  67. System.out.println("**Lemonade "+item0+" available "+item0p+ "€ each. Item number 10**");
  68. System.out.println(" *******************************************************");
  69. System.out.println("\nType in the number of the item you want to add to shopping cart:");
  70. buy=scn.nextInt();
  71.  
  72. while (buy ==1 && item1>0) { // each product has a own while state that calculates things.
  73. item1b=item1b+1; // shows the amount of products purchades in the shoppingcart.
  74. item1=item1 -1; // this part reduces the amount of availiable items in the inventory.
  75. price=price+item1p; // this part adds the value of the product to the total purchades price.
  76. System.out.println("Mathbook, cost 20€."); // if there are 0 products availaible, it does not add it to the total value or amount of items bought.
  77. break;}
  78.  
  79. while (buy ==2 && item2>0) {
  80. item2b=item2b+1;
  81. item2=item2 -1;
  82. price=price+item2p;
  83. System.out.println("Cookingbook, cost 30€.");
  84. break;}
  85. while (buy ==3 && item3>0) {
  86. item3b=item3b+1;
  87. item3=item3 -1;
  88. price=price+item3p;
  89. System.out.println("Toaster, cost 100€.");
  90. break;}
  91. while (buy ==4 && item4>0) {
  92. item4b=item4b+1;
  93. item4=item4 -1;
  94. price=price+item4p;
  95. System.out.println("Lamp, cost 20€.");
  96. break;}
  97. while (buy ==5 && item5>0) {
  98. item5b=item5b+1;
  99. item5=item5 -1;
  100. price=price+item5p;
  101. System.out.println("Wineglass, cost 7€.");
  102. break;}
  103. while (buy ==6 && item6>0) {
  104. item6b=item6b+1;
  105. item6=item6 -1;
  106. price=price+item6p;
  107. System.out.println("Pillow, cost 10€.");
  108. break;}
  109. while (buy ==7 && item7>0) {
  110. item7b=item7b+1;
  111. item7=item7 -1;
  112. price=price+item7p;
  113. System.out.println("Blanket, cost 40€.");
  114. break;}
  115. while (buy ==8 && item8>0) {
  116. item8b=item8b+1;
  117. item8=item8 -1;
  118. price=price+item8p;
  119. System.out.println("Computer, cost 1020€.");
  120. break;}
  121. while (buy ==9 && item9>0) {
  122. item9b=item9b+1;
  123. item9=item9 -1;
  124. price=price+item9p;
  125. System.out.println("Candy, cost 1€.");
  126. break;}
  127. while (buy ==10 && item0>0) {
  128. item0b=item0b+1;
  129. item0=item0 -1;
  130. price=price+item0p;
  131. System.out.println("Lemonade, cost 5€.");
  132. break;}
  133.  
  134. System.out.println("Type 1 to continue shopping, 0 to quit.");
  135. cont=scn.nextInt();
  136.  
  137. if (cont==0) {
  138. System.out.println(" SHOPPING CART: ");
  139. System.out.println(" **********************************");
  140. System.out.println("**Total price of your items: "+price+"€**");
  141. System.out.println("**You bought: "+(item1b)+" Mathbooks. **");
  142. System.out.println("**You bought: "+(item2b)+" Cookingbooks. **");
  143. System.out.println("**You bought: "+(item3b)+" Toasters. **");
  144. System.out.println("**You bought: "+(item4b)+" Lamps. **");
  145. System.out.println("**You bought: "+(item5b)+" Wineglasses. **");
  146. System.out.println("**You bought: "+(item6b)+" Pillows. **");
  147. System.out.println("**You bought: "+(item7b)+" Blankets. **");
  148. System.out.println("**You bought: "+(item8b)+" Computer. **");
  149. System.out.println("**You bought: "+(item9b)+" Candy. **");
  150. System.out.println("**You bought: "+(item0b)+" Lemonade. **");
  151. System.out.println(" **********************************");
  152. System.out.println("\nTo buy items in Cart, type 1. To exit shop without buying, type 0.");
  153. buy1=scn.nextInt();
  154. while (buy1==1) {
  155. System.out.println("You have bought items for "+price+"€, thank you for shopping at Onlinejava.");
  156. break;}
  157. while (buy1==2) {
  158. System.out.println("Bye!");
  159. break;
  160. }
  161. }
  162.  
  163.  
  164.  
  165. }
  166. }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement