-
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
28 changed files
with
971 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
58 changes: 58 additions & 0 deletions
58
src/main/java/me/alex4386/gachon/sw14462/day11/quiz/PersonAddress.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,58 @@ | ||
package me.alex4386.gachon.sw14462.day11.quiz; | ||
|
||
public class PersonAddress { | ||
|
||
public static String nationality = "Korea"; | ||
|
||
private String firstName; | ||
private String lastName; | ||
private String emailAddress; | ||
|
||
|
||
private String phoneNumber; | ||
|
||
public String getFirstName() { | ||
return this.firstName; | ||
} | ||
|
||
public String getLastName() { | ||
return this.lastName; | ||
} | ||
|
||
public String getEmailAddress() { | ||
return this.emailAddress; | ||
} | ||
|
||
public String getPhoneNumber() { | ||
return this.phoneNumber; | ||
} | ||
|
||
public static String getNationality() { | ||
return PersonAddress.nationality; | ||
} | ||
|
||
public void setName(String firstName, String lastName) { | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
} | ||
|
||
public void setEmailAddress(String emailAddress) { | ||
this.emailAddress = emailAddress; | ||
} | ||
|
||
public void setPhoneNumber(String phoneNumber) { | ||
this.phoneNumber = phoneNumber; | ||
} | ||
|
||
public void printPersonInfo() { | ||
System.out.println("First Name: " + this.firstName); | ||
System.out.println("Last Name: " + this.lastName); | ||
System.out.println("Email Address: " + this.emailAddress); | ||
System.out.println("Phone Number: " + this.phoneNumber); | ||
System.out.println("Nationality: " + PersonAddress.nationality); | ||
} | ||
|
||
public boolean equals(PersonAddress other) { | ||
return this.firstName.equals(other.firstName) && this.lastName.equals(other.lastName); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/me/alex4386/gachon/sw14462/day11/quiz/PersonAddressTest.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.day11.quiz; | ||
|
||
public class PersonAddressTest { | ||
public static void main(String[] args) { | ||
PersonAddress addr1 = new PersonAddress(); | ||
PersonAddress addr2 = new PersonAddress(); | ||
|
||
addr1.setName("Alex", "Lee"); | ||
addr1.setEmailAddress("[email protected]"); | ||
addr1.setPhoneNumber("010-1234-5678"); | ||
|
||
addr2.setName("Alex", "Lee"); | ||
addr2.setEmailAddress("[email protected]"); | ||
addr2.setPhoneNumber("010-5678-1234"); | ||
|
||
addr1.printPersonInfo(); | ||
addr2.printPersonInfo(); | ||
|
||
if (addr1.equals(addr2)) { | ||
System.out.println("Same person"); | ||
} else { | ||
System.out.println("Different person"); | ||
} | ||
} | ||
} |
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,18 @@ | ||
package me.alex4386.gachon.sw14462.day13; | ||
|
||
import me.alex4386.gachon.sw14462.utils.Chainloader; | ||
|
||
public class Main { | ||
public static String chainloadTarget = "ex7_1b"; | ||
|
||
public static void main(String[] args) throws Throwable { | ||
String packageName = Main.class.getPackage().getName(); | ||
String chainLoadTargetClass = packageName + "." + chainloadTarget + ".Main"; | ||
|
||
try { | ||
Chainloader.chainloadTarget(chainLoadTargetClass, args); | ||
} catch (Exception e) { | ||
throw e; | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/me/alex4386/gachon/sw14462/day13/ex7_1/ArrayOfTemperatures2.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,43 @@ | ||
package me.alex4386.gachon.sw14462.day13.ex7_1; | ||
|
||
import java.util.Scanner; | ||
|
||
/** | ||
Reads temperatures from the user and shows which are above | ||
and which are below the average of all the temperatures. | ||
*/ | ||
public class ArrayOfTemperatures2 | ||
{ | ||
public static void main(String[] args) { | ||
Scanner keyboard = new Scanner(System.in); | ||
System.out.println("How many temperatures do you have?"); | ||
int size = keyboard.nextInt(); | ||
double[] temperature = new double[size]; | ||
// Read temperatures and compute their average: | ||
System.out.println("Enter " + temperature.length + | ||
" temperatures:"); | ||
double sum = 0; | ||
for (int index = 0; index < temperature.length; index++) { | ||
temperature[index] = keyboard.nextDouble(); | ||
sum = sum + temperature[index]; | ||
} | ||
double average = sum / temperature.length; | ||
System.out.println("The average temperature is " + | ||
average); | ||
// Display each temperature and its relation to the | ||
// average: | ||
System.out.println("The temperatures are"); | ||
for (int index = 0; index < temperature.length; index++) { | ||
if (temperature[index] < average) | ||
System.out.println(temperature[index] + | ||
" below average"); | ||
else if (temperature[index] > average) | ||
System.out.println(temperature[index] + | ||
" above average"); | ||
else //temperature[index] == average | ||
System.out.println(temperature[index] + | ||
" the average"); | ||
} | ||
System.out.println("Have a nice week."); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/alex4386/gachon/sw14462/day13/ex7_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,7 @@ | ||
package me.alex4386.gachon.sw14462.day13.ex7_1; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
ArrayOfTemperatures2.main(args); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/alex4386/gachon/sw14462/day13/ex7_1a/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.day13.ex7_1a; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
ScoreReaderTest.main(args); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/me/alex4386/gachon/sw14462/day13/ex7_1a/ScoreReader.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,51 @@ | ||
package me.alex4386.gachon.sw14462.day13.ex7_1a; | ||
|
||
public class ScoreReader { | ||
private int[] scores; | ||
private int currentIdx; | ||
|
||
public ScoreReader(int size) { | ||
this.scores = new int[size]; | ||
this.currentIdx = 0; | ||
} | ||
|
||
public void addScore(int score) { | ||
if (this.currentIdx >= this.scores.length) { | ||
System.out.println("Scores are full"); | ||
return; | ||
} | ||
|
||
this.scores[this.currentIdx] = score; | ||
this.currentIdx++; | ||
} | ||
|
||
public double getAverage() { | ||
double sum = 0; | ||
for (int i = 0; i < this.currentIdx; i++) { | ||
sum += this.scores[i]; | ||
} | ||
|
||
return sum / this.currentIdx; | ||
} | ||
|
||
public int[] getScoresAboveAverage() { | ||
double average = this.getAverage(); | ||
|
||
int size = 0; | ||
for (int i = 0; i < this.currentIdx; i++) { | ||
if (this.scores[i] > average) { | ||
size++; | ||
} | ||
} | ||
|
||
int[] data = new int[size]; | ||
for (int i = 0, j = 0; i < this.currentIdx; i++) { | ||
if (this.scores[i] > average) { | ||
data[j] = this.scores[i]; | ||
j++; | ||
} | ||
} | ||
|
||
return data; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/me/alex4386/gachon/sw14462/day13/ex7_1a/ScoreReaderTest.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,32 @@ | ||
package me.alex4386.gachon.sw14462.day13.ex7_1a; | ||
|
||
import java.util.Scanner; | ||
|
||
public class ScoreReaderTest { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
|
||
System.out.print("Enter the number of students: "); | ||
int studentCount = scanner.nextInt(); | ||
|
||
if (studentCount <= 0) { | ||
System.out.println("Invalid number of students"); | ||
return; | ||
} | ||
|
||
ScoreReader scoreReader = new ScoreReader(studentCount); | ||
for (int i = 0; i < studentCount; i++) { | ||
System.out.print("Enter the score of student " + (i + 1) + ": "); | ||
int score = scanner.nextInt(); | ||
scoreReader.addScore(score); | ||
} | ||
|
||
System.out.println("Average score: " + scoreReader.getAverage()); | ||
int[] scoresAboveAverage = scoreReader.getScoresAboveAverage(); | ||
System.out.print("Scores above average: "); | ||
for (int i = 0; i < scoresAboveAverage.length; i++) { | ||
System.out.print(scoresAboveAverage[i] + " "); | ||
} | ||
System.out.println(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/me/alex4386/gachon/sw14462/day13/ex7_1b/FrequencyAnalyzer.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,45 @@ | ||
package me.alex4386.gachon.sw14462.day13.ex7_1b; | ||
|
||
public class FrequencyAnalyzer { | ||
private String input; | ||
private int[] frequency; | ||
|
||
public FrequencyAnalyzer(String input) { | ||
this.input = input; | ||
this.frequency = new int[10]; | ||
|
||
this.analyze(); | ||
} | ||
|
||
public void setInput(String input) { | ||
this.reset(); | ||
this.input = input; | ||
this.analyze(); | ||
} | ||
|
||
private void reset() { | ||
// reuse the array, but initialize to 0 | ||
for (int i = 0; i < this.frequency.length; i++) { | ||
this.frequency[i] = 0; | ||
} | ||
} | ||
|
||
public int[] getFrequency() { | ||
return this.frequency; | ||
} | ||
|
||
private void analyze() { | ||
// split to each character | ||
String[] characters = this.input.split(""); | ||
|
||
// count frequency | ||
for (String character : characters) { | ||
try { | ||
int number = Integer.parseInt(character); | ||
this.frequency[number]++; | ||
} catch (NumberFormatException e) { | ||
// ignore | ||
} | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/me/alex4386/gachon/sw14462/day13/ex7_1b/FrequencyAnalyzerTest.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,28 @@ | ||
package me.alex4386.gachon.sw14462.day13.ex7_1b; | ||
|
||
import java.util.Scanner; | ||
|
||
public class FrequencyAnalyzerTest { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
FrequencyAnalyzer analyzer = null; | ||
|
||
while (true) { | ||
System.out.print("Enter your phone number: "); | ||
String phoneNumber = scanner.nextLine(); | ||
|
||
if (phoneNumber.equals("exit")) { | ||
break; | ||
} | ||
|
||
analyzer = analyzer == null ? new FrequencyAnalyzer(phoneNumber) : analyzer; | ||
analyzer.setInput(phoneNumber); | ||
|
||
System.out.println("Frequency of each digit:"); | ||
int[] frequency = analyzer.getFrequency(); | ||
for (int i = 0; i < frequency.length; i++) { | ||
System.out.println(i + ": " + frequency[i]); | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/alex4386/gachon/sw14462/day13/ex7_1b/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.day13.ex7_1b; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
FrequencyAnalyzerTest.main(args); | ||
} | ||
} |
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,18 @@ | ||
package me.alex4386.gachon.sw14462.day14; | ||
|
||
import me.alex4386.gachon.sw14462.utils.Chainloader; | ||
|
||
public class Main { | ||
public static String chainloadTarget = "ex7_8"; | ||
|
||
public static void main(String[] args) throws Throwable { | ||
String packageName = Main.class.getPackage().getName(); | ||
String chainLoadTargetClass = packageName + "." + chainloadTarget + ".Main"; | ||
|
||
try { | ||
Chainloader.chainloadTarget(chainLoadTargetClass, args); | ||
} catch (Exception e) { | ||
throw e; | ||
} | ||
} | ||
} |
Oops, something went wrong.