Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class storeProgram {
- public static void main(String[] args) {
- //Ask the user what we sell and what the cost is
- Scanner sc=new Scanner(System.in);
- System.out.println("What do we sell? (plural): ");
- String item = sc.nextLine();
- System.out.println("How much do "+item+" cost? $");
- double cost = sc.nextDouble();
- System.out.println("How many days do you want to simulate? ");
- int days = sc.nextInt();
- while(days>0) {
- //Calculate the number of items sold and the total
- //Math.random is EXCLUSIVE on the upper bound
- int sold = (int)(Math.random() * 25);
- System.out.println("Today you sold "+sold+" "+ item+".");
- double total = cost*sold*100;
- total=(int)total;
- total=(double)total;
- total=total/100;
- System.out.println("You made $" + total);
- //Dictator Davis' Store
- int max = sold + 5;
- int min = sold - 3;
- double ddCost=-1;
- int ddSold= (int)(Math.random()*(max-min+1)+min);
- while (ddCost<=0) {
- ddCost = cost - Math.random()*2;
- }
- double ddTotal = ddSold*ddCost;
- System.out.println("Your main competitor is Dictator Davis' "+item+" Emporium");
- System.out.println("Today they sold "+ddSold+" "+item+" and they made $"+ddTotal);
- if(ddTotal>total) {
- System.out.println("You are really bad at this");
- }else {
- System.out.println("Good job, you won");
- }
- days--;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement