学习Java的第十一天

学习内容:实验一学生类

程序代码:

 

import java.util.Scanner;

 

public class Student {
private String no;
private String name;
private int age;
static public int sum;//统计学生类对象总数
public Student(String no,String name,int age){//构造方法
this.no=no;
this.name=name;
this.age=age;
System.out.println("Constructor run");
sum+=1;
System.out.println("Student类对象总数为:"+sum);
}
public void setNo(String no) {//设置学号
this.no=no;
}
public String getNo(){//返回学号
return no;
}
public void setName(String name) {//设置姓名
this.name=name;
}
public String getName(){//返回姓名
return name;
}
public void setAge(int age) {//设置年龄
this.age=age;
}
public int getAge() {//返回年龄
return age;
}
public void show() {//输出学生信息
System.out.println("No:"+no+",Name:"+name+",Age:"+age);
}
@SuppressWarnings("null")
public static void main(String[] args) {//主方法
// TODO 自动生成的方法存根
String s1="20190327";
String s2="doublebest";
Student stu1 = new Student(s1,s2,0);
stu1.setAge(21);
stu1.show();
Scanner sc=new Scanner(System.in);
String s3=sc.next();
String s4=sc.next();
int a=sc.nextInt();
Student stu2=new Student(s3,s4,a);
stu2.show();
Scanner sc2=new Scanner(System.in);
String s5=sc.next();
String s6=sc.next();
int a1=sc2.nextInt();
Student stu3=new Student(s5,s6,a1);
stu3.show();
Scanner sc3=new Scanner(System.in);
String s7=sc3.next();
String s8=sc3.next();
int a2=sc3.nextInt();
Student stu4=new Student(s7,s8,a2);
stu4.show();
}
}

运行截图:

 

 遇到的问题:

明天任务:实验一Date类

 

posted @ 2020-07-16 18:18  CherriesOvO  阅读(146)  评论(0编辑  收藏  举报