package 学生;
public class person1 {
 public String name;
 public String birthday;
 public String grade;
 public String gender;
 public String province;
 public String city;
 public static int count=0;
 public person1(String name,String birthday,String grade,String gender,String province,String city) {
  this.name=name;
  this.birthday=birthday;
  this.grade=grade;
  this.gender=gender;
  this.province=province;
  this.city=city;
  count++;
  // TODO 自动生成的构造函数存根
 }
 public static void main(String[] args) {
  Student stud1=new Student("李明","1998-1-1","2017","男","青海省","西宁市","计算机","网络工程",88,89);
  stud1.show1();
  stud1.Setnumber();
  Student stud2=new Student("张三","1999-11-1","2018","男","四川省","成都市","计算机","物联网工程",98,96);
  stud2.show1();
  stud2.Setnumber();
  Student stud3=new Student("王二","2000-10-1","2017","女","辽宁省","大连市","计算机","计算机科学与技术",78,84);
  stud3.show1();
  stud3.Setnumber();
  Student stud4=new Student("张四","1997-12-1","2017","女","青海省","海东市","计算机","网络工程",74,84);
  stud4.show1();
  stud4.Setnumber();
  stud1.searchname("张");
  stud2.searchname("张");
  stud3.searchname("张");
  stud1.searchplace("青海省");
  stud2.searchplace("青海省");
  stud3.searchplace("青海省");
  stud1.Sum();
  stud2.Sum();
  stud3.Sum();
  stud4.Sum();
  
 }
}
 class Student extends person1
{
 public String department,speciality;
 public int math;
 public int computer;
 public static int sum=0;
 public static int total=0;
 public static int sum1=0;
 public static int total1=0;
 public static int sum2=0;
 public static int total2=0;
 public Student(String name,String birthday,String grade,String gender,String province,String city,String department,String speciality,int math,int computer)
 {
  super(name,birthday,grade,gender,province,city);
  this.department=department;
  this.speciality=speciality;
  this.math=math;
  this.computer=computer;
 }
 public void show1()
 {
  System.out.println("\n");
  System.out.println("基本信息为:");
  System.out.println("姓名为:"+this.name);
  System.out.println("生日为:"+this.birthday);
  System.out.println("性别为:"+this.gender);
  System.out.println("省份为:"+this.province);
  System.out.println("城市为:"+this.city);
  System.out.println("系为:"+this.department);
  System.out.println("专业为:"+this.speciality);
  System.out.println("数学成绩为:"+this.math);
  System.out.println("计算机成绩为:"+this.computer);
 }
 public void Setnumber()
 {
  System.out.print("学号为:");
  if(this.speciality=="网络工程")
   System.out.println(this.grade+"33111"+this.count);
  else if(this.speciality=="物联网工程")
   System.out.println(this.grade+"33112"+this.count);
  else if(this.speciality=="计算机科学与技术")
   System.out.println(this.grade+"33113"+this.count);
  
 }
 public void searchname(String nam)
 {
  int i=1;
  i=name.indexOf(nam);
  if(i!=-1) {
   System.out.println("\n");
   System.out.println("输入查找姓名信息的查找结果为:");
   System.out.println(nam);
   System.out.println(name+" "+birthday+" "+grade+" "+gender+" "+province+" "+city+" "+department+" "+speciality+" "+math+" "+computer);
  }
 }
 public void searchplace(String place)
 {
  int i=1;
  i=province.indexOf(place);
  if(i!=-1) {
   System.out.println("\n");
   System.out.println("输入查找地名信息的查找结果为:");
   System.out.println(place);
   System.out.println(name+" "+birthday+" "+grade+" "+gender+" "+province+" "+city+" "+department+" "+speciality+" "+math+" "+computer);
  }
 }
 public void Sum()
 {  
  
  System.out.println("\n");
  if(this.speciality=="网络工程") {
   System.out.println("经汇总后的网络工程班的数学成绩和计算机成绩分别为:");
   this.sum=this.sum+this.math;
   this.total=this.total+this.computer;
   System.out.println(this.sum);
   System.out.println(this.total);
  }
  else if(this.speciality=="物联网工程"){
   System.out.println("经汇总后的物联网工程班的数学成绩和计算机成绩分别为:");
   this.sum1=this.sum1+this.math;
   this.total1=this.total1+this.computer;
   System.out.println(this.sum1);
   System.out.println(this.total1);
  }
  else if(this.speciality=="计算机科学与技术"){
   System.out.println("经汇总后的计算机科学班的数学成绩和计算机成绩分别为:");
   this.sum2=this.sum2+this.math;
   this.total2=this.total2+this.computer;
   System.out.println(this.sum2);
   System.out.println(this.total2);
  } 
 }
}
 
实验结果:

 

实验心得:

1.此次实验难度较大,但也让我们充分认识到了类的继承和多态性。

2.此次实验主要的卡壳的地方在于对类的继承认识不够透彻,一看到题目中的查找操作无从下手。

3.实验中遇到了很多问题,但经过网上的查询和不断的修改基本完成了此次实验。

posted on 2019-05-06 21:26  买门票  阅读(182)  评论(0编辑  收藏  举报