有一个初级JAVA编程,需要大家帮助,需要用JAVA编写,谢谢大家了。
编写一个学生类,name,age,result编写一个老师类,name,age,salary编写各自的业务方法,1、在学生类中编写,打印学生所有信息的方法。2、在老师的类...
编写一个学生类,name,age,result
编写一个老师类,name,age,salary
编写各自的业务方法,
1、在学生类中编写,打印学生所有信息的方法。
2、在老师的类中,编写一个可以调用打印学生所有信息的方法。
3、在老师类中编写给学生加5分的一个方法,而且打印出开始分数和加分后的分数。
4、在老师类中编写一个可以给老师加500元工资的方法,而且打印开始工资和加薪之后的工资 展开
编写一个老师类,name,age,salary
编写各自的业务方法,
1、在学生类中编写,打印学生所有信息的方法。
2、在老师的类中,编写一个可以调用打印学生所有信息的方法。
3、在老师类中编写给学生加5分的一个方法,而且打印出开始分数和加分后的分数。
4、在老师类中编写一个可以给老师加500元工资的方法,而且打印开始工资和加薪之后的工资 展开
4个回答
展开全部
建议楼主采用这种方法
==================================学生类===================================
public class Student {
private String name;
private int age;
private int result;
/**
* 打印学生信息
* @param s 学生对象
*/
public void outStudentMess(Student s){
System.out.println("学生姓名:" + s.getName() + " 学生年龄:" + s.getAge() + " 学生成绩:" + s.getResult());
}
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 int getResult() {
return result;
}
public void setResult(int result) {
this.result = result;
}
}
================================教师类====================================
public class Teacher{
private String name;
private int age;
private long salary;
/**
* 老师类调用打印学生信息方法
* @param s
*/
public void outStudentsMess(Student s){
new Student().outStudentMess(s);
}
/**
* 教师给学生加分方法
* @param addResult 所加的分数
* @param s 学生对象
*/
public void addStudentsResult(int addResult, Student s){
int beforeAdd = s.getResult();
s.setResult(s.getResult() + addResult);
int afterAdd = s.getResult();
System.out.println("学生 " + s.getName() + " 分数,加分之前:" + beforeAdd + " 加分之后:" + afterAdd);
}
/**
* 教师给教师加钱方法
* @param addResult 所加的分数
* @param s 老师对象
*/
public void addTeacherSal(long addSalary, Teacher t){
long beforeAdd = t.getSalary();
t.setSalary(t.getSalary() + addSalary);
long afterAdd = t.getSalary();
System.out.println("老师 " + t.getName() + " 钱数,加钱之前:" + beforeAdd + " 加钱之后:" + afterAdd);
}
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 long getSalary() {
return salary;
}
public void setSalary(long salary) {
this.salary = salary;
}
}
=============================测试类========================================
public class Test {
public static void main(String[] args) {
Student s = new Student();
s.setAge(12);
s.setName("王二麻子");
s.setResult(55);
Student s1 = new Student();
s1.setAge(15);
s1.setName("谢臭脚");
s1.setResult(65);
Teacher t = new Teacher();
t.setAge(55);
t.setName("张大嘴");
t.setSalary(2000);
s.outStudentMess(s1);
s.outStudentMess(s);
t.outStudentsMess(s1);
t.addStudentsResult(5, s1);
t.addStudentsResult(16, s);
t.addTeacherSal(510, t);
}
}
==================================学生类===================================
public class Student {
private String name;
private int age;
private int result;
/**
* 打印学生信息
* @param s 学生对象
*/
public void outStudentMess(Student s){
System.out.println("学生姓名:" + s.getName() + " 学生年龄:" + s.getAge() + " 学生成绩:" + s.getResult());
}
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 int getResult() {
return result;
}
public void setResult(int result) {
this.result = result;
}
}
================================教师类====================================
public class Teacher{
private String name;
private int age;
private long salary;
/**
* 老师类调用打印学生信息方法
* @param s
*/
public void outStudentsMess(Student s){
new Student().outStudentMess(s);
}
/**
* 教师给学生加分方法
* @param addResult 所加的分数
* @param s 学生对象
*/
public void addStudentsResult(int addResult, Student s){
int beforeAdd = s.getResult();
s.setResult(s.getResult() + addResult);
int afterAdd = s.getResult();
System.out.println("学生 " + s.getName() + " 分数,加分之前:" + beforeAdd + " 加分之后:" + afterAdd);
}
/**
* 教师给教师加钱方法
* @param addResult 所加的分数
* @param s 老师对象
*/
public void addTeacherSal(long addSalary, Teacher t){
long beforeAdd = t.getSalary();
t.setSalary(t.getSalary() + addSalary);
long afterAdd = t.getSalary();
System.out.println("老师 " + t.getName() + " 钱数,加钱之前:" + beforeAdd + " 加钱之后:" + afterAdd);
}
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 long getSalary() {
return salary;
}
public void setSalary(long salary) {
this.salary = salary;
}
}
=============================测试类========================================
public class Test {
public static void main(String[] args) {
Student s = new Student();
s.setAge(12);
s.setName("王二麻子");
s.setResult(55);
Student s1 = new Student();
s1.setAge(15);
s1.setName("谢臭脚");
s1.setResult(65);
Teacher t = new Teacher();
t.setAge(55);
t.setName("张大嘴");
t.setSalary(2000);
s.outStudentMess(s1);
s.outStudentMess(s);
t.outStudentsMess(s1);
t.addStudentsResult(5, s1);
t.addStudentsResult(16, s);
t.addTeacherSal(510, t);
}
}
展开全部
这些题很面熟 好像是出自同一人之手吧 既然去学了就自己完成 别人告诉你答案有什么用
要是那样的话 还不如不去学呢
要是那样的话 还不如不去学呢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Teacher{
private String name;
private int salary,age;
Student s=null;
publicTeacher(int salary){
this.salary=salary;
}
public int getSalary(){
return salary;
}
public void setSalary(int salary){
this.salary+=salary;
}
public String getString(){
return s.getString();
}
public void setStudentChengJi(int chengji){
s.setChengJi(chengji);
}
public static void main(String[] args){
s=new Student("小马",12,63);
Teacher t=new Teacher(2000);
System.out.println(t.getString());
System.out.println("加分前");
System.out.println(s.getChengJi());
t.setStudentChengJi(5);
System.out.println("加分后");
System.out.println(s.getChengJi());
System.out.println("加工资前");
System.out.prinltn(s.getSalary());
t.setSalary(500);
System.out.println("加工资后");
System.out.prinltn(s.getSalary());
}
}
class Student{
private String name;
private int age;
private int chengji;
public Student(String name,int age,int chengji){
this.name=name;
this.age=age;
this.chengji=chengji;
}
public void setChengJi(int chengji){
this.chengji+=chengji;
}
public int getChengJi(){
return chengji;
}
public String getString(){
return name+"今年"+age+"分数是"+chengji;
}
}
private String name;
private int salary,age;
Student s=null;
publicTeacher(int salary){
this.salary=salary;
}
public int getSalary(){
return salary;
}
public void setSalary(int salary){
this.salary+=salary;
}
public String getString(){
return s.getString();
}
public void setStudentChengJi(int chengji){
s.setChengJi(chengji);
}
public static void main(String[] args){
s=new Student("小马",12,63);
Teacher t=new Teacher(2000);
System.out.println(t.getString());
System.out.println("加分前");
System.out.println(s.getChengJi());
t.setStudentChengJi(5);
System.out.println("加分后");
System.out.println(s.getChengJi());
System.out.println("加工资前");
System.out.prinltn(s.getSalary());
t.setSalary(500);
System.out.println("加工资后");
System.out.prinltn(s.getSalary());
}
}
class Student{
private String name;
private int age;
private int chengji;
public Student(String name,int age,int chengji){
this.name=name;
this.age=age;
this.chengji=chengji;
}
public void setChengJi(int chengji){
this.chengji+=chengji;
}
public int getChengJi(){
return chengji;
}
public String getString(){
return name+"今年"+age+"分数是"+chengji;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询