출처 : 네이버 지식인
package Education;
import java.util.Scanner;
class Student { public static void main(String[] args)
{
Yeon[] s = new Yeon[10];
int st_num;
String name, flag;
int attend, assignment, quiz, mid, last;
double total, j_total=0;
char hakjum = ' ';
int MAX_student = 10;
int count = 0;
double total_max=0, total_min=0, ave;
Scanner scan = new Scanner(System.in);
do {
System.out.print("성적을 줄 학생이 있으면 y로 없으면 n을 입력하세요. ");
flag = scan.next();
if(flag.equals("n"))
break;
System.out.print("학생의 번호를 입력하세요 : \t");
st_num = scan.nextInt();
System.out.print("학생의 이름을 입력하세요 : \t");
name = scan.next();
System.out.print("출석 점수를 입력하세요 : \t");
attend = scan.nextInt();
System.out.print("과제 점수를 입력하세요 : \t");
assignment = scan.nextInt();
System.out.print("퀴즈 점수를 입력하세요 : \t");
quiz = scan.nextInt();
System.out.print("중간시험 점수를 입력하세요 : \t");
mid = scan.nextInt();
System.out.print("기말시험 점수를 입력하세요 : \t");
last = scan.nextInt();
Yeon sj = new Yeon(st_num, name, attend, assignment, quiz, mid, last);
s[count] = sj;
total = (attend*0.1 + assignment*0.4 + quiz*0.1 + mid*0.2 + last*0.2);
j_total += s[count].getTotal();
System.out.println("총점 : " + s[count].getTotal());
System.out.println("학점 : " + s[count].getHakjum(s[count].getTotal()));
count++;
} while (count <= MAX_student);
System.out.println("성적 평가표");
for(int i=0; i<count; i++)
{
System.out.print(s[i].getNum() + "\t");
System.out.print(s[i].getName() + "\t");
System.out.print(s[i].getTotal() + "\t");
System.out.println(s[i].getHakjum(i) + "\t");
}
ave = j_total/count;
total_max = s[0].getTotal();
for(int i=0; i<count-1; i++)
{
if( s[i].getTotal() < s[i+1].getTotal() )
total_max = s[i+1].getTotal();
else
total_max = s[i].getTotal();
}
total_min = s[0].getTotal();
for(int i=0; i<count-1; i++)
{
if(s[i].getTotal() < s[i+1].getTotal())
total_min = s[i].getTotal();
else
total_min = s[i+1].getTotal();
}
System.out.println("평균 점수 : \t" + ave);
System.out.println("최고 점수 : \t" + total_max);
System.out.println("최저 점수 : \t" + total_min);
} // main
}
class Yeon
{
int st_num;
String name, flag;
int attend, assignment, quiz, mid, last;
double total, j_total;
char hakjum = ' ';
int MAX_student = 10;
int count = 0;
double total_max, total_min, ave;
public Yeon(int st_num, String name, int attend, int assignment, int quiz, int mid, int last)
{
this.st_num = st_num;
this.name = name;
this.attend = attend;
this.assignment = assignment;
this.quiz = quiz;
this.mid = mid;
this.last = last;
}
public int getNum()
{
return st_num;
}
public String getName()
{
return name;
}
public int getAttend()
{
return attend;
}
public int getAssignment()
{
return assignment;
}
public int getQuiz()
{
return quiz;
}
public int getMid()
{
return mid;
}
public int getFinal()
{
return last;
}
public double getTotal()
{
total = (attend*0.1 + assignment*0.4 + quiz*0.1 + mid*0.2 + last*0.2);
return total;
}
public char getHakjum(double total)
{
if (total >= 90)
hakjum = 'A';
else if(total >= 80)
hakjum = 'B';
else if(total >= 70)
hakjum = 'C';
else if(total >= 60)
hakjum = 'D';
else if(total <= 59)
hakjum = 'F';
return hakjum;
}
}
ChatGPT, 블록체인, 자바, 맥북, 인터넷, 컴퓨터 정보를 공유합니다.
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!