Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class storeProgram {
  3. public static void main(String[] args) {
  4.  
  5. //Ask the user what we sell and what the cost is
  6. Scanner sc=new Scanner(System.in);
  7. System.out.println("What do we sell? (plural): ");
  8. String item = sc.nextLine();
  9. System.out.println("How much do "+item+" cost? $");
  10. double cost = sc.nextDouble();
  11.  
  12. System.out.println("How many days do you want to simulate? ");
  13. int days = sc.nextInt();
  14.  
  15. while(days>0) {
  16.  
  17. //Calculate the number of items sold and the total
  18. //Math.random is EXCLUSIVE on the upper bound
  19. int sold = (int)(Math.random() * 25);
  20. System.out.println("Today you sold "+sold+" "+ item+".");
  21.  
  22. double total = cost*sold*100;
  23. total=(int)total;
  24. total=(double)total;
  25. total=total/100;
  26. System.out.println("You made $" + total);
  27.  
  28.  
  29. //Dictator Davis' Store
  30. int max = sold + 5;
  31. int min = sold - 3;
  32. double ddCost=-1;
  33.  
  34. int ddSold= (int)(Math.random()*(max-min+1)+min);
  35. while (ddCost<=0) {
  36. ddCost = cost - Math.random()*2;
  37. }
  38. double ddTotal = ddSold*ddCost;
  39. System.out.println("Your main competitor is Dictator Davis' "+item+" Emporium");
  40. System.out.println("Today they sold "+ddSold+" "+item+" and they made $"+ddTotal);
  41.  
  42. if(ddTotal>total) {
  43. System.out.println("You are really bad at this");
  44. }else {
  45. System.out.println("Good job, you won");
  46. }
  47. days--;
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement