//饿死了,要去吃饭了,我写了一个添加学生的例子
public class XiTi{
public static void main(String[] args){
new Student().start();
}
}
class Student{
String xuehao; //学号
String name; //姓名
byte sex; //性别
long phone; //电话
String zhuzhi; //住址
static Student[] arr = new Student[10];
{
}
void start(){
System.out.println("---------主界面---------");
System.out.println("1、添加学生信息");
System.out.println("2、查询学生信息");
System.out.println("3、修改学生信息");
System.out.println("4、所有学生信息列表");
System.out.println("5、退出系统\n");
java.util.Scanner sc = new java.util.Scanner(System.in);
try{
int num = sc.nextInt();
if(num == 1){
System.out.println("您选择了<添加学生信息>,正在为您跳转...");
add(new Student());
}
}catch(Exception e){
System.out.println("输入有误,请重新操作!");
new Student().start();
}
}
//添加方法
boolean add(Student stu){
System.out.println("\n>>>添加学生信息页面");
int num = 0;
try{
java.util.Scanner sc = new java.util.Scanner(System.in);
System.out.println(++num+".请输入学号:");
stu.xuehao = sc.next();
System.out.println(++num+".请输入姓名:");
stu.name = sc.next();
System.out.println(++num+".请输入性别:");
String sex = sc.next();
if("男".equals(sex)){
stu.sex = 0;
}else if("女".equals(sex)){
stu.sex = 1;
}else{
System.out.println("年龄只能输入<男>或<女>.");
}
System.out.println(++num+".请输入手机号:");
stu.phone = sc.nextLong();
System.out.println(++num+".请输入住址:");
stu.zhuzhi = sc.next();
}catch(Exception e){
System.out.println("输入有误,请重新操作!");
new Student().start();
}
int i = 0;
arr[i++] = stu;
return stu != null ? true : false;
}
}
楼主,程序如下:
public class StudentSystem {
static Student1[] student = new Student1[10];
static int index = 0;
public static void show()
{
print("============学生信息管理系统===========", 1);
print("1、添加学生信息",1);
print("2、查询学生信息",1);
print("3、修改学生信息",1);
print("4、所有学生信息列表",1);
print("5、退出系统",1);
print("请选择操作项:", 2);
Scanner scanner = new Scanner(System.in);
int action = scanner.nextInt();
switch (action) {
case 1:
Student1 s = new Student1();
print("请输入学生学号:", 2);
int sno = scanner.nextInt();
s.setSno(sno);
print("请输入学生姓名:", 2);
String name = scanner.next();
s.setName(name);
print("请输入学生性别:", 2);
int sex = scanner.nextInt();
s.setSex(sex);
print("请输入学生电话:", 2);
String phone = scanner.next();
s.setPhone(phone);
print("请输入学生住址:", 2);
String address = scanner.next();
s.setAddress(address);
if(index >= 10)
{
print("学生人数已满!",1);
}
else
{
student[index++] = s;
}
break;
case 2:
print("请输入学生学号:", 2);
int no = scanner.nextInt();
for(int i=0;i
if(student[i].getSno() == no)
{
System.out.println(student[i]);
break;
}
}
break;
case 3:
print("请输入要修改信息的学生学号:", 2);
int mno = scanner.nextInt();
for(int i=0;i
if(student[i].getSno() == mno)
{
print("请输入学生姓名:", 2);
String n = scanner.next();
student[i].setName(n);
print("请输入学生性别:", 2);
int sx = scanner.nextInt();
student[i].setSex(sx);
print("请输入学生电话:", 2);
String p = scanner.next();
student[i].setPhone(p);
print("请输入学生住址:", 2);
String addr = scanner.next();
student[i].setAddress(addr);
print("修改成功!", 1);
break;
}
}
break;
case 4:
for(int i=0;i
System.out.println(student[i]);
}
break;
case 5:
print("系统退出!",2);
System.exit(0);
break;
default:
print("操作有误,请重新选择!", 2);
break;
}
}
public static void print(String info,int flag)
{
if(flag == 1)
{
System.out.println(info);
}
else
{
System.out.print(info);
}
}
public static void main(String[] args) {
while(true)
{
show();
}
}
}
class Student1
{
private int sno;
private String name;
private int sex;
private String phone;
private String address;
public int getSno() {
return sno;
}
public void setSno(int sno) {
this.sno = sno;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String toString()
{
return this.sno + "\t" + this.name + "\t" + this.sex + "\t" + this.phone + "\t" + this.address;
}
}
功能已全部实现,细节验证需你自己完善,具体你运行程序操作下就知道了。
有问题欢迎提问,满意请采纳!有分就加点。
控制台程序?