Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ZooTask {
- public static void main (String[] args) {
- // Setting running total variable
- int RunningTotal = 0;
- // Setting group total variable
- int GroupTotal = 0;
- // Setting group variable
- int EnterGroup;
- // Create a Scanner to take input from user
- Scanner input = new Scanner(System.in);
- System.out.println("Enter a group? Yes=1/No=0");
- while ((EnterGroup = input.nextInt()) == 1 ); {
- System.out.println("Enter the number of children (age 6–15): ");
- int children = input.nextInt();
- System.out.println("Enter the number of adults (age 16–59): ");
- int adults = input.nextInt();
- System.out.println("Enter the number of seniors (age 60+): ");
- int seniors = input.nextInt();
- //Setting variables for calculations
- int childCharge = 0;
- int childUnC = 0;
- int childAcc = 0;
- int totalAdult = 0;
- int adultCharge = adults * 10;
- int seniorsCharge = seniors * 8;
- //calculating childcharge
- if (children <= adults || children <= seniors){
- childCharge= children * 2;
- }
- else if (children >= adults || children >= seniors){
- totalAdult = adults + seniors;
- childUnC = (children - totalAdult);
- childAcc = (children - childUnC);
- childCharge = (childAcc * 2) + (childUnC * 5);
- }
- //determining the group total
- GroupTotal = (adultCharge + seniorsCharge + childCharge);
- //displaying the group total
- System.out.println("Total entry charge is: $" + GroupTotal);
- //adding group total to running total
- RunningTotal+=GroupTotal;
- System.out.println();
- System.out.println("Enter a group? Yes=1/No=0");
- EnterGroup = input.nextInt();
- }
- //printing the total takings
- System.out.println("Total takings: $" + RunningTotal);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment