Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. import java.util.*;
  2. public class StoreProgram {
  3.  
  4.  
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. //Ask the user what you sell and what the cost is
  8. System.out.println("What do we sell? (plural)");
  9. String item = sc.nextLine();
  10.  
  11. System.out.println("How much do "+ item + " cost?");
  12.  
  13. double cost = sc.nextDouble();
  14.  
  15. System.out.println("How many days do you want to simulate? ");
  16. int days = sc.nextInt();
  17.  
  18. while (days > 0) {
  19. //Calculate the number of items sold and the total
  20. //Math.random is exclusively upper bound
  21. //int sold = 1; //debug for negative items
  22. int sold = (int) (Math.random() * 25);
  23. System.out.println("Today you sold " + sold + " " + item + ".");
  24. // System.out.println(cost);
  25. // System.out.println(sold); //debugging
  26. double total = cost * sold;
  27. total = (int) (total * 100); //removing unwanted decimal places
  28. total = total / 100;
  29.  
  30. System.out.println("you made $" + total);
  31.  
  32.  
  33. int max = sold +5;
  34. int min;
  35. //making sure min cannot be < 0
  36. if (sold < 3) {
  37. min = sold - (int) (Math.random() * sold);
  38. }
  39. else {
  40. min = sold - 3;
  41. }
  42.  
  43. int ddSold = (int) (Math.random() * (max-min + 1) + min);
  44. //System.out.println(ddSold); //debugging
  45. double ddCost;
  46. //making sure the cost cannot be < 0
  47. if (cost < 2) {
  48. ddCost = cost - (Math.random() * cost);
  49. }
  50. else {
  51. ddCost = cost - (Math.random() * 2);
  52. }
  53. double ddTotal = ddSold * ddCost;
  54. ddTotal = (int) (ddTotal * 100); //removing unwanted decimal places
  55. ddTotal = ddTotal / 100;
  56.  
  57. System.out.println("Your main competitor is dictator Davis' " + item + " Emporium");
  58. System.out.println("Today they sold" + " " + ddSold + " " + item + " and they made $" + ddTotal);
  59.  
  60. if (ddTotal > total) {
  61. System.out.println("not noice");
  62. }
  63. else {
  64. System.out.println("noice");
  65. }
  66. System.out.println(""); // seperating days
  67. days--; //subtracting days
  68. }
  69. }
  70.  
  71. }
  72.  
  73. //extra credit
  74. //no negative prices
  75. //no negative items
  76. //two decimals
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement