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

[13기] 서병주 과제 제출합니다. #30

Open
wants to merge 2 commits into
base: main
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
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ dependencies {

test {
useJUnitPlatform()
}
tasks.withType(JavaCompile){
options.encoding = "UTF-8"
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Dec 30 05:45:58 KST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
96 changes: 95 additions & 1 deletion src/main/java/gpacalc/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,101 @@
package gpacalc;
import java.util.ArrayList;
import camp.nextstep.edu.missionutils.Console;


public class Application {
public static void main(String[] args) {
//TODO: 구현
ArrayList<ArrayList<Subject>> general=new ArrayList<>();
general.add(new ArrayList<>());
general.add(new ArrayList<>());
String[] line=new String[2];
String[][] parts=new String[2][];
boolean flag=true;
System.out.println("전공 과목명과 이수학점, 평점을 입력해주세요(예시: 프로그래밍언어론-3-A+,소프트웨어공학-3-B+):");
line[0]=Console.readLine();
parts[0]=line[0].split(",");
System.out.println("교양 과목명과 이수학점, 평점을 입력해주세요(예시: 선형대수학-3-C0,인간관계와자기성장-3-P):");
line[1]=Console.readLine();
parts[1]=line[1].split(",");
for(String part:parts[0]) {
String[] subject = part.split("-");
if (!subject[1].equals("1") && !subject[1].equals("2") && !subject[1].equals("3") && !subject[1].equals("4")) {
flag=false;
throw new IllegalArgumentException();
}
if (subject[0].length() > 10 || subject[0].replaceAll(" ", "").isEmpty()) {
flag=false;
throw new IllegalArgumentException();
}
if (!subject[2].equals("A+") && !subject[2].equals("A0") && !subject[2].equals("B+") && !subject[2].equals("B0") && !subject[2].equals("C+") && !subject[2].equals("C0") && !subject[2].equals("D+") && !subject[2].equals("D0") && !subject[2].equals("F") && !subject[2].equals("P") && !subject[2].equals("NP")) {
flag=false;
throw new IllegalArgumentException();
}
}
for(String part:parts[1]) {
String[] subject = part.split("-");
if (!subject[1].equals("1") && !subject[1].equals("2") && !subject[1].equals("3") && !subject[1].equals("4")) {
flag=false;
throw new IllegalArgumentException();
}
if (subject[0].length() > 10 || subject[0].replaceAll(" ", "").isEmpty()) {
flag=false;
throw new IllegalArgumentException();
}
if (!subject[2].equals("A+") && !subject[2].equals("A0") && !subject[2].equals("B+") && !subject[2].equals("B0") && !subject[2].equals("C+") && !subject[2].equals("C0") && !subject[2].equals("D+") && !subject[2].equals("D0") && !subject[2].equals("F") && !subject[2].equals("P") && !subject[2].equals("NP")) {
flag=false;
throw new IllegalArgumentException();
}
}
if(flag){
for(int i=0;i<2;i++){
for(String part:parts[i]){
String[] subject=part.split("-");
Subject newSubject=new Subject(subject[0],Integer.parseInt(subject[1]),subject[2]);
general.get(i).add(newSubject);
}
}
double weightSum=0;
int count=0;
double sum2=0;
double count2=0;
int scoreSum=0;
System.out.println("<과목 목록>");
for(Subject subject:general.get(0)){
System.out.println("[전공] "+subject.getName()+","+subject.getPoint()+","+subject.getScore());
weightSum+=subject.getScore2()*subject.getPoint();
sum2+=subject.getScore2()*subject.getPoint();
if(!subject.getScore().equals("P")&&!subject.getScore().equals("NP")) {
count += subject.getPoint();
count2 += subject.getPoint();
}
if(!subject.getScore().equals("F")&&!subject.getScore().equals("NP")) {
scoreSum += subject.getPoint();
}
}
for(Subject subject:general.get(1)){
System.out.println("[교양] "+subject.getName()+","+subject.getPoint()+","+subject.getScore());
weightSum+=subject.getScore2()*subject.getPoint();
if(!subject.getScore().equals("P")&&!subject.getScore().equals("NP")) {
count += subject.getPoint();
}
if(!subject.getScore().equals("F")&&!subject.getScore().equals("NP")) {
scoreSum += subject.getPoint();
}
}
double avg=weightSum/count;
double majorAvg=sum2/count2;

System.out.println();
System.out.println("<취득학점>");
System.out.println(scoreSum+"학점");
System.out.println();
System.out.println("<평점평균>");
System.out.printf("%.2f / 4.5\n",avg);
System.out.println();
System.out.println("<전공 평점평균>");
System.out.printf("%.2f / 4.5\n",majorAvg);
}
}
}

53 changes: 53 additions & 0 deletions src/main/java/gpacalc/Subject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package gpacalc;

class Subject {
private String name;
private String score;
private int point;

public Subject(String name, int point, String score) {
this.name = name;
this.score = score;
this.point = point;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getScore() {
return score;
}

public void setScore(String score) {
this.score = score;
}

public int getPoint() {
return point;
}

public void setPoint(int point) {
this.point = point;
}

public double getScore2() {
double s = switch (score) {
case "A+" -> 4.5;
case "A0" -> 4.0;
case "B+" -> 3.5;
case "B0" -> 3.0;
case "C+" -> 2.5;
case "C0" -> 2.0;
case "D+" -> 1.5;
case "D0" -> 1.0;
default -> 0;
};
return s;
}

}