用虛線分割的是三個類,寫的很清楚,跪求大神幫幫忙!package javaoopch5.training1;public class Student {? private int? id;? private String? name;? private String sex;? public int getId() {?? ?return id;}public void setId(int id) {?? ?this.id = id;}public String getName() {?? ?return name;}public void setName(String name) {?? ?this.name = name;}public String getSex() {?? ?return sex;}public void setSex(String sex) {?? ?this.sex = sex;}public Student() {?? ?super();}public Student(int id, String name, String? sex) {?? ?super();?? ?this.id = id;?? ?this.name = name;?? ?this.sex = sex;}? ? }----------------------------------------------------------------package javaoopch5.training1;import java.util.ArrayList;import java.util.List;public class StuMar {?? ?private List list=new ArrayList();?? ?public void AddStudent(Student s){?? ??? ?list.add(s);?? ?}?? ?public void showAll(){?? ?System.out.println("學號\t姓名\t性別");?? ?for(int i=0;i<list.size();i++){?? ?Student s=(Student) list.get(i);?? ?System.out.println(s.getId()+"\t"+s.getName()+"\t"+s.getSex());}?? ?}}--------------------------------------------------------------------------------------------package javaoopch5.training1;import java.util.Scanner;public class test {?? ?public static void main(String[] args) {?? ??? ? String choose2;?? ??? ? int id = 0;?? ??? ? String name = null;?? ??? ? String sex = null;?? ??? ? ?? ??? ? do{?? ??? ?System.out.println("歡迎使用學生管理系統");?? ??? ?System.out.println("請選擇:1.添加學生 2.查詢學生? 3.刪除學生\n");?? ??? ??? ??? ?Scanner sc=new Scanner(System.in);?? ??? ? int input =sc.nextInt();?? ??? ??? ??? ? if(input==1)?? ??? ? {?? ??? ??? ? System.out.println("請輸入學生的學號\n");?? ??? ??? ?? id=sc.nextInt();?? ??? ??? ? System.out.println("請輸入學生的姓名\n");?? ??? ??? ?? name =sc.next();?? ??? ??? ? System.out.println("請輸入學生的性別\n");?? ??? ??? ? sex=sc.next();?? ??? ? }else?? ??? ? {?? ??? ??? ? System.out.println("選擇其他");?? ??? ? }?? ??? ? System.out.println("是否繼續(y/n)");?? ??? ??? choose2=sc.next();?? ??? ?}while(choose2.equals("y"));?? ??? ? Student stu=new Student( id, name,sex);?? ??? ? StuMar stum=new StuMar();?? ??? ? stum.AddStudent(stu);?? ??? ? stum.showAll();?? ??? ??? ? ?? ??? ? ?? ?}}?? ??? ? ?? ??? ??? ??? ??? ?
添加回答
舉報
0/150
提交
取消