-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
607 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package me.alex4386.gachon.sw14462.day08; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
|
||
public class Main { | ||
public static String chainloadTarget = "ex4_7"; | ||
|
||
public static void main(String[] args) { | ||
String packageName = Main.class.getPackage().getName(); | ||
String chainLoadTargetClass = packageName + "." + chainloadTarget + ".Main"; | ||
|
||
try { | ||
Class<?> klass = Class.forName(chainLoadTargetClass); | ||
klass.getMethod("main", String[].class).invoke(null, (Object) args); | ||
} catch (ClassNotFoundException e) { | ||
System.err.println("Failed to find the chainload target class."); | ||
e.printStackTrace(); | ||
} catch (InvocationTargetException e) { | ||
throw new RuntimeException(e); | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} catch (NoSuchMethodException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/me/alex4386/gachon/sw14462/day08/ex4_1/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package me.alex4386.gachon.sw14462.day08.ex4_1; | ||
|
||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or | ||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter. | ||
public class Main { | ||
public static void main(String[] args) { | ||
MotorBoatTest.main(args); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/me/alex4386/gachon/sw14462/day08/ex4_1/MotorBoat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package me.alex4386.gachon.sw14462.day08.ex4_1; | ||
|
||
public class MotorBoat { | ||
public double tankCapacity; | ||
public double fuelInTank; | ||
public double maximumSpeed; | ||
public double currentSpeed = 0; | ||
public double fuelEfficiency; | ||
|
||
public void printFuelUsage(double t) { | ||
System.out.println("Maximum speed fuel usage: "+this.getFuelUsage(t, this.maximumSpeed)); | ||
System.out.println("Current speed fuel usage: "+this.getFuelUsage(t)); | ||
} | ||
|
||
public double getFuelUsage(double time) { | ||
return this.getFuelUsage(time, this.currentSpeed); | ||
} | ||
|
||
public double getFuelUsage(double time, double speed) { | ||
return this.fuelEfficiency * Math.pow(speed, 2) * time; | ||
} | ||
|
||
public double getTravelledDistance(double time) { | ||
return this.currentSpeed * time; | ||
} | ||
|
||
public double getAvailableDistance() { | ||
return this.fuelInTank / (this.fuelEfficiency * this.currentSpeed); | ||
} | ||
|
||
|
||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/me/alex4386/gachon/sw14462/day08/ex4_1/MotorBoatTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package me.alex4386.gachon.sw14462.day08.ex4_1; | ||
|
||
public class MotorBoatTest { | ||
public static void main(String[] args) { | ||
MotorBoat boat = new MotorBoat(); | ||
|
||
// provision boat instance - since I can not use constructor "yet" | ||
boat.tankCapacity = 100; | ||
boat.fuelInTank = 50; | ||
boat.maximumSpeed = 100; | ||
boat.currentSpeed = 50; | ||
boat.fuelEfficiency = 0.1; | ||
|
||
// test section | ||
boat.printFuelUsage(10); | ||
System.out.println("Travelled distance: "+boat.getTravelledDistance(10)); | ||
System.out.println("Available distance: "+boat.getAvailableDistance()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/alex4386/gachon/sw14462/day08/ex4_2a/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package me.alex4386.gachon.sw14462.day08.ex4_2a; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
MotorBoatTest.main(args); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/me/alex4386/gachon/sw14462/day08/ex4_2a/MotorBoat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package me.alex4386.gachon.sw14462.day08.ex4_2a; | ||
|
||
public class MotorBoat { | ||
public static final double tankCapacity = 60.0; | ||
private double fuelInTank; | ||
private double maximumSpeed; | ||
private double currentSpeed = 0; | ||
private double fuelEfficiency; | ||
|
||
// === GETTER & SETTER === | ||
public double getFuelInTank() { | ||
return this.fuelInTank; | ||
} | ||
|
||
public void setFuelInTank(double fuelInTank) { | ||
if (fuelInTank > tankCapacity) { | ||
throw new IllegalArgumentException("Fuel in tank cannot exceed tank capacity"); | ||
} | ||
|
||
this.fuelInTank = fuelInTank; | ||
} | ||
|
||
public double getMaximumSpeed() { | ||
return this.maximumSpeed; | ||
} | ||
|
||
public void setMaximumSpeed(double maximumSpeed) { | ||
this.maximumSpeed = maximumSpeed; | ||
} | ||
|
||
public double getCurrentSpeed() { | ||
return this.currentSpeed; | ||
} | ||
|
||
public void setCurrentSpeed(double currentSpeed) { | ||
this.currentSpeed = currentSpeed; | ||
} | ||
|
||
public double getFuelEfficiency() { | ||
return this.fuelEfficiency; | ||
} | ||
|
||
public void setFuelEfficiency(double fuelEfficiency) { | ||
this.fuelEfficiency = fuelEfficiency; | ||
} | ||
|
||
|
||
|
||
public void printFuelUsage(double t) { | ||
System.out.println("Maximum speed fuel usage: "+this.getFuelUsage(t, this.maximumSpeed)); | ||
System.out.println("Current speed fuel usage: "+this.getFuelUsage(t)); | ||
} | ||
|
||
public double getFuelUsage(double time) { | ||
return this.getFuelUsage(time, this.currentSpeed); | ||
} | ||
|
||
public double getFuelUsage(double time, double speed) { | ||
return this.fuelEfficiency * Math.pow(speed, 2) * time; | ||
} | ||
|
||
public double getTravelledDistance(double time) { | ||
return this.currentSpeed * time; | ||
} | ||
|
||
public double getAvailableDistance() { | ||
return this.fuelInTank / (this.fuelEfficiency * this.currentSpeed); | ||
} | ||
|
||
|
||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/me/alex4386/gachon/sw14462/day08/ex4_2a/MotorBoatTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package me.alex4386.gachon.sw14462.day08.ex4_2a; | ||
|
||
public class MotorBoatTest { | ||
public static void main(String[] args) { | ||
MotorBoat boat = new MotorBoat(); | ||
boat.setFuelInTank(50); | ||
boat.setCurrentSpeed(50); | ||
boat.setFuelEfficiency(0.1); | ||
|
||
boat.printFuelUsage(5); | ||
System.out.println("Maximum speed fuel usage: "+boat.getFuelUsage(10, boat.getMaximumSpeed())); | ||
System.out.println("Current speed fuel usage: "+boat.getFuelUsage(10)); | ||
System.out.println("Travelled distance: "+boat.getTravelledDistance(10)); | ||
System.out.println("Available distance: "+boat.getAvailableDistance()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/me/alex4386/gachon/sw14462/day08/ex4_2b/Counter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package me.alex4386.gachon.sw14462.day08.ex4_2b; | ||
|
||
public class Counter { | ||
private int count = 0; | ||
|
||
public void resetCounter() { | ||
this.count = 0; | ||
} | ||
|
||
public void increase() { | ||
count++; | ||
} | ||
|
||
public void decrease() { | ||
if (count <= 0) { | ||
throw new RuntimeException("Count cannot be negative"); | ||
} | ||
count--; | ||
} | ||
|
||
public int getCount() { | ||
return count; | ||
} | ||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/me/alex4386/gachon/sw14462/day08/ex4_2b/CounterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package me.alex4386.gachon.sw14462.day08.ex4_2b; | ||
|
||
public class CounterTest { | ||
public static void main(String[] args) { | ||
Counter counter = new Counter(); | ||
|
||
System.out.println("Increasing twice"); | ||
counter.increase(); | ||
counter.increase(); | ||
|
||
assert counter.getCount() == 2; | ||
|
||
System.out.println("Decreasing once"); | ||
counter.decrease(); | ||
|
||
assert counter.getCount() == 1; | ||
|
||
System.out.println("Resetting counter"); | ||
counter.resetCounter(); | ||
|
||
assert counter.getCount() == 0; | ||
|
||
System.out.println("Test complete."); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/alex4386/gachon/sw14462/day08/ex4_2b/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package me.alex4386.gachon.sw14462.day08.ex4_2b; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
CounterTest.main(args); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/me/alex4386/gachon/sw14462/day08/ex4_3/GradeDistribution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package me.alex4386.gachon.sw14462.day08.ex4_3; | ||
|
||
public class GradeDistribution { | ||
final char grades[] = {'A', 'B', 'C', 'D', 'F'}; | ||
int[] gradeNums = new int[5]; | ||
|
||
public void setGradeNums(char letter, int num) { | ||
switch (letter) { | ||
case 'A': | ||
gradeNums[0] = num; | ||
break; | ||
case 'B': | ||
gradeNums[1] = num; | ||
break; | ||
case 'C': | ||
gradeNums[2] = num; | ||
break; | ||
case 'D': | ||
gradeNums[3] = num; | ||
break; | ||
case 'F': | ||
gradeNums[4] = num; | ||
break; | ||
} | ||
} | ||
|
||
public int getGradeNums(char letter) { | ||
switch (letter) { | ||
case 'A': | ||
return gradeNums[0]; | ||
case 'B': | ||
return gradeNums[1]; | ||
case 'C': | ||
return gradeNums[2]; | ||
case 'D': | ||
return gradeNums[3]; | ||
case 'F': | ||
return gradeNums[4]; | ||
default: | ||
return 0; | ||
} | ||
} | ||
|
||
public int totalGradeNums() { | ||
int total = 0; | ||
for (int i = 0; i < gradeNums.length; i++) { | ||
total += gradeNums[i]; | ||
} | ||
return total; | ||
} | ||
|
||
public double gradePercentage(char letter) { | ||
return ((double) getGradeNums(letter) / totalGradeNums()) * 100.0; | ||
} | ||
|
||
public void drawBarGraph() { | ||
int columns = 50; | ||
for (int i = 0; i < columns; i++) { | ||
System.out.print("*"); | ||
} | ||
System.out.println(); | ||
|
||
for (int i = 0; i < gradeNums.length; i++) { | ||
double multiplier = (double) columns / 100.0; | ||
int counts = (int) Math.round(this.gradePercentage(grades[i]) * multiplier); | ||
for (int j = 0; j < counts; j++) { | ||
System.out.print("*"); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/me/alex4386/gachon/sw14462/day08/ex4_3/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package me.alex4386.gachon.sw14462.day08.ex4_3; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
GradeDistribution gradeDistribution = new GradeDistribution(); | ||
|
||
gradeDistribution.setGradeNums('A', 1); | ||
gradeDistribution.setGradeNums('B', 4); | ||
gradeDistribution.setGradeNums('C', 6); | ||
gradeDistribution.setGradeNums('D', 2); | ||
gradeDistribution.setGradeNums('F', 1); | ||
|
||
System.out.println("Grade Distribution"); | ||
System.out.println("A: " + gradeDistribution.getGradeNums('A') + " (" + gradeDistribution.gradePercentage('A') + "%)"); | ||
System.out.println("B: " + gradeDistribution.getGradeNums('B') + " (" + gradeDistribution.gradePercentage('B') + "%)"); | ||
System.out.println("C: " + gradeDistribution.getGradeNums('C') + " (" + gradeDistribution.gradePercentage('C') + "%)"); | ||
System.out.println("D: " + gradeDistribution.getGradeNums('D') + " (" + gradeDistribution.gradePercentage('D') + "%)"); | ||
System.out.println("F: " + gradeDistribution.getGradeNums('F') + " (" + gradeDistribution.gradePercentage('F') + "%)"); | ||
|
||
gradeDistribution.drawBarGraph(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/me/alex4386/gachon/sw14462/day08/ex4_4/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package me.alex4386.gachon.sw14462.day08.ex4_4; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
PurchaseDemo.main(args); | ||
} | ||
} |
Oops, something went wrong.