赞
踩
- import java.util.Scanner;
- import java.text.SimpleDateFormat;//获取系统时间
- import java.util.Date;
- class Student {
- String sno; //学号
- String name; //姓名
- int age; //年龄
- String sex; //性别
- DAte birth; //出生年月日
- Student(){}
- Student(String sn){
- sno=sn;
- name="Null";
- age=0;
- sex="Null";
- }
- Student(String sn,String na,int ag,DAte bri){
- sno=sn;
- name=na;
- age=ag;
- birth=bri;
- }
- public String getSno() {
- Scanner sc=new Scanner(System.in);
- try {
- System.out.println("请输入学生学号:");
- sno=sc.next();
- return sno;
- }
- finally {
- sc.close(); //关闭系统资源,习惯
- }
- }
- public void putSno() {
- System.out.print("学号:"+sno+"\t");
- }
-
- public String getName() {
- Scanner sc=new Scanner(System.in);
- try {
-
- System.out.println("请输入学生姓名:");
- name=sc.next();
- return name;
- }
- finally {
- sc.close();
- }
- }
- public void putName() {
- System.out.print("姓名:"+name+"\t");
- }
-
- public int getAge() { //年龄
- SimpleDateFormat sd=new SimpleDateFormat("yyyy");
- Date data=new Date();
- String st=sd.format(data);
- age=Integer.parseInt(st)-birth.year;
- return age;
- }
- public void putAge() {
- System.out.print("该学生的年龄为:"+age+"岁\t\t");
- }
-
- public String getSex() {
- Scanner sc=new Scanner(System.in);
- try {
- System.out.println("请输入学生性别:");
- sex=sc.next();
- return sex;
- }
- finally {
- sc.close();
- }
- }
- public void putSex() {
- System.out.print("性别:"+sex+"\t");
- }
-
- public DAte getBrith() {
- Scanner sc=new Scanner(System.in);
- try {
- System.out.println("请输入学生出生年、月、日:");
- birth=new DAte();
- birth.getDate();
- return birth;
- }
- finally {
- sc.close();
- }
- }
- public void putBrith() {
- System.out.print("生日为:");
- birth.putDate();
- System.out.print("\t");
- }
- }

- import java.util.Scanner;
- class DAte {
- int year;
- int month;
- int day;
- DAte(){
-
- }
- void getDate() {
- Scanner sc=new Scanner(System.in);
- try {
- System.out.println("请输入年:");
- year=sc.nextInt();
- System.out.println("请输入月:");
- month=sc.nextInt();
- System.out.println("请输入日:");
- day=sc.nextInt();
- }
- finally {
- sc.close();
- }
- }
- void putDate()
- {
- System.out.print(year+"年");
- System.out.print(month+"月");
- System.out.print(day+"日");
- }
- }

- class MainStudent {
- public static void main(String arge[]) {
- Student[] stu=new Student[10];
- System.out.println("接下来我们会进行输入同学的个人信息,分别包含(学号,姓名,性别,出生年月日),若提前结束请在学号项输入-1即可");
- int i;
- for(i=0;i<10;i++)
- {
- stu[i]=new Student(); //需要给每个数组成员分别定义数组空间
- if(Integer.parseInt(stu[i].getSno())==-1)break;
- stu[i].getName();
- stu[i].getSex();
- stu[i].getBrith();
- stu[i].getAge();
- }
-
- for(int j=i-1;j>=0;j--)
- {
- stu[j].putSno();
- stu[j].putName();
- stu[j].putSex();
- stu[j].putBrith();
- stu[j].putAge();
- System.out.println();
- }
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。