diff --git a/.vscode/settings.json b/.vscode/settings.json index 3fe1f5c..c122de0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,9 +18,8 @@ "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, "java.server.launchMode": "Standard" -} +} \ No newline at end of file diff --git a/_01_02b/Employee.class b/_01_02b/Employee.class new file mode 100644 index 0000000..657702e Binary files /dev/null and b/_01_02b/Employee.class differ diff --git a/_01_02b/Employee.java b/_01_02b/Employee.java index 12928d5..99f965f 100644 --- a/_01_02b/Employee.java +++ b/_01_02b/Employee.java @@ -5,35 +5,48 @@ 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. + double sum = firstBonus+secondBonus+thirdBonus; + System.out.println(sum); } diff --git a/_01_04/MenuBuilder.java b/_01_04/MenuBuilder.java index aeaebc5..6c50e19 100644 --- a/_01_04/MenuBuilder.java +++ b/_01_04/MenuBuilder.java @@ -7,26 +7,37 @@ 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("Break Fast"); // 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("Programming_in_java"); + // 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("Ubwali"); // 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_04/MenuItem.class b/_01_04/MenuItem.class new file mode 100644 index 0000000..a77cdef Binary files /dev/null and b/_01_04/MenuItem.class differ diff --git a/_01_05b/MenuBuilder.java b/_01_05b/MenuBuilder.java index cc35ba3..7e17c03 100644 --- a/_01_05b/MenuBuilder.java +++ b/_01_05b/MenuBuilder.java @@ -3,30 +3,41 @@ import java.util.ArrayList; public class MenuBuilder { + /** + * @param args + */ public static void main(String[] args) { // Create a variable called menuTitle of type String and assign it the value "My // Dream Menu:". + String menuTitle = "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("Jollof Rice"); // 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("Ubwali"); // 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("tagine"); // 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_02/Ticket.class b/_02_02/Ticket.class new file mode 100644 index 0000000..c4bf5df Binary files /dev/null and b/_02_02/Ticket.class differ diff --git a/_02_02/Ticket.java b/_02_02/Ticket.java new file mode 100644 index 0000000..3dfb316 --- /dev/null +++ b/_02_02/Ticket.java @@ -0,0 +1,17 @@ +package _02_02; + +public class Ticket { + + private String destination; + private double price; + private boolean isReturn; + + public Ticket() { + + } + +public static void main(String args[]){ +Ticket ticket = new Ticket(); +System.out.println(ticket); +} +} \ No newline at end of file diff --git a/_02_03b/Ticket.java b/_02_03b/Ticket.java new file mode 100644 index 0000000..912827d --- /dev/null +++ b/_02_03b/Ticket.java @@ -0,0 +1,11 @@ +package _02_03b; + +public class Ticket { + private String destination; + private double price; + private boolean isReturn; + + public Ticket() { + + } +} diff --git a/_02_05b/Ticket.java b/_02_05b/Ticket.java index 339f8a0..33f7994 100644 --- a/_02_05b/Ticket.java +++ b/_02_05b/Ticket.java @@ -12,8 +12,25 @@ 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 price){ + this.price = price; + } + public void setIsReturn(boolean isReturn){ + this.isReturn = isReturn; + } // 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_06/TicketMachine.java b/_02_06/TicketMachine.java index 70c43e1..ea81940 100644 --- a/_02_06/TicketMachine.java +++ b/_02_06/TicketMachine.java @@ -4,18 +4,24 @@ 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/_02_07b/TicketMachine.java b/_02_07b/TicketMachine.java index 77398c3..cb94eae 100644 --- a/_02_07b/TicketMachine.java +++ b/_02_07b/TicketMachine.java @@ -1,23 +1,27 @@ package _02_07b; public class TicketMachine { - -public static void main(String[] args) { - // Create an object called ticket of type Ticket - // Set the destination of the ticket to New York + public static void main(String[] args) { + // Create an object called ticket of type Ticket + Ticket ticket = new Ticket(); - // Set the price of the ticket to 15.30 + // Set the destination of the ticket to New York + ticket.setDestination("New York"); - // Set the isReturn value to true + // Set the price of the ticket to 15.30 + ticket.setPrice(15.30); - // Print the ticket's destination to the console + // 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 - - // Print the ticket's isReturn value to the console - -} + // 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..2950001 100644 --- a/_03_03b/GradingSystem.java +++ b/_03_03b/GradingSystem.java @@ -5,7 +5,12 @@ public class GradingSystem { public boolean isAPass(int percentage) { // Return true if the percentage is higher than or equal to 60. // Otherwise return false. - return false; + if (percentage >= 60) { + return true; + } else { + return false; + + } } public char getGrade(int percentage) { @@ -14,17 +19,41 @@ public char getGrade(int percentage) { // If it's 70-79, return 'C'. // If it's 60-69, return 'D'. // If it's less than 60, return 'F'. - return 'X'; + if (percentage >= 90) { + return 'A'; + } else if (percentage >= 80 && percentage <= 89) { + return 'B'; + } else if (percentage >= 70 && percentage <= 79) { + return 'C'; + } else if (percentage <= 60 && percentage <= 69) { + return 'D'; + } else if (percentage < 60) { + return 'F'; + } else { + return 'X'; + } } public String retakeMessage(int percentage, boolean allowedToRetake) { // If percentage is less than 60 and allowedToRetake is true, return a String + if (percentage < 60 && allowedToRetake == true) { + return "he student has been entered for a retake."; + } // that says "The student has been entered for a retake." // If percentage is less than 60 and allowedToRetake is false, return a String + if (percentage < 60 && allowedToRetake == false) { + return "he student is not allowed to retake this exam."; + } // that says "The student is not allowed to retake this exam." // If percentage is 60 or higher, return a String that says "A retake is not + if (percentage >= 60) { + return "A retake is not required"; + } // required." - return ""; + else { + return ""; + } + } } diff --git a/_03_04/ForLoops.class b/_03_04/ForLoops.class new file mode 100644 index 0000000..ce23bb8 Binary files /dev/null and b/_03_04/ForLoops.class differ diff --git a/_03_04/ForLoops.java b/_03_04/ForLoops.java index 11a2292..dc5f5ba 100644 --- a/_03_04/ForLoops.java +++ b/_03_04/ForLoops.java @@ -1,14 +1,26 @@ package _03_04; public class ForLoops { + private static int x; public static void main(String[] args) { // Write a for loop that prints out the phrase "I love for loops" 5 times + for (x = 0; x <= 5; x++) { + System.out.println("I love for loops"); + System.out.println(x); + } + System.out.println("first loop ends............."); // Write a for loop that prints out the numbers 1 to 10 + for (x = 1; x < 11; x++) { + System.out.println(x); + } + System.out.println("the second loop ends........"); // Write a for loop that prints out the numbers 10 to 1 - + for (x = 10; x > 0; x--) { + System.out.println(x); + } } diff --git a/_03_06/EnhancedForLoops.class b/_03_06/EnhancedForLoops.class new file mode 100644 index 0000000..aab70b9 Binary files /dev/null and b/_03_06/EnhancedForLoops.class differ diff --git a/_03_06/EnhancedForLoops.java b/_03_06/EnhancedForLoops.java index 0008f6d..c590923 100644 --- a/_03_06/EnhancedForLoops.java +++ b/_03_06/EnhancedForLoops.java @@ -8,13 +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 prime:primeNumbers){ + System.out.println(prime); + } 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 weekDay:weekDays){ + System.out.println(weekDay); + } 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 rand:randomNumbers){ + if (rand > 50){ + System.out.println(rand); + } + } } diff --git a/_03_07b/EnhancedForLoops.class b/_03_07b/EnhancedForLoops.class new file mode 100644 index 0000000..262384d Binary files /dev/null and b/_03_07b/EnhancedForLoops.class differ diff --git a/_03_07b/EnhancedForLoops.java b/_03_07b/EnhancedForLoops.java index 40d3207..357aeb9 100644 --- a/_03_07b/EnhancedForLoops.java +++ b/_03_07b/EnhancedForLoops.java @@ -8,13 +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 prime:primeNumbers){ + System.out.println(prime); + } 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 weekDay :weekDays){ + System.out.println(weekDay); + } 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 rand:randomNumbers){ + if(rand > 50){ + System.out.println(rand); + } + } }