제발 도와주세요!!ㅜㅜㅠㅠ자바 오버라이딩 질문!!

제발 도와주세요!!ㅜㅜㅠㅠ자바 오버라이딩 질문!!

작성일 2022.08.12댓글 1건
    게시물 수정 , 삭제는 로그인 필요

자바 오버라이딩 하는데 너무 어려워서 질문드립니다 ㅜㅜ!! 이렇게 
코드를 짰는데 Place , Company, University 의 각각에 오버라이딩을 활용해 toString 메서드랑 introduce 메서드를 만들고. tosString 메서드는 title = 제목 nRooms = 방 수 nEmployees = 종업원 수  이런식으로 그냥 그 뜻 의미만 정의하기. 를 하고싶습니다!! 어떻게 해야될까요 ㅜ?
class Place {
private String title;
private int nRooms;
private String location;

public Place(String title, int nRooms, String location) {
super();
this.title = title;
this.nRooms = nRooms;
this.location = location;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public Integer getnRooms() {
return nRooms;
}

public void setnRooms(int nRooms) {
this.nRooms = nRooms;
}

public String getLocation() {
return location;
}

public void setLocation(String location) {
this.location = location;
}


}
<pre>class University extends Place {
private int rank;
private int nStudents;
private int nTeachers;

public University(String title, int nRooms, String location, int rank, int nStudents,
int nTeachers) {
super(title, nRooms, location);
this.rank = rank;
this.nStudents = nStudents;
this.nTeachers = nTeachers;
}

public int getRank() {
return rank;
}

public void setRank(int rank) {
this.rank = rank;
}

public int getnStudents() {
return nStudents;
}

public void setnStudents(int nStudents) {
this.nStudents = nStudents;
}

public int getnTeachers() {
return nTeachers;
}

public void setnTeachers(int nTeachers) {
this.nTeachers = nTeachers;
}

}



profile_image 익명 작성일 -

아까 올라왔던 질문같은데... 뭐 이런건가요?

public class Main { public static void main(String[] args) { Company c = new Company("넥슨", 20, "경기", 100, 2.0, 30); University u = new University("서울대", 20, "서울", 1, 50, 10); System.out.println("회사정보"); c.introduce(); System.out.println(c); System.out.println("대학정보"); u.introduce(); System.out.println(u); } } class Place { private String title; private int nRooms; private String location; public Place(String title, int nRooms, String location) { super(); this.title = title; this.nRooms = nRooms; this.location = location; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public Integer getnRooms() { return nRooms; } public void setnRooms(int nRooms) { this.nRooms = nRooms; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public void introduce() { System.out.printf("이곳은 %s이며, %d개의 숙소를 가지고 있고, 위치는 %s입니다.\n", title, nRooms, location); } @Override public String toString() { return String.format("title: %s\nnRooms: %d\nlocation:%s\n", title, nRooms, location); } } class University extends Place { private int rank; private int nStudents; private int nTeachers; public University(String title, int nRooms, String location, int rank, int nStudents, int nTeachers) { super(title, nRooms, location); this.rank = rank; this.nStudents = nStudents; this.nTeachers = nTeachers; } public int getRank() { return rank; } public void setRank(int rank) { this.rank = rank; } public int getnStudents() { return nStudents; } public void setnStudents(int nStudents) { this.nStudents = nStudents; } public int getnTeachers() { return nTeachers; } public void setnTeachers(int nTeachers) { this.nTeachers = nTeachers; } @Override public void introduce() { super.introduce(); System.out.printf("등급은 %d등급이고 학생수는 %d명이며, 교사들의 숫자는 %d명입니다.\n", rank, nStudents, nTeachers); } @Override public String toString() { return super.toString() + String.format("rank: %d\nnStudents: %d\nnTeachers:%d\n", rank, nStudents, nTeachers); } } class Company extends Place { private int nEmployees; private double annualIncome; private int nDepartments; public Company(String title, int nRooms, String location, int nEmployees, double annualIncome, int nDepartments) { super(title, nRooms, location); this.nEmployees = nEmployees; this.annualIncome = annualIncome; this.nDepartments = nDepartments; } public int getnEmployees() { return nEmployees; } public void setnEmployees(int nEmployees) { this.nEmployees = nEmployees; } public double getAnnualIncome() { return annualIncome; } public void setAnnualIncome(double annualIncome) { this.annualIncome = annualIncome; } public int getnDepartments() { return nDepartments; } public void setnDepartments(int nDepartments) { this.nDepartments = nDepartments; } @Override public void introduce() { super.introduce(); System.out.printf("사원수는 %d명이고 연간소득은 %.1f이며, 부서의 숫자는 %d개입니다.\n", nEmployees, annualIncome, nDepartments); } @Override public String toString() { return super.toString() + "nEmployees: " + nEmployees + "\nannualIncome: " + annualIncome + "\nDepartments: " + nDepartments + "\n"; } }

자바 질문드려요

... 메서드 오버로딩과 메서드 오버라이딩을... 제발 도와주세요 .. 위의 문제는 기본적이면서도 중요한 자바 개념입니다.. 문제의...

급!!!!!! 자료구조 연결리스트에서...

... 내공 있는거 전부 다 겁니다ㅠㅠ 제발 도와주세요ㅠㅠㅠㅠ 윗분이 답해주신 내용이 질문내용과 좀... Clone()을 오버라이딩 해서 직접 넣어줄수도...