Java实验一

1.使用集成开发环境编写程序,输出九九乘法表。

public class MultiplicationTable {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		for(int i=1;i<10;i++){
			for(int j=1;j<=i;j++){
				System.out.printf("%d*%d=%d\t",j,i,i*j);
			}
			System.out.println();
		}
	}
}

2.定义一个学生类:

class Student {
	private String id;
	private String name;
	private int age;
	private String sex;
	private String classs;	
	public Student(){	
	}
	public Student(String id,String name,int age,String sex,String classs){
		this.id = id;
		this.name=name;
		this.age=age;
		this.sex=sex;
		this.classs=classs;
	}	
	public String getId(){
		return id;
	}
	public void setId(String id){
		this.id = id;
	}	
	public String getName(){
		return name;
	}
	public void setName(String name){
		this.name=name;
	}
	public int getAge(){
		return age;
	}
	public void setAge(int age){
		this.age=age;
	}
	public String getSex(){
		return sex;
	}
	public void setSex(String sex){
		this.sex=sex;
	}
	public String getClasss(){
		return classs;
	}
	public void setClasss(String classs){
		this.classs = classs;
	}
	public void introduction() {
		System.out.println("学号:"+id+",姓名:"+name+",年龄:"+age+",性别:"+sex+",班级:"+classs);
	}
	public void chooseClass() {
		System.out.println("课程已选");
	}
	public void exam() {
		System.out.println("考试已经开始,请注意考试纪律!");
	}
}

public class StudentTest {
	public static void main(String[] args) {
		Student s1 = new Student("201800709","张三",19,"男","软件工程01班");
		s1.introduction();
		s1.chooseClass();
		s1.exam();
	}
}

3.某学校教师的工资=基本工资+课时补贴。教授的基本工资为 5000 元,每学时补贴 70 元;副教授的基本工资为 3500 元,每学时补贴 60 元;讲师的基本工资为 2600 元,每学时补贴 55 元。已知某个教师的学时数,计算该教师的每月工资。(要求使用继承实现)。

class Teacher{
	private double basisSelary;
	private double studyTime;
	private double benfit;
	public double getBasisSelary() {
		return basisSelary;
	}
	public void setBasisSelary(double basisSelary) {
		this.basisSelary = basisSelary;
	}
	public double getStudyTime() {
		return studyTime;
	}
	public void setStudyTime(double studyTime) {
		this.studyTime = studyTime;
	}
	public double getBenfit() {
		return benfit;
	}
	public void setBenfit(double benfit) {
		this.benfit = benfit;
	}
	
	 void showSelary(){
		System.out.println("该教师每月工资为"+(basisSelary+benfit*studyTime)+"元");	
	}
}

class Professor extends Teacher {
	public Professor() {
		// TODO Auto-generated constructor stub
	}
	public Professor( double studyTime){
		setBasisSelary(5000);
		setStudyTime(studyTime);
		setBenfit(70);
	}	
}

class AssociateProfessor extends Teacher {
	public AssociateProfessor() {
		// TODO Auto-generated constructor stub
	}
	public AssociateProfessor( double studyTime){
		setBasisSelary(3500);
		setStudyTime(studyTime);
		setBenfit(60);
	}
}

class Lecture extends Teacher {
	public Lecture() {
		// TODO Auto-generated constructor stub
	}
	public Lecture( double studyTime){
		setBasisSelary(2600);
		setStudyTime(studyTime);
		setBenfit(55);
	}
}

public class TeacherTest {
	public static void main(String[] args) {
		Professor p1  =new Professor(0);
		p1.showSelary();
		AssociateProfessor a1 = new AssociateProfessor(0);
		a1.showSelary();
		Lecture l1 = new Lecture(0);
		l1.showSelary();
	}

4.编写一个 Java 应用程序,该程序包括三个类:Anthropoid 类人猿类、People

类和主类 E。要求:

(1)类人猿类中有构造方法:Anthropoid(String s),并且有一个 public

void speak()方法,在该方法中输出“咿咿呀呀……”的信息。

(2)People 类是类人猿的子类,在 People 类中重写 speak()方法,在该方

法中输出“我的语言已经很丰富了”的信息。

(3)在 People 类中新增方法 void think(),在该方法中输出“认真思考”。

(4)在主类 E 的 main 方法中,分别创建类人猿与 People 类的实例化对象

测试这两个类的功能。

class Anthropoid{
	public Anthropoid() {
		// TODO Auto-generated constructor stub
	}
	public Anthropoid(String s){	
	}	
	public void speck(){
		System.out.println("咿咿呀呀……");
	}
}
class People extends Anthropoid{
	
	public void speck(){
		System.out.println("我的语言已经很丰富了");
	}
	void think(){
		System.out.println("认真思考");
	}
}
public class E {
	public static void main(String[] args) {
		Anthropoid a1 = new Anthropoid();
		a1.speck();
		People p1 = new People();
		p1.speck();
		p1.think();
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值