티스토리 뷰

오늘 예정 진도 -> static멤버 전까지

이렇게 해주시고 코드 복붙 해주세요

package com;

public class FirstClass {
    public static void main(String[] args) {
        Student st1 = new Student("부엉이", 2020158004, 4.0);
        st1.introduce();
        st1.study();
        System.out.println(st1.getGpa());
        System.out.println(st1.setAndGetName("씨부엉"));
        st1.introduce();
        st1.study();
        st1.setGpa(st1.getGpa() + 0.5);
        System.out.println(st1.getGpa());
        st1.name = "부엉부엉이";
        st1.introduce();
        Student st2 = new Student();
        st2.introduce();

        System.out.println();
        School school = new School();
        school.makeStudentArray(3);
        school.addStudent(st1);
        school.addStudent(st2);
        school.setClassroom("부엉s");
        Student[] studentArray = school.getStudent();
        studentArray[2] = new Student("김승진", 1234567890, 10.0);
        school.printAll();
        School tukorea = new School((school.getStudent()), school.getClassroom());
        System.out.println();
        System.out.println(tukorea.getAllGpa()[0]);
        for(double d : tukorea.getAllGpa()){
            System.out.print(d + " ");
        }

        System.out.println();
        System.out.println();
        Student[] sArray = new Student[10];
        for(int i = 0; i < sArray.length; i++){
            sArray[i] = new Student("학생" + i, i + 1234567890, i * 1.0);
        }
        tukorea.setStudent(sArray);
        tukorea.printAll();
    }
}

 

package com;

public class Student {
    public String name;
    private int studentId;
    private double gpa;

    public Student(String name, int studentId, double gpa) {
        this.name = name;
        this.studentId = studentId;
        this.gpa = gpa;
    }
    public Student(){}

    public void introduce() {
        System.out.println("내 학번은 " + studentId + "이고 " + name + "이라고 해");
    }

    public void study() {
        System.out.println(name + " 공부중");
    }

    public String setAndGetName(String name) {
        this.name = name;
        return this.name;
    }

    public double getGpa() {
        return gpa;
    }

    public void setGpa(double gpa) {
        this.gpa = gpa;
    }
}

 

package com;

public class School {
    private Student[] student;
    private String classroom;
    private int index = 0;

    public School(){}

    public School(Student[] student, String classroom) {
        this.student = student;
        this.classroom = classroom;
    }

    public void makeStudentArray(int length){
        student = new Student[length];
    }

    public Student[] getStudent(){
        return this.student;
    }

    public void setClassroom(String classroom){
        this.classroom = classroom;
    }

    public String getClassroom(){
        return this.classroom;
    }

    public void setStudent(Student[] studentArray){
        this.student = studentArray;
    }

    public void addStudent(Student student){
        if (this.student.length > index)
            this.student[index++] = student;
    }
    public void printAll(){
        System.out.println("반 이름은: " + classroom);
        for (Student s : student) {
            s.introduce();
        }
    }

    public double[] getAllGpa(){
        double[] gpa = new double[student.length];
        for(int i = 0; i < student.length; i++){
            gpa[i] = student[i].getGpa();
        }
        return gpa;
    }
}

같은 패키지(com) 아래에 SpecialClass 클래스를 하나 만들어주세요!

package com;

public class SpecialClass {
    public static void main(String[] args) {
        InnerClass innerClass = new InnerClass();
        innerClass.print();
    }
    private static class InnerClass {
        InnerClass(){
            System.out.println("내부 클래스 생성");
        }
        private void print(){
            System.out.println("I'm a class which locate inside of the SpecialClass!");
            class InnerInnerClass {
                void print(){
                    System.out.println("Hello");
                }
            }
            InnerInnerClass innerInnerClass = new InnerInnerClass();
            innerInnerClass.print();
        }
    }
}

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
TAG
more
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함