Skip to content

Commit

Permalink
chore: homework
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4386 committed Apr 18, 2024
1 parent b3ad2fe commit b353eb8
Show file tree
Hide file tree
Showing 28 changed files with 971 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/me/alex4386/gachon/sw14462/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.*;

public class Main {
public static String currentTarget = "day11";
public static String currentTarget = "day14";
public static boolean fallbackToLatest = true;

public static Map<String, Class<?>> getAvailableTargetClassNames() {
Expand Down
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);
}
}
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");
}
}
}
18 changes: 18 additions & 0 deletions src/main/java/me/alex4386/gachon/sw14462/day13/Main.java
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;
}
}
}
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.");
}
}
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);
}
}
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);
}
}
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;
}
}
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();
}
}
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
}
}
}
}
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]);
}
}
}
}
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);
}
}
18 changes: 18 additions & 0 deletions src/main/java/me/alex4386/gachon/sw14462/day14/Main.java
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;
}
}
}
Loading

0 comments on commit b353eb8

Please sign in to comment.