Question: Draw a flowchart for the following code : import java.util.Scanner; public class ThemePark { public static void main(String[] args) { Scanner scan = new Scanner(System.in);

Draw a flowchart for the following code :

import java.util.Scanner;

public class ThemePark {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in); int age; double amt, totalAmt = 0.0; int answer;

do { System.out.println("WELCOME TO XYZ WATER THEME PARK!"); System.out.println("*********************");

System.out.print(" How may tickets?: "); int num = scan.nextInt(); amt = 0.0;

for (int i = 1; i <= num; i++) { System.out.print("Enter the age of visitor " + i + ": "); age = scan.nextInt();

// Now calculating price

amt += calculatePrice(age); }

// Now calling discountedPrice method if visitor(s) has membership

System.out.print("Membership card?: [Y/N] "); char ans = scan.next().charAt(0);

if (ans == 'Y' || ans == 'y') { totalAmt = discountedPrice(amt); } else totalAmt = amt;

// Showing total amount System.out.println("Total amount: RM" + totalAmt);

// Asking user for next System.out.println(" THANK YOU. PLEASE COME AGAIN!");

System.out.println("***********************"); System.out.println("Do you want to continue?"); System.out.print("Please enter an integer or -1 to stop: "); answer = scan.nextInt();

} while(answer != -1); }

// calculatePrice method which calculates and return price based on age

public static double calculatePrice(int age) {

double price = 0.0; if (age <= 12) price = 30.00; else if(age >= 13 && age <= 60) price = 60.00; else price = 20.00;

return price; }

public static double discountedPrice(double price) {

// Applying discount and return price

double discount = price * 0.20; return price - discount; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!