Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions _01_02b/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down
10 changes: 10 additions & 0 deletions _01_04/MenuBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<MenuItem> 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);
}
}
11 changes: 11 additions & 0 deletions _01_05b/MenuBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<MenuItem> 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);
}
}
12 changes: 12 additions & 0 deletions _02_03b/Ticket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package _02_03b;

public class Ticket {

public Ticket() {

}

private String destination;
private double price;
private Boolean isReturn;
}
1 change: 0 additions & 1 deletion _02_04/Ticket.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ public Ticket() {

// Add a separate method to get the value of each field, called getDestination,
// getPrice and getIsReturn.

}
24 changes: 24 additions & 0 deletions _02_05b/Ticket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
7 changes: 7 additions & 0 deletions _02_07b/TicketMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());

}

Expand Down
27 changes: 27 additions & 0 deletions _03_03b/GradingSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
}

Expand Down
2 changes: 1 addition & 1 deletion _03_03b/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
11 changes: 10 additions & 1 deletion _03_05b/ForLoops.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

}
12 changes: 11 additions & 1 deletion _03_07b/EnhancedForLoops.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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);
}
}
}

}