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

Maven Project and Simple Java task created #16

Open
wants to merge 1 commit into
base: master
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
# Java Basic Training

Tugas:

Simple java: letter-grade, calender, factorial
-Letter-grade : penggunaan IF-ELSE, input angka, output grade
-Calender : penggunaan SWITCH, input angka, output bulan dalam tulisan
-Factorial : penggunaan LOOP, input angka, output hasil

Simple project: to-do list


61 changes: 61 additions & 0 deletions src/main/java/com/gdn/onboarding/onboardingjava/Calendar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.gdn.onboarding.onboardingjava;

public class Calendar {
private String month(int month) {
switch(month) {
case 1:
return "January";
case 2:
return "February";
case 3:
return "March";
case 4:
return "April";
case 5:
return "May";
case 6:
return "June";
case 7:
return "July";
case 8:
return "August";
case 9:
return "September";
case 10:
return "October";
case 11:
return "November";
default:
return "December";
}
}

public static void main(String[] args) {
Calendar calendar = new Calendar();
String month1 = calendar.month(1);
String month2 = calendar.month(2);
String month3 = calendar.month(3);
String month4 = calendar.month(4);
String month5 = calendar.month(5);
String month6 = calendar.month(6);
String month7 = calendar.month(7);
String month8 = calendar.month(8);
String month9 = calendar.month(9);
String month10 = calendar.month(10);
String month11 = calendar.month(11);
String month12 = calendar.month(12);

System.out.println("The first month is: " + month1);
System.out.println("The second month is: " + month2);
System.out.println("The third month is: " + month3);
System.out.println("The fourth month is: " + month4);
System.out.println("The fifth month is: " + month5);
System.out.println("The sixth month is: " + month6);
System.out.println("The seventh month is: " + month7);
System.out.println("The eighth month is: " + month8);
System.out.println("The ninth month is: " + month9);
System.out.println("The tenth month is: " + month10);
System.out.println("The eleventh month is: " + month11);
System.out.println("The twelfth month is: " + month12);
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/gdn/onboarding/onboardingjava/Factorial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.gdn.onboarding.onboardingjava;

public class Factorial {
private int calculateFactorial(int number) {
if (number == 1) {
return 1;
}
else {
int result = 1;
for (int i = 2; i <= number; i++) {
result *= i;
}
return result;
}
}

public static void main(String[] args) {
Factorial factorial = new Factorial();
int factorial1 = factorial.calculateFactorial(1);
int factorial2 = factorial.calculateFactorial(2);
int factorial3 = factorial.calculateFactorial(3);
int factorial4 = factorial.calculateFactorial(4);
int factorial5 = factorial.calculateFactorial(5);
int factorial6 = factorial.calculateFactorial(6);

System.out.println("Factorial of 1 : " + factorial1);
System.out.println("Factorial of 2 : " + factorial2);
System.out.println("Factorial of 3 : " + factorial3);
System.out.println("Factorial of 4 : " + factorial4);
System.out.println("Factorial of 5 : " + factorial5);
System.out.println("Factorial of 6 : " + factorial6);
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/gdn/onboarding/onboardingjava/LetterGrade.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.gdn.onboarding.onboardingjava;

public class LetterGrade {
public String getGrade(int point) {
if (point > 80) {
return "A";
} else if (point > 74) {
return "AB";
} else if (point > 69) {
return "B";
} else if (point > 64) {
return "BC";
} else if (point > 59) {
return "C";
} else {
return "D";
}
}

public static void main(String[] args) {
LetterGrade grader = new LetterGrade();
String grade1 = grader.getGrade(90);
String grade2 = grader.getGrade(78);
String grade3 = grader.getGrade(72);
String grade4 = grader.getGrade(68);
String grade5 = grader.getGrade(62);
String grade6 = grader.getGrade(58);

System.out.println("Nilai Mata Kuliah 1 : " + grade1);
System.out.println("Nilai Mata Kuliah 2 : " + grade2);
System.out.println("Nilai Mata Kuliah 3 : " + grade3);
System.out.println("Nilai Mata Kuliah 4 : " + grade4);
System.out.println("Nilai Mata Kuliah 5 : " + grade5);
System.out.println("Nilai Mata Kuliah 6 : " + grade6);
}
}