1、java作业java作业上海建桥学院实验报告课程名称: Java程序设计 实验类型: 设计型 实验项目名称: 类的设计与使用 实验地点: 计算中心326 实验日期: 2018 年 5 月 24 日姓名: 学号: 班级: 成绩: 一、实验目的及要求培养面向对象的思想,要求能够用面向对象的思想去解决问题。二、实验环境及要求 jdk1.5以上的开发环境,可使用任何编辑器。三、实验内容及步骤1.String name;String school;String zy;String class;Double mxsj;Double wlsj;Double sore; 已知学生类(Student),该类中包
2、含有如下成员变量和成员方法: 1)成员变量 年级、学院、专业、班级、姓名、面向对象程序设计、网络原理、数据库、总成绩Class student 2)成员方法 计算总成绩class Student private String name; private double grade; public Student() public Student(String name, double grade) this.name = name; this.grade = grade; public String getName() return name; public void setName(Strin
3、g name) this.name = name; public double getGrade() return grade; public void setGrade(double grade) this.grade = grade; public class txt1 public static void main(String args) Student stu1 = new Student(); stu1.setName(zhangsan); stu1.setGrade(99); Student stu2 = new Student(lisi, 100); 2. (1)编写MyStu
4、dent类,通过该类在程序中直接为成员变量赋值,并通过控制台输出该生的姓名、学院、专业、班级和总成绩。 (2)通过构造函数为成员变量赋值,并通过控制台输出该生的姓名、学院、专业、班级和总成绩。 注意:要求以上的2种方法编程,输出结果相同四、 源程序public class MyStudent private String college; private String job; private String classes; private String name; private int oop; private int network; private int sql; private i
5、nt sum; public MyStudent(String name,String college,String job, String classes, int oop, int network,int sql) this.name = name; this.college = college; this.job = job; this.classes = classes; this.oop = oop; work = network; this.sql = sql; public int sum() return oop+network+sql; public String getCo
6、llege() return college; public void setCollege(String college) this.college = college; public String getJob() return job; public void setJob(String job) this.job = job; public String getClasses() return classes; public void setClasses(String classes) this.classes = classes; public String getName() r
7、eturn name; public void setName(String name) this.name = name; public int getOop() return oop; public void setOop(int oop) this.oop = oop; public int getNetwork() return network; public void setNetwork(int network) work = network; public int getSql() return sql; public void setSql(int sql) this.sql
8、= sql; public String toString() return 姓名:+getName()+ +学院:+getCollege()+ +专业:+getJob()+ +班级:+getClasses()+ +总成绩:+sum(); public static void main(String args) MyStudent test1=new MyStudent(cyb,外国语学院,计算机,计算机1班,89,86,99); System.out.println(test1); public int sum() return oop+network+sql;/getter,setter方
9、法public String getGrade() return grade;public void setGrade(String grade) this.grade=grade;public String getCollege() return college;public void setCollege(String college) this.college = college;public void setJob(String job) this.job = job;public String getClass() return class;public void setclass(
10、String calss) this.class=class;public String getName() this.name = name;public void setName(String name) this.name=namepublic int getOop() return oop;public void setOop(int oop) this.oop = oop;public int getNetwork() return network;public void getNetwork(int network) work = network;public int getSql
11、() return sql;public void getSql(int sql) return sql = sql;/to String 方法public String toString() retunrn年级:+getGrade()+学院:+getCollege()+专业:+getJob()+班级:+getClass()+姓名:+getName()+面向对象程序设计:+getOop()+网络原理:+getNetwork()+数据库:+getSql()+总成绩:+sum();public static void main(Stringargs) Student s = new Student
12、(); s.setGrade(大二); s.setJob(计算机); s.setClass(计算机一班); s.setName(cyb); s.setOop(89); s.setName(86); S.setSql(99);System.out.println(s);2.1).public class MyStudent private String grade=大二; private String college=外国语学院; private String job=计算机; private String class=计算机1班; private String name=cyb; privat
13、e int oop=89; private int network=86; private int sql=99; private int sum=oop+network+sql; public MyStudent() public String toString() return 姓名:+name+ +学院:+college+ +专业:+job+ +班级:+class+ +总成绩:+sum; public static void main(String args) MyStudent ms=new MyStudent(); System.out.println(ms); 五、实验结果六、分析与讨论(实验过程中发现的重点与难点,请认真总结)在一开始我认这门课光光是在于理论知识的,但
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1