Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Made by Joni Bäckström 101970
- * date: 8.12.2011
- * BlueJ 3.0.5
- * Class 6, home assignment 2
- * The program works as intended. Has a lot of text that
- * could have been made clearer by having 2 classes
- * but had some troubles with that, so i put everything
- * into the same class.
- *
- */
- import java.util.Scanner;
- public class store {
- public static void main (String args[]) {
- Scanner scn = new Scanner(System.in);
- int price=0;
- int buy1;
- int buy=0;
- int cont=1;
- // Each product has 3 different Integers.
- int item1=3; // int item1 tells the number of availiable products in the store
- int item1p=20; // item1p tells the price of the item
- int item1b=0; // here so the program can calculate the purchases
- int item2=2;
- int item2p=30;
- int item2b=0;
- int item3=5;
- int item3p=100;
- int item3b=0;
- int item4=13;
- int item4p=20;
- int item4b=0;
- int item5=7;
- int item5p=7;
- int item5b=0;
- int item6=15;
- int item6p=10;
- int item6b=0;
- int item7=99;
- int item7p=40;
- int item7b=0;
- int item8=1;
- int item8p=1020;
- int item8b=0;
- int item9=100;
- int item9p=1;
- int item9b=0;
- int item0=25;
- int item0p=5;
- int item0b=0;
- while (cont==1) {
- System.out.println("");
- System.out.println(" INVENTORY");
- System.out.println(" *******************************************************");
- System.out.println("**Mathbooks "+item1+" available "+item1p+ "€ each. Item number 1**");
- System.out.println("**Cookingbooks "+item2+" available "+item2p+ "€ each. Item number 2**");
- System.out.println("**Toasters "+item3+" available "+item3p+ "€ each. Item number 3**");
- System.out.println("**Lamps "+item4+" available "+item4p+ "€ each. Item number 4**");
- System.out.println("**Wineglasses "+item5+" available "+item5p+ "€ each. Item number 5**");
- System.out.println("**Pillows "+item6+" available "+item6p+ "€ each. Item number 6**");
- System.out.println("**Blankets "+item7+" available "+item7p+ "€ each. Item number 7**");
- System.out.println("**Computers "+item8+" available "+item8p+ "€ each. Item number 8**");
- System.out.println("**Candy "+item9+" available "+item9p+ "€ each. Item number 9**");
- System.out.println("**Lemonade "+item0+" available "+item0p+ "€ each. Item number 10**");
- System.out.println(" *******************************************************");
- System.out.println("\nType in the number of the item you want to add to shopping cart:");
- buy=scn.nextInt();
- while (buy ==1 && item1>0) { // each product has a own while state that calculates things.
- item1b=item1b+1; // shows the amount of products purchades in the shoppingcart.
- item1=item1 -1; // this part reduces the amount of availiable items in the inventory.
- price=price+item1p; // this part adds the value of the product to the total purchades price.
- 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.
- break;}
- while (buy ==2 && item2>0) {
- item2b=item2b+1;
- item2=item2 -1;
- price=price+item2p;
- System.out.println("Cookingbook, cost 30€.");
- break;}
- while (buy ==3 && item3>0) {
- item3b=item3b+1;
- item3=item3 -1;
- price=price+item3p;
- System.out.println("Toaster, cost 100€.");
- break;}
- while (buy ==4 && item4>0) {
- item4b=item4b+1;
- item4=item4 -1;
- price=price+item4p;
- System.out.println("Lamp, cost 20€.");
- break;}
- while (buy ==5 && item5>0) {
- item5b=item5b+1;
- item5=item5 -1;
- price=price+item5p;
- System.out.println("Wineglass, cost 7€.");
- break;}
- while (buy ==6 && item6>0) {
- item6b=item6b+1;
- item6=item6 -1;
- price=price+item6p;
- System.out.println("Pillow, cost 10€.");
- break;}
- while (buy ==7 && item7>0) {
- item7b=item7b+1;
- item7=item7 -1;
- price=price+item7p;
- System.out.println("Blanket, cost 40€.");
- break;}
- while (buy ==8 && item8>0) {
- item8b=item8b+1;
- item8=item8 -1;
- price=price+item8p;
- System.out.println("Computer, cost 1020€.");
- break;}
- while (buy ==9 && item9>0) {
- item9b=item9b+1;
- item9=item9 -1;
- price=price+item9p;
- System.out.println("Candy, cost 1€.");
- break;}
- while (buy ==10 && item0>0) {
- item0b=item0b+1;
- item0=item0 -1;
- price=price+item0p;
- System.out.println("Lemonade, cost 5€.");
- break;}
- System.out.println("Type 1 to continue shopping, 0 to quit.");
- cont=scn.nextInt();
- if (cont==0) {
- System.out.println(" SHOPPING CART: ");
- System.out.println(" **********************************");
- System.out.println("**Total price of your items: "+price+"€**");
- System.out.println("**You bought: "+(item1b)+" Mathbooks. **");
- System.out.println("**You bought: "+(item2b)+" Cookingbooks. **");
- System.out.println("**You bought: "+(item3b)+" Toasters. **");
- System.out.println("**You bought: "+(item4b)+" Lamps. **");
- System.out.println("**You bought: "+(item5b)+" Wineglasses. **");
- System.out.println("**You bought: "+(item6b)+" Pillows. **");
- System.out.println("**You bought: "+(item7b)+" Blankets. **");
- System.out.println("**You bought: "+(item8b)+" Computer. **");
- System.out.println("**You bought: "+(item9b)+" Candy. **");
- System.out.println("**You bought: "+(item0b)+" Lemonade. **");
- System.out.println(" **********************************");
- System.out.println("\nTo buy items in Cart, type 1. To exit shop without buying, type 0.");
- buy1=scn.nextInt();
- while (buy1==1) {
- System.out.println("You have bought items for "+price+"€, thank you for shopping at Onlinejava.");
- break;}
- while (buy1==2) {
- System.out.println("Bye!");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement