JAVA第十次作业
1.
import java.util.Scanner;
public class pd357 {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("请输入一个整数:");
int a=sc.nextInt();
if(a%3==0&&a%5==0&&a%7==0){
System.out.println("能被整除");
}else{System.out.println("不能被整除");}
}
}
2.
public class Ren {
private String name;
private int age;
private String xb;
public void duty(int a){
switch(a){
case 1:
System.out.println("职责:好好学习");
break;
case 2:
System.out.println("职责:教书育人");
break;
}
}
public void setName(String name){
this.name=name;
}
public void setAge(int age){
this.age=age;
}
public void setXb(String xb){
this.xb=xb;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
public String getXb(){
return xb;
}
public String toString(){
return "name:"+this.name+",age:"+this.age+",xb:"+this.xb;
}
}
3.
public class Student extends Ren{
private int sno;
private int score;
public Student(String name,int age,String xb,int sno,int score){
this.sno=sno;
this.score=score;
this.setName(name);
this.setAge(age);
this.setXb(xb);
}
public Student(){}
public void setSno(int sno){
this.sno=sno;
}
public void setScore(int score){
this.sno=score;
}
public int getSno(){
return sno;
}
public int getScore(int score){
return score;
}
public String toString(){
return "sno:"+sno+"score"+score;
}
public void display(){
System.out.println("name:"+this.getName());
System.out.println("age:"+this.getAge());
System.out.println("xb:"+this.getXb());
System.out.println("sno:"+this.sno);
System.out.println("score:"+this.score);
}
}
package d10czy;
public class Teacher extends Ren{
private int tno;
private String subject;
public Teacher(String name,int age,String xb,int sno,String subject){
this.tno=sno;
this.subject=subject;
this.setName(name);
this.setAge(age);
this.setXb(xb);
}
public void setTno(int sno){
this.tno=sno;
}
public void setSubject(int score){
this.subject=subject;
}
public int getTno(){
return tno;
}
public String getSubject(String subject){
return subject;
}
public String toString(){
return "tno:"+tno+"subject:"+subject;
}
public void display(){
System.out.println("name:"+this.getName());
System.out.println("age:"+this.getAge());
System.out.println("xb:"+this.getXb());
System.out.println("tno:"+this.tno);
System.out.println("subject:"+this.subject);
}
}
public class TestDemo {
public static void main(String[] args){
Student s=new Student("Hestia",19,"男",001,100);
Teacher t=new Teacher("Arona", 21, "女", 002, "高等元素论");
s.display();
s.duty(1);
t.display();
t.duty(2);
}
}