Initial Commit
This commit is contained in:
27
Source Code/Assignment6/src/LeapYearCheck.java
Normal file
27
Source Code/Assignment6/src/LeapYearCheck.java
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
*This class takes a given date and tells the user if it is a leap year
|
||||
* @author Isaac Shoebottom (3429069)
|
||||
*/
|
||||
public class LeapYearCheck {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
java.util.Scanner scanner = new java.util.Scanner(System.in);
|
||||
long year;
|
||||
do {
|
||||
System.out.print("Please enter a year: ");
|
||||
year = scanner.nextLong();
|
||||
if (year < 1582) {
|
||||
System.out.println("Invalid Year, you cannot enter a year prior to 1582");
|
||||
}
|
||||
}
|
||||
while (year < 1582);
|
||||
|
||||
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) {
|
||||
System.out.println("This is a leap year");
|
||||
}
|
||||
else {
|
||||
System.out.println("This is not a leap year.");
|
||||
}
|
||||
}
|
||||
}
|
71
Source Code/Assignment6/src/MakingChange.java
Normal file
71
Source Code/Assignment6/src/MakingChange.java
Normal file
@ -0,0 +1,71 @@
|
||||
/**
|
||||
* This class returns the amount of change the user would be given provided they give the amount they paid and the price of their items
|
||||
* @author Isaac Shoebottom (3429069)
|
||||
*/
|
||||
|
||||
public class MakingChange {
|
||||
public static void main(String[] args){
|
||||
java.util.Scanner scanner = new java.util.Scanner(System.in);
|
||||
double totalPrice;
|
||||
double amountPaid;
|
||||
long changeTotal;
|
||||
|
||||
do {
|
||||
do {
|
||||
System.out.print("Please enter the total price: ");
|
||||
totalPrice = scanner.nextDouble();
|
||||
if (totalPrice <= 0) {
|
||||
System.out.println("Invalid input. Please enter a positive number");
|
||||
}
|
||||
}
|
||||
while (totalPrice <= 0);
|
||||
|
||||
do {
|
||||
System.out.print("Please enter the amount paid: ");
|
||||
amountPaid = scanner.nextDouble();
|
||||
if (amountPaid <= 0) {
|
||||
System.out.println("Invalid input. Please enter a positive number");
|
||||
}
|
||||
}
|
||||
while (amountPaid < 0);
|
||||
changeTotal = (long)(amountPaid*100) - (long)(totalPrice*100);
|
||||
if (changeTotal< 0) {
|
||||
System.out.println("Invalid inputs. The amount of change given must be at least zero \n");
|
||||
}
|
||||
}
|
||||
while (changeTotal < 0);
|
||||
|
||||
|
||||
long twenties = (changeTotal/2000);
|
||||
changeTotal -= (twenties * 2000);
|
||||
long tens = (changeTotal/1000);
|
||||
changeTotal -= (tens * 1000);
|
||||
long fives = (changeTotal/500);
|
||||
changeTotal -= (fives * 500);
|
||||
long toonies = (changeTotal/200);
|
||||
changeTotal -= (toonies * 200);
|
||||
long loonies = (changeTotal/100);
|
||||
changeTotal -= (loonies * 100);
|
||||
long quarters = (changeTotal/25);
|
||||
changeTotal -= (quarters * 25);
|
||||
long dimes = (changeTotal/10);
|
||||
changeTotal -= (dimes * 10);
|
||||
long nickels = (changeTotal/5);
|
||||
changeTotal -= (nickels * 5);
|
||||
long pennies = changeTotal;
|
||||
|
||||
System.out.println(
|
||||
"\n" +
|
||||
"Here is the change that they are due:\n" +
|
||||
"20$ bills: " + twenties + "\n" +
|
||||
"10$ bills: " + tens + "\n" +
|
||||
"5$ bills: " + fives + "\n" +
|
||||
"Toonies: " + toonies + "\n" +
|
||||
"Loonies: " + loonies + "\n" +
|
||||
"Quarters: " + quarters + "\n" +
|
||||
"Dimes: " + dimes + "\n" +
|
||||
"Nickels: " + nickels + "\n" +
|
||||
"Pennies: " + pennies
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user