23 May 2011 ~ 0 Comments

Child Discount – Java Example

Well today I have finally written my first piece of code (From memory) and thought I would share it with you. The code asks for the users age, and then applies a discount if they are under that age. Basic I know, but it does the job.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//ask for users age and then discount if under 14
import java.util.*;
public class ChildDiscountIf {

public static void main(String[] args) {
//Set the price and double - long number
double price = 10.00;
int age;
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter your age:- ");
age = keyboard.nextInt(); // ask for input

if (age <= 14) // if 14 or below add the child discount
{
System.out.println("Half price Child Ticket");
price = price/2;
}

System.out.println("Total price: £" + price);
}
}

It’s rather basic, but like I have said – It does the job and at least I’m learning

Be Sociable, Share!

No related posts.

Leave a Reply

show
 
close
#oGame still play it after so many years, if anyone is #bored give it a go http://t.co/3HKrOZtR