logotransparent.png

Legion of Learners

www.lol-101.com

  • Home

  • Classrooms

  • Courses

  • About Us

    • Executive Team
    • Board Members
  • Resources

  • More

    Use tab to navigate through the menu items.
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    kevinzhao183
    Jul 19, 2020
      ·  Edited: Jul 19, 2020

    Intro to Java 7/18 Homework

    in Java Question Bank

    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.

    8 comments
    0
    isaac.k.hsu
    Jul 19, 2020

    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%");
    		}
    	}
    }

    0
    afefe2007
    Jul 22, 2020

    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."); } } }

    0
    jonathan.cheng.2004
    Jul 20, 2020

    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"); } } }

    0
    andymei2007
    Jul 22, 2020

    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"); } } }

    0
    ivanyu521
    Jul 22, 2020

    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"); } } }



    0
    ivanyu521
    Jul 22, 2020

    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"); } } }



    0
    afefe2007
    Jul 22, 2020

    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."); } } }

    0
    epicmaxawesome
    Jul 25, 2020

    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.");

    }

    }

    }

    0
    8 comments

    Questions? Email us at legionoflearners@gmail.com or join our WeChat group!

    • lol-101dotcom

    ©2020 Legion of Learners