题目如下:
在java项目中随机挑选5个进行程序的编写:
1)包含类的封装,get/set方法。
2)包含构造方法和构造方法的重载。
3)包含继承,方法重写。
4)包含抽象类和接口。
5)包含异常处理机制6)包含自定义异常。
7)包含super,final关键字。
8)包含多态。
9)包含4个字符串处理方法。
10)包含选择语句和循环语句
public class UniversityStudent extends Student implements Scholarship{
private int spot;
private double avg;
public UniversityStudent(String name, String sno, String classname, int spot, double avg) {
super(name, sno, classname);
this.spot = spot;
this.avg = avg;
}
@Override
public boolean isShip() {
if (this.avg>95 && spot>9){
return true;
}
return false;
}
public String show(){
return super.show()+",绩点:"+this.spot+",平均分:"+this.avg;
}
}
public class 自定义异常 {
/*
* 创建方法printDeptAndEmp(),两个参数,部门编号,员工编号,1-5 抛出部门异常,1-10 抛出员工异常,然后在主调函数中对可能的异常分别进行处理
DepartmentException
EmployeeException
两个自定义异常
* */
void printDeptAndEmp(int depid,int empid) throws DepartmentException,EmployeeException {
if(depid>=1 && depid<=5) {
throw new DepartmentException("部门id不能在1~5之间。");
}
if(empid>=1 && empid<=10) {
throw new DepartmentException("部门id不能在1~10之间。");
}
System.out.println("部门ID="+depid+",员工ID="+empid);
}
public static void main(String[] args) {
try {
new 自定义异常().printDeptAndEmp(7, 3);
}catch(DepartmentException ex1) {
System.out.println(ex1.getMessage());
}catch(EmployeeException ex2) {
System.out.println(ex2.getMessage());
}
}
}
class EmployeeException extends Exception{
private String msg;
public EmployeeException() {}
public EmployeeException(String msg) {
this.msg = msg;
}
@Override
public String getMessage() {
return "员工ID错误:" + msg;
}
}
class DepartmentException extends Exception{
private String msg;
public DepartmentException() {}
public DepartmentException(String msg) {
this.msg = msg;
}
@Override
public String getMessage() {
return "部门ID错误:" + msg;
}
}
都是一些基础题目 如果你想从事这一行 打好基础比较好