Java实验报告

Java面向对象实验报告1


实验要求

1. 已知学生类(Student),该类中包含有如下成员变量和成员方法:
1)成员变量
年级、学院、专业、班级、姓名、面向对象程序设计、网络原理、数据库、总成绩
2)成员方法
计算总成绩
2. (1)编写MyStudent类,通过该类在程序中直接为成员变量赋值,并通过控制台输出该生的姓名、学院、专业、班级和总成绩。
(2)通过构造函数为成员变量赋值,并通过控制台输出该生的姓名、学院、专业、班级和总成绩。
注意:要求以上的2种方法编程,输出结果相同
3.定义一个代表员工的Employee类。它的属性包括“员工姓名”、“员工号码”、“员工基本薪水”、“员工薪水增长额”;它的方法包括“构造方法”、“获取员工性名”、“获取员工号码”、“获取员工基本薪水”、“计算薪水增长额”及“计算增长后的工资总额”。


代码实现

public class Employee {
	private String e_name;
	private int e_id,e_basicSalary,e_increase;
	
	public Employee() {
		super();
	}
	public Employee(String e_name, int e_id, int e_basicSalary, int e_increase) {
		super();
		this.e_name = e_name;
		this.e_id = e_id;
		this.e_basicSalary = e_basicSalary;
		this.e_increase = e_increase;
	}
	public String getE_name() {
		return e_name;
	}

	public int getE_id() {
		return e_id;
	}

	public int getE_basicSalary() {
		return e_basicSalary;
	}
	//计算薪水增长额
	public int countSIn(int e_basicSalary,double rate){//rate薪水增长率
		double e_increase=e_basicSalary*rate;
		return (int)e_increase;
	}
	//计算增长后的工资总额计算增长后的工资总额
	public int zong(int e_basicSalary,int e_increase){
		return e_basicSalary+e_increase;
	}
}
public class student {
	public String grade,college,major,class_b,name;
	public int FOP,NP,DB,AllScore;
	
	public student() {
		super();
	}

	public student(String grade, String college, String major, String class_b, String name, int fOP, int nP, int dB,
			int allScore) {
		super();
		this.grade = grade;
		this.college = college;
		this.major = major;
		this.class_b = class_b;
		this.name = name;
		FOP = fOP;
		NP = nP;
		DB = dB;
		AllScore = allScore;
	}
	public int AllScore(int fOP, int nP, int dB) {
		int result=fOP+nP+dB;
		return result;
	}

	@Override
	public String toString() {
		return "student [grade=" + grade + ", college=" + college + ", major=" + major + ", class_b=" + class_b
				+ ", name=" + name + ", FOP=" + FOP + ", NP=" + NP + ", DB=" + DB + ", AllScore=" + AllScore + "]";
	}
	
}

public class MyStudent {
	public static void main(String[] args) {
		//method1:年级、学院、专业、班级、姓名、面向对象程序设计、网络原理、数据库、总成绩
		student s=
				new student("大三","计算机学院","软件工程","软件一班","张三",78,89,95,0);
		int zong=s.AllScore(78, 89, 95);
		s.AllScore=zong;
		System.out.println("student [grade=" + s.grade + ", college=" + s.college + ", major=" + s.major + ", class_b=" + s.class_b
				+ ", name=" + s.name + ", FOP=" + s.FOP + ", NP=" + s.NP + ", DB=" + s.DB + ", AllScore=" + s.AllScore + "]");
		//method2:年级、学院、专业、班级、姓名、面向对象程序设计、网络原理、数据库、总成绩
		student s1=new student();
		s1.grade="大三";
		s1.college="计算机学院";
		s1.major="软件工程";
		s1.class_b="软件一班";
		s1.name="张三";
		s1.FOP=78;
		s1.NP=89;
		s1.DB=95;
		int result=s.AllScore(s1.FOP, s1.NP, s1.DB);
		s1.AllScore=result;
		System.out.println("student [grade=" + s1.grade + ", college=" + s1.college + ", major=" + s1.major + ", class_b=" + s1.class_b
				+ ", name=" + s1.name + ", FOP=" + s1.FOP + ", NP=" + s1.NP + ", DB=" + s1.DB + ", AllScore=" + s1.AllScore + "]");
	}
}	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

努力上进的小樊(派大心)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值