Skip to content

Commit 7abbaa3

Browse files
authored
Merge pull request #2 from ozzioma/master
LBT Academy Java Project
2 parents 62e12c2 + a149caa commit 7abbaa3

30 files changed

Lines changed: 517 additions & 18 deletions

hello/src/Arguments.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class Arguments {
2+
3+
public static void main(String[] args)
4+
{
5+
calculateDeductions("Mr. Ajayi",
6+
1000, 2000, 3000, 4000);
7+
}
8+
9+
//varargs..variable arguments
10+
public static double calculateDeductions(String staffName,
11+
double... deductions)
12+
{
13+
//initialization
14+
double total = 0;
15+
//double total;
16+
17+
for (double deduction : deductions)
18+
{
19+
total += deduction;
20+
//total=total+deduction;
21+
}
22+
System.out.println("total deductions for " +
23+
staffName + " is->" + total);
24+
return total;
25+
}
26+
27+
28+
29+
}

hello/src/ArmySalaryLevel.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ public class ArmySalaryLevel extends SalaryLevel {
22

33
private double deductions;
44
private double overTime;
5+
public static final double DEDUCTION_LIMIT =5000;
6+
7+
public ArmySalaryLevel()
8+
{
9+
super(1000,"123");
10+
//setOverTime(123);
11+
this.getSalary();
12+
}
513

614
public double getDeductions() {
715
return deductions;
@@ -37,13 +45,44 @@ public double calculateSalary(double multiplier) {
3745
//polymorphism not inheritance
3846
public double calculateSalary(double totalDeductions,
3947
double totalOvertime)
48+
throws InvalidDeductionException
49+
{
50+
//first of all, do parameter validation
51+
52+
if(totalDeductions > DEDUCTION_LIMIT)
53+
{
54+
throw new InvalidDeductionException(
55+
"Deduction limit exceeded"
56+
,totalDeductions);
57+
}
58+
59+
this.setOverTime(totalOvertime);
60+
setDeductions(totalDeductions);
61+
62+
double baseSalary=getSalary()*3;
63+
64+
double divider=baseSalary/43545.6565;
65+
double netSalary=(baseSalary+totalOvertime)-totalDeductions;
66+
return netSalary/divider;
67+
}
68+
69+
public double calculateSalary2(double totalDeductions,
70+
double totalOvertime)
4071
{
72+
if(totalDeductions > DEDUCTION_LIMIT)
73+
{
74+
throw new InvalidDeductionRuntimeException(
75+
"Deduction limit exceeded"
76+
,totalDeductions);
77+
}
78+
4179
this.setOverTime(totalOvertime);
4280
setDeductions(totalDeductions);
4381

4482
double baseSalary=getSalary()*3;
4583

84+
double divider=baseSalary/43545.6565;
4685
double netSalary=(baseSalary+totalOvertime)-totalDeductions;
47-
return netSalary;
86+
return netSalary/divider;
4887
}
4988
}

hello/src/BaseTaxBracket.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public abstract class BaseTaxBracket
2+
{
3+
private String region;
4+
5+
public double calculateStampTax(double amount)
6+
{
7+
return amount*0.05;
8+
}
9+
10+
public abstract double calculateVAT();
11+
12+
}

hello/src/Casting.java

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
public class Casting
2+
{
3+
public static void main(String[] args)
4+
{
5+
NNPCSalaryLevel nnpcSalaryLevel=new NNPCSalaryLevel();
6+
nnpcSalaryLevel.setSalary(1000);
7+
nnpcSalaryLevel.setBonus(200);
8+
nnpcSalaryLevel.setGrade("Level 15");
9+
10+
ArmySalaryLevel armySalaryLevel=new ArmySalaryLevel();
11+
armySalaryLevel.setSalary(4000);
12+
armySalaryLevel.setDeductions(500);
13+
armySalaryLevel.setOverTime(300);
14+
armySalaryLevel.setGrade("Level 16");
15+
16+
SalaryLevel salaryLevel=new SalaryLevel(3000,"345");
17+
salaryLevel.setSalary(6000);
18+
salaryLevel.setGrade("Level 12");
19+
20+
processSalary(nnpcSalaryLevel);
21+
processSalary(armySalaryLevel);
22+
processSalary(salaryLevel);
23+
24+
processSalary2(nnpcSalaryLevel);
25+
processSalary2(armySalaryLevel);
26+
processSalary2(salaryLevel);
27+
28+
//processArmySalary(salaryLevel);
29+
//processArmySalary(nnpcSalaryLevel);
30+
31+
//TaxBracket taxBracket=new TaxBracket();
32+
//processSalary(taxBracket);
33+
}
34+
35+
public static void processSalary(SalaryLevel level)
36+
{
37+
double netSalary=0;
38+
if(level instanceof ArmySalaryLevel)
39+
{
40+
System.out.println("Level is Army salary level");
41+
42+
ArmySalaryLevel armySalaryLevel=(ArmySalaryLevel) level;
43+
System.out.println("Army salary grade overtime is->"+armySalaryLevel.getOverTime());
44+
}
45+
else if(level instanceof NNPCSalaryLevel)
46+
{
47+
48+
System.out.println("Level is NNPC salary level");
49+
50+
}
51+
else
52+
{
53+
System.out.println("Level is default salary level");
54+
}
55+
56+
57+
}
58+
59+
public static void processSalary2(SalaryLevelInterface level)
60+
{
61+
double netSalary=0;
62+
63+
//SalaryLevelInterface levelInterface=new SalaryLevelInterface();
64+
65+
ArmySalaryLevel army=new ArmySalaryLevel();
66+
SalaryLevel army2=new ArmySalaryLevel();
67+
SalaryLevelInterface army3=new ArmySalaryLevel();
68+
69+
System.out.println("Calculated salary is->"+level.calculateSalary());
70+
71+
if(level instanceof ArmySalaryLevel)
72+
{
73+
System.out.println("Level is Army salary level");
74+
75+
ArmySalaryLevel armySalaryLevel=(ArmySalaryLevel) level;
76+
System.out.println("Army salary grade overtime is->"+armySalaryLevel.getOverTime());
77+
}
78+
else if(level instanceof NNPCSalaryLevel)
79+
{
80+
81+
System.out.println("Level is NNPC salary level");
82+
83+
}
84+
else
85+
{
86+
System.out.println("Level is default salary level");
87+
}
88+
}
89+
90+
public static void processArmySalary(ArmySalaryLevel level)
91+
{
92+
93+
}
94+
95+
}

hello/src/CollectionDemos.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.*;
2+
3+
public class CollectionDemos {
4+
5+
6+
public void example1()
7+
{
8+
List list=new ArrayList<>();
9+
Integer num1=123;//Integer.valueOf("123");// new Integer(123);
10+
list.add(123);
11+
}
12+
13+
public void setsExample()
14+
{
15+
Set<String> set=new TreeSet<>();
16+
set.add("Chief Ozzy De Great, 1st");
17+
set.add("Maj. Gen Buhari");
18+
set.add("WBT Ajayi");
19+
20+
Set<Integer> numbas=new TreeSet<>();
21+
numbas.add(123);
22+
numbas.add(234);
23+
}
24+
25+
}
26+
27+

hello/src/Generics.java

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import java.util.ArrayList;
2+
import java.util.List;
3+
4+
public class Generics {
5+
6+
7+
}
8+
9+
10+
class Student {
11+
12+
13+
}
14+
15+
class JuniorStudent extends Student {
16+
17+
}
18+
19+
class SeniorStudent extends Student {
20+
21+
}
22+
23+
class ExamProcessorOld {
24+
public void processJuniorResults(JuniorStudent[] students) {
25+
26+
}
27+
28+
public void processSeniorResults(SeniorStudent[] students) {
29+
30+
}
31+
32+
public void processStudentResults(Object[] students) {
33+
34+
}
35+
36+
37+
}
38+
39+
interface ExamProcessor<Y>
40+
{
41+
void processResult(Y student);
42+
void processResult(Y student,double height, String fullname);
43+
void processResults(Y[] students);
44+
void processResults2(List<Y> students);
45+
46+
//JuniorStudent getJuniorStudent(int index);
47+
//SeniorStudent getSeniorStudent(int index);
48+
49+
Y getStudent(int index);
50+
}
51+
52+
interface ExamProcessorInterface
53+
{
54+
void processResult(JuniorStudent student);
55+
void processResult(SeniorStudent student);
56+
void processResults(JuniorStudent[] students);
57+
void processResults(SeniorStudent[] students);
58+
void processResults2(List<JuniorStudent> students);
59+
void processResults3(List<SeniorStudent> student);
60+
}
61+
62+
class ExamProcessor2<T> implements ExamProcessor<T>
63+
{
64+
List<T> list = new ArrayList<T>();
65+
66+
public void processResult(T student) {
67+
list.add(student);
68+
}
69+
70+
public void processResult(T student,double height, String fullname)
71+
{
72+
73+
}
74+
75+
public void processResults(T[] students) {
76+
for (T item : students) {
77+
list.add(item);
78+
}
79+
}
80+
81+
public void processResults2(List<T> students) {
82+
list.addAll(students);
83+
}
84+
85+
public T getStudent(int index)
86+
{
87+
return null;
88+
}
89+
}
90+
91+
92+
class StudentsList {
93+
94+
ExamProcessor2<JuniorStudent> juniorStudentExamProcessor = new ExamProcessor2<>();
95+
ExamProcessor2<SeniorStudent> seniorStudentExamProcessor2 = new ExamProcessor2<SeniorStudent>();
96+
97+
private JuniorStudent[] list = new JuniorStudent[100];
98+
99+
private List list2 = new ArrayList();
100+
101+
private List<JuniorStudent> juniorStudents = new ArrayList<JuniorStudent>();
102+
private ArrayList<SeniorStudent> seniorStudents = new ArrayList<SeniorStudent>();
103+
104+
public void addStudent(int index, JuniorStudent student) {
105+
list[index] = student;
106+
}
107+
108+
public JuniorStudent getStudent(int index) {
109+
return list[index];
110+
}
111+
112+
public void addJuniorStudent(JuniorStudent student) {
113+
list2.add(student);
114+
}
115+
116+
public void addJuniorStudent(int index,JuniorStudent student) {
117+
juniorStudents.add(index,student);
118+
}
119+
public void addJuniorStudent2(JuniorStudent student) {
120+
juniorStudents.add(student);
121+
122+
//SeniorStudent seniorStudent=new SeniorStudent();
123+
//juniorStudents.add(seniorStudent);
124+
}
125+
126+
public void addSeniorStudent(SeniorStudent student) {
127+
list2.add(student);
128+
}
129+
130+
//5
131+
public JuniorStudent getJuniorStudent(int index) {
132+
JuniorStudent student = (JuniorStudent) list2.get(index);
133+
return student;
134+
//return list2.get(index);
135+
}
136+
137+
//type safety
138+
public JuniorStudent getJuniorStudent2(int index) {
139+
JuniorStudent student = juniorStudents.get(index);
140+
return student;
141+
//return list2.get(index);
142+
143+
}
144+
145+
public SeniorStudent getSeniorStudent(int index) {
146+
SeniorStudent student = (SeniorStudent) list2.get(index);
147+
148+
return student;
149+
//return list2.get(index);
150+
}
151+
152+
public void processJuniorResults(List<JuniorStudent> students) {
153+
juniorStudentExamProcessor.processResults2(students);
154+
155+
}
156+
157+
}

0 commit comments

Comments
 (0)