diff --git a/.vscode/settings.json b/.vscode/settings.json index 3fe1f5c..de48ede 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,7 +18,6 @@ "files.autoSave": "afterDelay", "screencastMode.onlyKeyboardShortcuts": true, "terminal.integrated.fontSize": 18, - "workbench.activityBar.visible": true, "workbench.colorTheme": "Visual Studio Dark", "workbench.fontAliasing": "antialiased", "workbench.statusBar.visible": true, diff --git a/_01_02b/Employee.java b/_01_02b/Employee.java index 12928d5..7a9e497 100644 --- a/_01_02b/Employee.java +++ b/_01_02b/Employee.java @@ -5,35 +5,47 @@ public class Employee { public static void main(String[] args) { // Create a variable called age of type int and assign it the value 29. + int age = 29; // Print the age variable to the console. + System.out.println(age); // Create a variable called isAManager of type boolean and assign it the value // true. + Boolean isAManager = true; // Print the isAManager variable to the console. + System.out.println(isAManager); // Create a variable called yearsOfService of type double and assign it the // value 2.5. + double yearsOfService = 2.5; // Print the yearsOfService variable to the console. + System.out.println(yearsOfService); // Create a variable called baseSalary of type int and assign it the value 3000. + int baseSalary = 3000; // Create a variable called overtimePayment of type int and assign it the value // 40. + int overtimePayment = 40; // Create a variable called totalPayment of type int and assign it to the value // of baseSalary added to overtimePayment. + int totalPayment = baseSalary + overtimePayment; // Print the totalPayment variable to the console. + System.out.println( totalPayment); // Create three variables all of type double on a single line. // They should be called firstBonus, secondBonus and thirdBonus and they should // be assigned the values 10.00, 22.00 and 35.00. + double firstBonus = 10.00, secondBonus = 22.00, thirdBonus = 35.00; // Print out the sum of the variables called firstBonus, secondBonus and // thirdBonus. + System.out.println(firstBonus+secondBonus+thirdBonus); } diff --git a/_01_04/MenuBuilder.java b/_01_04/MenuBuilder.java index aeaebc5..afce96c 100644 --- a/_01_04/MenuBuilder.java +++ b/_01_04/MenuBuilder.java @@ -7,26 +7,36 @@ public static void main(String[] args) { // Create a variable called menuTitle of type String and assign it the value "My // Dream Menu:". + String menuTitle = "My Dream Menu:"; // Print the menuTitle variable to the console. + System.out.println(menuTitle); // Create a variable called menu of type ArrayList. + ArrayList menu = new ArrayList<>(); // Create a variable called starter of type MenuItem and pass in the name of // your favourite starter. + MenuItem starter = new MenuItem("Fanta"); // Add the starter variable to the ArrayList called menu. + menu.add(starter); // Create a variable called mainCourse of type MenuItem and pass in the name of // your favourite main course. + MenuItem mainCourse = new MenuItem("Banku and Tilapia"); // Add the mainCourse variable to the ArrayList called menu. + menu.add(mainCourse); // Create a variable called dessert of type MenuItem and pass in the name of // your favourite dessert. + MenuItem dessert = new MenuItem("Strawberry cake"); // Add the dessert variable to the ArrayList called menu. + menu.add(dessert); // Print the menu variable to the console. + System.out.println(menu); } } diff --git a/_01_05b/MenuBuilder.java b/_01_05b/MenuBuilder.java index cc35ba3..7270211 100644 --- a/_01_05b/MenuBuilder.java +++ b/_01_05b/MenuBuilder.java @@ -8,25 +8,36 @@ public static void main(String[] args) { // Create a variable called menuTitle of type String and assign it the value "My // Dream Menu:". + String menuTitle = "My Dream Menu:"; + // Print the menuTitle variable to the console. + System.out.println(menuTitle); // Create a variable called menu of type ArrayList. + ArrayList menu = new ArrayList<>(); // Create a variable called starter of type MenuItem and pass in the name of // your favourite starter. + MenuItem starter = new MenuItem("Fanta"); // Add the starter variable to the ArrayList called menu. + menu.add(starter); // Create a variable called mainCourse of type MenuItem and pass in the name of // your favourite main course. + MenuItem mainCourse = new MenuItem("Banku and Tilapia"); // Add the mainCourse variable to the ArrayList called menu. + menu.add(mainCourse); // Create a variable called dessert of type MenuItem and pass in the name of // your favourite dessert. + MenuItem dessert = new MenuItem("Strawberry cake"); // Add the dessert variable to the ArrayList called menu. + menu.add(dessert); // Print the menu variable to the console. + System.out.println(menu); } } diff --git a/_02_03b/Ticket.java b/_02_03b/Ticket.java new file mode 100644 index 0000000..58f48b2 --- /dev/null +++ b/_02_03b/Ticket.java @@ -0,0 +1,12 @@ +package _02_03b; + +public class Ticket { + + public Ticket() { + + } + + private String destination; + private double price; + private Boolean isReturn; +} diff --git a/_02_04/Ticket.java b/_02_04/Ticket.java index 0fcbbf1..771d367 100644 --- a/_02_04/Ticket.java +++ b/_02_04/Ticket.java @@ -15,5 +15,4 @@ public Ticket() { // Add a separate method to get the value of each field, called getDestination, // getPrice and getIsReturn. - } diff --git a/_02_05b/Ticket.java b/_02_05b/Ticket.java index 339f8a0..4784b5e 100644 --- a/_02_05b/Ticket.java +++ b/_02_05b/Ticket.java @@ -13,7 +13,31 @@ public Ticket() { // Add three public methods to set the value of each field, called // setDestination, setPrice and setIsReturn. + + public void setDestination(String destination) { + this.destination = destination; + } + + public void setPrice(double value) { + this.price = value; + } + + public void setIsReturn(Boolean value) { + isReturn = value; + } + // Add three public methods to get the value of each field, called // getDestination, getPrice and getIsReturn. + public String getDestination(){ + return destination; + } + + public double getPrice(){ + return price; + } + + public Boolean getIsReturn(){ + return isReturn; + } } diff --git a/_02_07b/TicketMachine.java b/_02_07b/TicketMachine.java index 77398c3..be2dfd8 100644 --- a/_02_07b/TicketMachine.java +++ b/_02_07b/TicketMachine.java @@ -4,18 +4,25 @@ public class TicketMachine { public static void main(String[] args) { // Create an object called ticket of type Ticket + Ticket ticket = new Ticket(); // Set the destination of the ticket to New York + ticket.setDestination("New York"); // Set the price of the ticket to 15.30 + ticket.setPrice(15.30); // Set the isReturn value to true + ticket.setIsReturn(true);; // Print the ticket's destination to the console + System.out.println(ticket.getDestination()); // Print the ticket's price to the console + System.out.println(ticket.getPrice()); // Print the ticket's isReturn value to the console + System.out.println(ticket.getIsReturn()); } diff --git a/_03_03b/GradingSystem.java b/_03_03b/GradingSystem.java index c8717c7..a59a291 100644 --- a/_03_03b/GradingSystem.java +++ b/_03_03b/GradingSystem.java @@ -5,25 +5,52 @@ public class GradingSystem { public boolean isAPass(int percentage) { // Return true if the percentage is higher than or equal to 60. // Otherwise return false. + if (percentage >= 60) { + return true; + } return false; } public char getGrade(int percentage) { // If the percentage is 90 or above, return 'A'. + if (percentage >= 90) { + return 'A'; + } // If it's 80-89, return 'B'. + else if (percentage >= 80 && percentage <= 89) { + return 'B'; + } // If it's 70-79, return 'C'. + else if (percentage >= 70 && percentage <= 79) { + return 'C'; + } // If it's 60-69, return 'D'. + else if (percentage >= 60 && percentage <= 69) { + return 'D'; + } // If it's less than 60, return 'F'. + else if (percentage < 60) { + return 'F'; + } return 'X'; } public String retakeMessage(int percentage, boolean allowedToRetake) { // If percentage is less than 60 and allowedToRetake is true, return a String // that says "The student has been entered for a retake." + if (percentage < 60 && allowedToRetake) { + return "The student has been entered for a retake."; + } // If percentage is less than 60 and allowedToRetake is false, return a String // that says "The student is not allowed to retake this exam." + else if (percentage < 60 && !allowedToRetake) { + return "The student is not allowed to retake."; + } // If percentage is 60 or higher, return a String that says "A retake is not // required." + if (percentage > 59) { + return "A retake is not required"; + } return ""; } diff --git a/_03_03b/Main.java b/_03_03b/Main.java index 24d62f4..8f62a68 100644 --- a/_03_03b/Main.java +++ b/_03_03b/Main.java @@ -4,7 +4,7 @@ public class Main { public static void main(String[] args) { GradingSystem gradingSystem = new GradingSystem(); - int percentage = 85; + int percentage = 15; System.out.println("Percentage: " + percentage); System.out.println("Pass: " + gradingSystem.isAPass(percentage)); System.out.println("Grade: " + gradingSystem.getGrade(percentage)); diff --git a/_03_05b/ForLoops.java b/_03_05b/ForLoops.java index 3de83d3..88a0ed6 100644 --- a/_03_05b/ForLoops.java +++ b/_03_05b/ForLoops.java @@ -5,10 +5,19 @@ public class ForLoops { public static void main(String[] args) { // Write a for loop that prints out the phrase "I love for loops" 5 times + for (int i = 0; i < 5; i++) { + System.out.println("I love for loops"); + } + // Write a for loop that prints out the numbers 1 to 10 + for (int i = 1; i < 11; i++) { + System.out.println(i); + } // Write a for loop that prints out the numbers 10 to 1 - + for (int i = 10; i > 0; i--) { + System.out.println(i); + } } } diff --git a/_03_07b/EnhancedForLoops.java b/_03_07b/EnhancedForLoops.java index 40d3207..d75907c 100644 --- a/_03_07b/EnhancedForLoops.java +++ b/_03_07b/EnhancedForLoops.java @@ -8,14 +8,24 @@ public class EnhancedForLoops { public static void main(String[] args) { int[] primeNumbers = { 2, 3, 5, 7, 11, 13, 17, 19 }; // Write an enhanced for loop to print out each prime number in the array. + for (int value : primeNumbers) { + System.out.println(value); + } List weekDays = Arrays.asList("Monday", "Tuesday", "Wednesday", "Thursday", "Friday"); // Write an enhanced for loop to print out each week day in the list. + for (String day : weekDays) { + System.out.println(day); + } int[] randomNumbers = { 23, 51, 72, 84, 1, 60, 34, 102 }; // Write an enhanced for loop to print out the numbers in the array that are // greater than 50. + for (int value : randomNumbers) { + if (value > 50) { + System.out.println(value); + } + } } - }