Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
Week3Assessment_Jonathon.Adlington
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jonathon.adlington
Week3Assessment_Jonathon.Adlington
Commits
4d8d4c06
Commit
4d8d4c06
authored
Oct 07, 2017
by
Jonathon Adlington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comments added
parent
9cac4de9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
9 deletions
+39
-9
three.java
Acsending_Order/Acsending_Order/src/three.java
+8
-3
leap.java
Leap_Year/Leap_Year/src/leap.java
+9
-0
cost.java
Postage_Cost/Postage_Cost/src/cost.java
+22
-6
No files found.
Acsending_Order/Acsending_Order/src/three.java
View file @
4d8d4c06
...
...
@@ -5,13 +5,18 @@ public class three {
public
static
void
main
(
String
[]
args
)
{
// TODO Auto-generated method stub
int
fn
,
sn
,
tn
;
System
.
out
.
println
(
"Enter three numbers"
);
int
fn
,
sn
,
tn
;
// declared integers
System
.
out
.
println
(
"Enter three numbers"
);
//input prompt
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
();
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
&&
sn
<
tn
)
...
...
Leap_Year/Leap_Year/src/leap.java
View file @
4d8d4c06
...
...
@@ -11,6 +11,15 @@ public class leap {
Scanner
in
=
new
Scanner
(
System
.
in
);
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
)
{
System
.
out
.
println
(
year
+
" is a leap year"
);
...
...
Postage_Cost/Postage_Cost/src/cost.java
View file @
4d8d4c06
...
...
@@ -6,29 +6,45 @@ public class cost {
public
static
void
main
(
String
[]
args
)
{
// 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)..."
);
Scanner
in
=
new
Scanner
(
System
.
in
);
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
)
{
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
)
{
System
.
out
.
printf
(
weight
+
"kg"
+
" =
£
"
+
"%.2f"
,
weight
*
3
);
System
.
out
.
printf
(
weight
+
"kg"
+
" = £"
+
"%.2f"
,
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
)
{
System
.
out
.
printf
(
weight
+
"kg"
+
" =
£
"
+
"%.2f"
,
weight
*
5
);
System
.
out
.
printf
(
weight
+
"kg"
+
" = £"
+
"%.2f"
,
weight
*
5
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment