Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first task compete #4

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Binary file added _01_02b/Employee.class
Binary file not shown.
13 changes: 13 additions & 0 deletions _01_02b/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down
11 changes: 11 additions & 0 deletions _01_04/MenuBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<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("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);
}
}
Binary file added _01_04/MenuItem.class
Binary file not shown.
15 changes: 13 additions & 2 deletions _01_05b/MenuBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Binary file added _02_02/Ticket.class
Binary file not shown.
17 changes: 17 additions & 0 deletions _02_02/Ticket.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
11 changes: 11 additions & 0 deletions _02_03b/Ticket.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package _02_03b;

public class Ticket {
private String destination;
private double price;
private boolean isReturn;

public Ticket() {

}
}
19 changes: 18 additions & 1 deletion _02_05b/Ticket.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 7 additions & 1 deletion _02_06/TicketMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());

}

Expand Down
28 changes: 16 additions & 12 deletions _02_07b/TicketMachine.java
Original file line number Diff line number Diff line change
@@ -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());
}

}
35 changes: 32 additions & 3 deletions _03_03b/GradingSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 "";
}

}

}
Binary file added _03_04/ForLoops.class
Binary file not shown.
14 changes: 13 additions & 1 deletion _03_04/ForLoops.java
Original file line number Diff line number Diff line change
@@ -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);
}

}

Expand Down
Binary file added _03_06/EnhancedForLoops.class
Binary file not shown.
11 changes: 11 additions & 0 deletions _03_06/EnhancedForLoops.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<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 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);
}
}

}

Expand Down
Binary file added _03_07b/EnhancedForLoops.class
Binary file not shown.
Loading