class Student
{
 public int max_score;
 public int max_num;
 public int min_score;
 public int min_num;
 private int self_cnt;
 private static int cnt;
 public int score;
 public int num;
 public double avg=0;
 public double total=0;

 public void Student_data(int num,int score)
 {
  this.num=num;
  this.score=score;
  cnt++;
  self_cnt++;
  Compute(score);
  Compare(num,score);
 }
 public void Compute(int score)//分數總和
 {total= total+score;}

 public void Compare(int num,int score)//歸類最高及最低分
 {
   if (self_cnt==1)
   {
    max_score=score;
    min_score=score;
    max_num=num;
    min_num=num;
   }

   if (score>max_score)
      {
       max_score=score;
       max_num=num;
      }
   if (score       {
        min_score=score;
        min_num=num;
       }
 }

 public double Get_avg()//算出平均
 {
   avg=total/self_cnt;
   return avg;
 }

 public int Get_max_num()//最高分的號碼
 {return max_num;}

 public int Get_max_score()//最高分
 {return max_score;}

 public int Get_min_num()//最低分的號碼
 {return min_num;}

 public int Get_min_score()//最低分
 {return min_score;}

 public static int get_tot_cnt()//回傳學生人數
 {return cnt;}

}

public class joy11081
{
       public static void main(String[] args)
       {
         Student classA = new Student();
                 classA.Student_data(10,90);
                 classA.Student_data(20,30);
                 classA.Student_data(30,40);
                 classA.Student_data(40,50);

         Student classB = new Student();
                 classB.Student_data(11,10);
                 classB.Student_data(21,30);
                 classB.Student_data(31,60);
                 classB.Student_data(41,70);
                 classB.Student_data(51,90);

         System.out.print("A班平均:");
         System.out.println(classA.Get_avg());
         System.out.print("A班最高分");
         System.out.println(classA.Get_max_score());
         System.out.print("A班最高分的號碼");
         System.out.println(classA.Get_max_num());
         System.out.print("A班最低分");
         System.out.println(classA.Get_min_score());
         System.out.print("A班最低分的號碼");
         System.out.println(classA.Get_min_num());


         System.out.print("B班平均:");
         System.out.println(classB.Get_avg());
         System.out.print("B班最高分");
         System.out.println(classB.Get_max_score());
         System.out.print("B班最高分的號碼");
         System.out.println(classB.Get_max_num());
         System.out.print("B班最低分");
         System.out.println(classB.Get_min_score());
         System.out.print("B班最低分的號碼");
         System.out.println(classB.Get_min_num());
         System.out.print("兩班總人數:");
         System.out.println(Student.get_tot_cnt());
       }

}


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Joy 的頭像
    Joy

    正Man's World

    Joy 發表在 痞客邦 留言(0) 人氣()