Guest User

Zoo Code 2

a guest
Jul 26th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ZooTask {
  4.    
  5.     public static void main (String[] args) {
  6.      
  7.    
  8.         // Setting running total variable
  9.         int RunningTotal = 0;
  10.         // Setting group total variable
  11.         int GroupTotal = 0;
  12.         // Setting group variable
  13.         int EnterGroup;
  14.        
  15.         // Create a Scanner to take input from user
  16.         Scanner input = new Scanner(System.in);
  17.         System.out.println("Enter a group? Yes=1/No=0");
  18.        
  19.         while ((EnterGroup = input.nextInt()) == 1 ); {
  20.                
  21.             System.out.println("Enter the number of children (age 6–15): ");
  22.             int children = input.nextInt();
  23.                
  24.             System.out.println("Enter the number of adults (age 16–59): ");
  25.             int adults = input.nextInt();
  26.                
  27.             System.out.println("Enter the number of seniors (age 60+): ");
  28.             int seniors = input.nextInt();
  29.             //Setting variables for calculations
  30.             int childCharge = 0;
  31.             int childUnC = 0;
  32.             int childAcc = 0;
  33.             int totalAdult = 0;
  34.             int adultCharge = adults * 10;
  35.             int seniorsCharge = seniors * 8;
  36.             //calculating childcharge
  37.             if (children <= adults || children <= seniors){
  38.                 childCharge= children * 2;
  39.                 }
  40.             else if (children >= adults || children >= seniors){
  41.                 totalAdult = adults + seniors;
  42.                 childUnC = (children - totalAdult);
  43.                 childAcc = (children - childUnC);
  44.                 childCharge = (childAcc * 2) + (childUnC * 5);
  45.                 }
  46.             //determining the group total
  47.             GroupTotal = (adultCharge + seniorsCharge + childCharge);
  48.             //displaying the group total        
  49.             System.out.println("Total entry charge is: $" + GroupTotal);
  50.             //adding group total to running total
  51.             RunningTotal+=GroupTotal;
  52.             System.out.println();
  53.            
  54.             System.out.println("Enter a group? Yes=1/No=0");
  55.             EnterGroup = input.nextInt();          
  56.         }
  57.         //printing the total takings            
  58.     System.out.println("Total takings: $" + RunningTotal);
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment