我有一些课程,例如UniversityDepartment
&PolytechnicDepartment
这两个课程扩展了AcademicDepartment
课程。问题要我这样做。可以有AcademicDepartment
研究生课程和研究生课程。部门将是 2 University
& Polytechnic
。一个部门是理工学院还是大学,取决于研究生课程中实验室的数量。因此,如果我们在预科或研究生课程中,我认为用户必须从键盘输入它,如果我们在预科,我们还必须被问到如果我们在理工学院或大学,我们有多少个实验室。那么我将如何做到这一点?我会给你一个我的代码示例:
import java.io.*;
public class AcademicDepartment {
private String names;
private String labs;
private int teachers;
private int graduates;
// private boolean studies;
public void infostudies() throws IOException{
System.out.println("Enter the department you want."
+ "Press 1 for pre-graduate program or 2 for after-graduate program" );
String studies = "";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
studies = br.readLine();
if (studies == 1){
System.out.println("You are in pre-graduate program");
System.out.println("Enter the number of labs");
String labs = "";
BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
labs = br1.readLine();
if (labs > 5){
System.out.println("The department is polytechnic");
}
}
if (labs < 5 ){
System.out.println("The department is University");
}
else
{
System.out.println("Wrong number try again");
}
}
public AcademicDepartment(String names,String labs,int teachers,int graduates){
names = new String(names);
this.labs = labs;
this.teachers = teachers;
this.graduates = graduates;
}
public void printdepartmentinfo(){
System.out.println("The names are:" + names);
System.out.println("The labs are:" + labs);
System.out.println("The GRADUATES are:" + graduates);
System.out.println("The teachers are:" + teachers);
}
}