A sentimental robot

"Has~A" exercise 본문

Java

"Has~A" exercise

GOD03219 2017. 12. 28. 15:04

Data Class 1




public class Name {

 private String name;

 public Name() {

 }

 public Name(String name) {
  this.name = 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;
 }

 
}


Processing Class




import java.util.Scanner;

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;
 }

 public static void main(String[] args) {


  Scanner sc = new Scanner(System.in);
  Management ss = new Management();


  System.out.print("name input :");
  ss.setName(sc.next());


  System.out.print("kor :");
  ss.setKor(sc.nextInt());


  System.out.print("eng :");
  ss.setEng(sc.nextInt());


  System.out.print("mat :");
  ss.setMat(sc.nextInt());


  ss.setTotal();

 ss.setAvg();

  System.out.println(ss.getName());
  System.out.println(ss.getKor());
  System.out.println(ss.getEng());
  System.out.println(ss.getMat());
  System.out.println(ss.getTotal());
  System.out.println(ss.getAvg());

 }

}

'Java' 카테고리의 다른 글

Is~a 상속관계  (0) 2017.12.29
Extended.ver  (0) 2017.12.28
Has~a  (0) 2017.12.28
This  (0) 2017.12.28
Object oriented style exercise  (0) 2017.12.28