Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- // Define variables
- double a; // price for child card
- double b; // price for adult card
- int countA; // counter for child card
- int countB; // counter for adult card
- int x; // number of child cards to buy
- int y; // number of adult cards to buy
- Scanner in = new Scanner(System.in);
- // 1. set price for each card
- // a = 13.70;
- // b = 15.20;
- do {
- System.out.print("Enter price for child card: ");
- a = in.nextDouble();
- } while (a <=0);
- do {
- System.out.print("Enter price for adult card: ");
- b = in.nextDouble();
- } while (b <=0);
- // 2. initialize counters to zero
- countA = 0;
- countB = 0;
- // 3. get number of cards to buy
- System.out.print("Enter number of child cards: ");
- x = in.nextInt();
- System.out.print("Enter number of adult cards: ");
- y = in.nextInt();
- // 4. start a loop
- while (x > 0 || y > 0) {
- double total=0;
- if (x>0) {
- // 4.1 calculate total price
- total += x*a;
- // 4.3 update counters
- countA += x;
- }
- if (y>0) {
- // 4.1 calculate total price
- total += y*b;
- // 4.3 update counters
- countB += y;
- }
- // 4.2 show message
- System.out.println("Toatl price is: " + total);
- // next customer
- // 4.4 get new values for next customer
- System.out.print("Enter number of child cards: ");
- x = in.nextInt();
- System.out.print("Enter number of adult cards: ");
- y = in.nextInt();
- } // end of while
- // 5. print number of cards
- System.out.println("Toatl child cards is: " + countA);
- System.out.println("Toatl adult cards is: " + countB);
- // 6. calculate and show total
- System.out.println("Toatl money for this day is: " + (countA*a + countB*b));
- // close scanner
- in.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement