Commit 4d8d4c06 authored by Jonathon Adlington's avatar Jonathon Adlington

comments added

parent 9cac4de9
...@@ -5,13 +5,18 @@ public class three { ...@@ -5,13 +5,18 @@ public class three {
public static void main(String[] args) { public static void main(String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
int fn, sn, tn; int fn, sn, tn;// declared integers
System.out.println("Enter three numbers"); System.out.println("Enter three numbers");//input prompt
Scanner in = new Scanner(System.in); Scanner in = new Scanner(System.in);
fn = in.nextInt(); fn = in.nextInt();// used to allow user to in put a number after pressing enter each time
sn = in.nextInt(); sn = in.nextInt();
tn = in.nextInt(); tn = in.nextInt();
/*
These "if" statements are checking each number, which the user has entered, against the other.
They are checking to see which one is biggest and putting them in order. The output will be the 3
numbers, that the user has entered, are put in ascending order.
*/
if(fn < sn) if(fn < sn)
{ {
if(fn < sn && sn < tn) if(fn < sn && sn < tn)
......
...@@ -11,6 +11,15 @@ public class leap { ...@@ -11,6 +11,15 @@ public class leap {
Scanner in = new Scanner(System.in); Scanner in = new Scanner(System.in);
year = in.nextInt(); year = in.nextInt();
/*
This if statement is in a particular order, it is checking the year is a leap year before
concluding that it isn't. The reason i have the if statement check the year against 400 before 4
is to prevent the year 1900 being printed as a leap year. Then when 1900 is then checked against the next if statement
it is checked to see if is is divisible by 4 but NOT divisible by 100. A leap year which is divisible by 100,
like the year 2000 would have already met the condition of being divisible by 400 so it wont miss it out.
Then if the user input has not met the condition of the else if statement then it must not be a leap year.
*/
if(year % 400 == 0) if(year % 400 == 0)
{ {
System.out.println(year + " is a leap year"); System.out.println(year + " is a leap year");
......
...@@ -6,29 +6,45 @@ public class cost { ...@@ -6,29 +6,45 @@ public class cost {
public static void main(String[] args) { public static void main(String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
float weight; float weight;// i used a float here so the user can enter a decimal number.
System.out.println("Please enter weight(kg)..."); System.out.println("Please enter weight(kg)...");
Scanner in = new Scanner(System.in); Scanner in = new Scanner(System.in);
weight = in.nextFloat(); weight = in.nextFloat();
/*
This if statement will check that the weight is between a certain amount to coincide
with the given rates
The rates are:
• Less than 1 kilogram: 1.5 (per kg)
• 1 - 2 kilograms: 3.0 (per kg)
• 2 - 3 kilograms: 4.0 (per kg)
• Over 3 kilograms: 5.0 (per kg)
*/
if(weight < 1) if(weight < 1)
{ {
System.out.printf(weight + "kg" + " = £" + "%.2f", weight * 1.5); System.out.printf(weight + "kg" + " = £" + "%.2f", weight * 1.5);
/*
this and the following line of code reads like this - weight that the user has put in,
the the console then prints the kg after it and = £ of the cost of posting it
at two decimal places and is worked out by weight*1.5(per kg)
*/
} }
else if(weight < 2) else if(weight < 2)
{ {
System.out.printf(weight + "kg" + " = £" + "%.2f", weight * 3); System.out.printf(weight + "kg" + " = £" + "%.2f", weight * 3);
} }
else if(weight < 3) else if(weight < 3)
{ {
System.out.printf(weight + "kg" + " = £" + "%.2f", weight * 4); System.out.printf(weight + "kg" + " = £" + "%.2f", weight * 4);
} }
else if(weight > 3) else if(weight > 3)
{ {
System.out.printf(weight + "kg" + " = £" + "%.2f", weight * 5); System.out.printf(weight + "kg" + " = £" + "%.2f", weight * 5);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment