write Java code that uses a Selection Structure(s) to determine the movie price for a movie patron. Seniors 65 and older pay $10.00, under 5 years old are free, all other ages are $20.00, with one exception - college students under the age of 30 with a valid student ID receive a $5 discount, thus paying $15.00, be sure to use Single Boolean expressions when you can.
Solution
Code
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner scr=new Scanner(System.in);
int age;
double price;
char collegeid;
System.out.println("Enter the age
of the movie patron");
age=scr.nextInt();
if(age>65)
{
price=10.00;
System.out.println("Seniors should
pay $"+price);
}
else if(age<5)
{
price=0.00;
System.out.println("For childrens
it is free");
}
else if(age<30)
{
System.out.println("Do you have
valid student Id(y/n)");
collegeid = scr.next().charAt(0);
if(collegeid=='y')
{
price=15.00;
System.out.println("College student
with valid id should pay $"+price);
}
else
{
price=20.00;
System.out.println("College student
with out valid id should pay $"+price);
}
}
}
}
Screenshot
Output
---
all the best
Get Answers For Free
Most questions answered within 1 hours.