Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. package com.company;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6. static public class Product {
  7. String name;
  8. String id;
  9. float price;
  10. int quantiiy;
  11. int selfNuml;
  12. }
  13. static Scanner in = new Scanner(System.in);
  14. public static void main(String[] args) {
  15. Product p = new Product();
  16. Product p2 = new Product();
  17. Product p3 = new Product();
  18. Product p4 = new Product();
  19.  
  20. p.name = "milk";p2.name = "juice"; p3.name = "rice";p4.name = "suger";
  21. p.price = 10; p2.price = 5;p3.price = 15; p4.price = 17;
  22. p.id = "3432";p2.id = "332"; p3.id = "125"; p4.id = "102";
  23. p.quantiiy = 100; p2.quantiiy = 150;p3.quantiiy = 70;p4.quantiiy = 160;
  24. p.selfNuml = 6; p2.selfNuml = 1;p3.selfNuml = 5;p4.selfNuml = 9;
  25.  
  26. // creating array contains the for products;
  27. Product[] products = {p, p2, p3, p4};
  28. System.out.println("What do you want to do\n 1: Buy\n 2: Search");
  29. int choice = in.nextInt();
  30. switch(choice){
  31. case 1:
  32. int sum = 0;
  33. while(true) {
  34. int i = 1;
  35. for (Product a : products) {
  36. System.out.println(i + " --> " + a.name + " price( " + a.price + ")");
  37. i++;
  38. }
  39. System.out.println("Enter the number of price OR Enter to -1 to finish shopping");
  40. int productNum = in.nextInt();
  41. if(productNum == -1)
  42. break;
  43. Product temp = products[productNum - 1];
  44. System.out.println("Enter the amount of the product");
  45. int productQuantity = in.nextInt();
  46. sum += temp.price * productQuantity;
  47.  
  48. }
  49. System.out.println("you have pay " + sum + "LE");
  50. break;
  51. case 2:
  52. in.nextLine();
  53. System.out.println("Enter the product name");
  54. String name = in.nextLine();
  55. for(Product a: products){
  56. if(a.name.equalsIgnoreCase(name)){
  57. System.out.println("product name " + a.name +"\n"+"product price " + a.price + "\n" +"product locations at self number " + a.selfNuml);
  58. }
  59. }
  60. break;
  61.  
  62. default:
  63. System.out.println("invalid choice");
  64. break;
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement