클래스 상속 II
페이지 정보
작성자 최고관리자 작성일 70-01-01 09:00 조회 316 댓글 0본문
Main JAVA --------------------------------------------------------------------------------------
[code=php]
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.print(" 총 몇명의 학생이 존재합니까? ");
int number = scan.nextInt();
Student[] students = new Student[number];
for(int i=0;i<number;i++) {
String name;
int age, height, weight;
String studentID;
int grade;
double gPA;
//String teacherID;
//int monthSalary, workYear;
System.out.print("학생의 이릅을 입력하세요 : ");
name = scan.next();
System.out.print("학생의 나이를 입력하세요 : ");
age = scan.nextInt();
System.out.print("학생의 키를 입력하세요 : ");
height = scan.nextInt();
System.out.print("학생의 몸무게를 입력하세요 : ");
weight = scan.nextInt();
System.out.print("학생의 학번를 입력하세요 : ");
studentID = scan.next();
System.out.print("학생의 학년을 입력하세요 : ");
grade = scan.nextInt();
System.out.print("학생의 학점을 입력하세요 : ");
gPA = scan.nextDouble();
students[i] = new Student(name, age, height, weight, studentID, grade, gPA);
}
for (int i=0;i<number;i++) {
students[i].show();
}
}
}
[/code]
Person JAVA --------------------------------------------------------------------------------------
[code=php]
public class Person {
private String name;
private int age;
private int height;
private int weight;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public Person(String name, int age, int height, int weight, String studentID, int grade, double gPA) {
super();
this.name = name;
this.age = age;
this.height = height;
this.weight = weight;
}
}
[/code]
Student JAVA --------------------------------------------------------------------------------------
[code=php]
public class Student extends Person {
private String studentID;
private int grade;
private double GPA;
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
this.studentID = studentID;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
public double getGPA() {
return GPA;
}
public void setGPA(double gPA) {
GPA = gPA;
}
public Student(String name, int age, int height, int weight, String studentID, int grade, double gPA) {
super(name, age, height, weight);
this.studentID = studentID;
this.grade = grade;
GPA = gPA;
}
public void show() {
System.out.println("-------------------------");
System.out.println("학생 이름 : "+getName());
System.out.println("학생 나이 : "+getAge());
System.out.println("학생 키 : "+getHeight());
System.out.println("학생 몸무게 : "+getWeight());
System.out.println("학번 : "+getStudentID());
System.out.println("학년 : "+getGrade());
System.out.println("학범 : "+getGPA());
}
}
[/code]
Teacher JAVA --------------------------------------------------------------------------------------
[code=php]
public class Teacher extends Person {
private String teacherID;
private int monthSalary;
private int workYear;
public String getTeacherID() {
return teacherID;
}
public void setTeachedID(String teachedID) {
this.teacherID = teacherID;
}
public int getMonthSalary() {
return monthSalary;
}
public void setMonthSalary(int monthSalary) {
this.monthSalary = monthSalary;
}
public int getWorkYear() {
return workYear;
}
public void setWorkYear(int workYear) {
this.workYear = workYear;
}
public Teacher(String name, int age, int height, int weight, String teacherID, int monthSalary, int workYear) {
super(name, age, height, weight);
this.teacherID = teacherID;
this.monthSalary = monthSalary;
this.workYear = workYear;
}
public void show() {
System.out.println("-------------------------");
System.out.println("교사 이름 : "+getName());
System.out.println("교사 나이 : "+getAge());
System.out.println("교사 키 : "+getHeight());
System.out.println("교사 몸무게 : "+getWeight());
System.out.println("교직원 번호 : "+getTeacherID());
System.out.println("교사 월급 : "+getMonthSalary());
System.out.println("교사 연차 : "+getWorkYear());
}
}
[/code]
[code=php]
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.print(" 총 몇명의 학생이 존재합니까? ");
int number = scan.nextInt();
Student[] students = new Student[number];
for(int i=0;i<number;i++) {
String name;
int age, height, weight;
String studentID;
int grade;
double gPA;
//String teacherID;
//int monthSalary, workYear;
System.out.print("학생의 이릅을 입력하세요 : ");
name = scan.next();
System.out.print("학생의 나이를 입력하세요 : ");
age = scan.nextInt();
System.out.print("학생의 키를 입력하세요 : ");
height = scan.nextInt();
System.out.print("학생의 몸무게를 입력하세요 : ");
weight = scan.nextInt();
System.out.print("학생의 학번를 입력하세요 : ");
studentID = scan.next();
System.out.print("학생의 학년을 입력하세요 : ");
grade = scan.nextInt();
System.out.print("학생의 학점을 입력하세요 : ");
gPA = scan.nextDouble();
students[i] = new Student(name, age, height, weight, studentID, grade, gPA);
}
for (int i=0;i<number;i++) {
students[i].show();
}
}
}
[/code]
Person JAVA --------------------------------------------------------------------------------------
[code=php]
public class Person {
private String name;
private int age;
private int height;
private int weight;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public Person(String name, int age, int height, int weight, String studentID, int grade, double gPA) {
super();
this.name = name;
this.age = age;
this.height = height;
this.weight = weight;
}
}
[/code]
Student JAVA --------------------------------------------------------------------------------------
[code=php]
public class Student extends Person {
private String studentID;
private int grade;
private double GPA;
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
this.studentID = studentID;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
public double getGPA() {
return GPA;
}
public void setGPA(double gPA) {
GPA = gPA;
}
public Student(String name, int age, int height, int weight, String studentID, int grade, double gPA) {
super(name, age, height, weight);
this.studentID = studentID;
this.grade = grade;
GPA = gPA;
}
public void show() {
System.out.println("-------------------------");
System.out.println("학생 이름 : "+getName());
System.out.println("학생 나이 : "+getAge());
System.out.println("학생 키 : "+getHeight());
System.out.println("학생 몸무게 : "+getWeight());
System.out.println("학번 : "+getStudentID());
System.out.println("학년 : "+getGrade());
System.out.println("학범 : "+getGPA());
}
}
[/code]
Teacher JAVA --------------------------------------------------------------------------------------
[code=php]
public class Teacher extends Person {
private String teacherID;
private int monthSalary;
private int workYear;
public String getTeacherID() {
return teacherID;
}
public void setTeachedID(String teachedID) {
this.teacherID = teacherID;
}
public int getMonthSalary() {
return monthSalary;
}
public void setMonthSalary(int monthSalary) {
this.monthSalary = monthSalary;
}
public int getWorkYear() {
return workYear;
}
public void setWorkYear(int workYear) {
this.workYear = workYear;
}
public Teacher(String name, int age, int height, int weight, String teacherID, int monthSalary, int workYear) {
super(name, age, height, weight);
this.teacherID = teacherID;
this.monthSalary = monthSalary;
this.workYear = workYear;
}
public void show() {
System.out.println("-------------------------");
System.out.println("교사 이름 : "+getName());
System.out.println("교사 나이 : "+getAge());
System.out.println("교사 키 : "+getHeight());
System.out.println("교사 몸무게 : "+getWeight());
System.out.println("교직원 번호 : "+getTeacherID());
System.out.println("교사 월급 : "+getMonthSalary());
System.out.println("교사 연차 : "+getWorkYear());
}
}
[/code]
댓글목록 0
등록된 댓글이 없습니다.