A sentimental robot

Extended.ver 본문

Java

Extended.ver

GOD03219 2017. 12. 28. 15:14

Data Class 1




public class Name {

 private String name;

 public String getName() {
  return name;
 }

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

}


Data Class 2




public class Subject {

 private int score;

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


 public int getScore() {
  return score;
 }

 
}


Data Class 3




public class Management {


 private Name name;
 private Subject kor;
 private Subject eng;
 private Subject mat;
 private int total;
 private float avg;


 public Management() {
  name = new Name();
  kor = new Subject();
  eng = new Subject();
  mat = new Subject();
  total = 0;
  avg = 0;
 }


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

 public void setKor(int kor) {
  this.kor.setScore(kor);
 }

 public void setEng(int eng) {
  this.eng.setScore(eng);
 }

 public void setMat(int mat) {
  this.mat.setScore(mat);
 }

 public String getName() {
  return name.getName();
 }

 public int getKor() {
  return kor.getScore();
 }

 public int getEng() {
  return eng.getScore();
 }

 public int getMat() {
  return mat.getScore();
 }

 public void setTotal() {
  this.total = kor.getScore() + eng.getScore() + mat.getScore();
 }

 public int getTotal() {
  return total;
 }

 public void setAvg() {
  this.avg = total / 3.f;
 }

 public float getAvg() {
  return avg;
 }


Processing Class




import java.util.Scanner;

public class NN {


 private Management[] ss;

 public NN() {

 }


 public NN(int num) {
  ss = new Management[num];
  for (int i = 0; i < ss.length; i++)
   ss[i] = new Management();
 }


 public void setData() {
  Scanner sc = new Scanner(System.in);
  for (int i = 0; i < ss.length; i++) {
   System.out.print("name input :");

   ss[i].setName(sc.next());
   System.out.print("kor :");
   ss[i].setKor(sc.nextInt());
   System.out.print("eng :");
   ss[i].setEng(sc.nextInt());
   System.out.print("mat :");
   ss[i].setMat(sc.nextInt());
   ss[i].setTotal();
   ss[i].setAvg();
  }

 }


 public void display() {
  for (int i = 0; i < ss.length; i++) {

   System.out.println(ss[i].getName());
   System.out.println(ss[i].getKor());
   System.out.println(ss[i].getEng());
   System.out.println(ss[i].getMat());
   System.out.println(ss[i].getTotal());
   System.out.println(ss[i].getAvg());
  }
 }


 public static void main(String[] args) {


  Scanner sc = new Scanner(System.in);
  System.out.print("The number of student :");
  int num;
  num = sc.nextInt();
  NN ct = new NN(num);

  ct.setData();
  ct.display();


 }

}

'Java' 카테고리의 다른 글

Inheritance exercise(1)  (0) 2017.12.29
Is~a 상속관계  (0) 2017.12.29
"Has~A" exercise  (0) 2017.12.28
Has~a  (0) 2017.12.28
This  (0) 2017.12.28