A restaurant is deciding to give a discount to customers based on their age. Children under 12 years old will get a discount of 20%, while all other people will get no discount. Write a program that takes an age as an input and outputs what kind of discount a person of that age would get. Comment your solution below.
top of page
bottom of page
import java.util.Scanner;
class Main {
publicstaticvoid main(String[] args) {
System.out.println("What is your age?");
Scanner sc = new Scanner(System.in);
double b = sc.nextln();
if (b < 0 ) {
System.out.println("Invalid Age");
} elseif (0 < b < 13) {
System.out.println("Fortunately, you have a 20% discount!");
} else {
System.out.println("You will need to pay the full price of what you are ordering.");
}
}
}
import java.util.Scanner; class Main { public static void main(String[] args) { System.out.println("What is your age?"); Scanner sc = new Scanner(System.in); double b = sc.nextln(); if (b < 0 ) { System.out.println("Invalid Age"); } else if (0 < b < 13) { System.out.println("Fortunately, you have a 20% discount!"); } else { System.out.println("You will need to pay the full price of what you are ordering."); } } }
import java.util.Scanner; class Main { public static void main(String[] args) { System.out.println("What is your age?"); Scanner sc = new Scanner(System.in); int age = sc.nextInt(); if (age<12){ System.out.println("You are eligible for a 20% Discount."); } else { System.out.println("Not available for a Discount"); } } }
import java.util.*; class Main { public static void main(String[] args) { System.out.println("What is your age?"); Scanner sc = new Scanner(System.in); int age = sc.nextInt(); if (age<12){ System.out.println("You are eligible for a 20% Discount."); } else { System.out.println("Not available for a Discount"); } } }
import java.util.Scanner; class Main { public static void main(String[] args) { System.out.println("What is your age?"); Scanner sc = new Scanner (System.in); int age = sc.nextInt(); if (age < 12) { System.out.println("You get a discount of 20%"); } else { System.out.println("You get no discount"); } } }
import java.util.*; class Main { public static void main(String[] args) { System.out.println("What is your age?"); Scanner sc = new Scanner(System.in); int b = sc.nextInt(); if (b<12){ System.out.println("You get a 20% Discount."); } else { System.out.println("You are not eligible for a discount"); } } }
This is my program:
import java.util.Scanner; public class Restaurant { public static void main(String[] args) { System.out.print("What is the age of guest: "); Scanner a = new Scanner(System.in); int b = a.nextInt(); if(b < 0) { System.out.print("Invalid age"); } else if(b < 12) { System.out.print("Discount: 20%"); } else { System.out.print("Discount: 0%"); } } }