lListStudent students = new ArrayListStudent();
創(chuàng)新互聯(lián)于2013年開始,先為習水等服務(wù)建站,習水等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為習水企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
BufferedReader br = new BufferedReader(new FileReader("D:\student.txt"));
String tmpStr = br.readLine();
while(tmpStr != null){
int firstIndex = tmpStr.indexOf(" ");
int secondIndex = tmpStr.indexOf(" ",firstIndex + 1);
int thirdIndex = tmpStr.indexOf(" ", secondIndex + 1);
int forthIndex = tmpStr.indexOf(" ", thirdIndex + 1);
Integer stuId = Integer.parseInt(tmpStr.substring(0,firstIndex));
String stuName = tmpStr.substring(firstIndex + 1,secondIndex);
Integer stuYW = Integer.parseInt(tmpStr.substring(secondIndex + 1,thirdIndex));
Integer stuSX = Integer.parseInt(tmpStr.substring(thirdIndex + 1,forthIndex));
Integer stuYY = Integer.parseInt(tmpStr.substring(forthIndex + 1));
Student student = new Student();
student.setStuId(stuId);
student.setStuName(stuName);
student.setStuYW(stuYW);
student.setStuSX(stuSX);
student.setStuYY(stuYY);
students.add(student);
tmpStr.readLine();
}
//創(chuàng)建一個學生實體類 封裝stuId stuName stuYW stuSx stuYY 這5個屬性。。。
//已經(jīng)幫你把數(shù)據(jù)拆分出來 并以Student 對象的形式放入集合中了 接下來 給分吧 哇咔咔
用java寫的話,可以用List來實現(xiàn)學生管理系統(tǒng):\x0d\x0a首先,管理系統(tǒng)是針對學生對象的,所以我們先把學生對象就寫出來:\x0d\x0apackage bean;\x0d\x0apublic class Student {\x0d\x0a String name;\x0d\x0a String studentId;\x0d\x0a String sex;\x0d\x0a int grade;\x0d\x0a public Student(String name,String studentId,String sex,int grade){\x0d\x0a this.name= name;\x0d\x0a this.studentId= studentId;\x0d\x0a this.sex = sex;\x0d\x0a this.grade = grade; \x0d\x0a }\x0d\x0a public int getGrade(){\x0d\x0a return grade;\x0d\x0a }\x0d\x0a public String getName(){\x0d\x0a return name;\x0d\x0a }\x0d\x0a public String getSex(){\x0d\x0a return sex;\x0d\x0a }\x0d\x0a public void setGrade(int g){\x0d\x0a this.grade = g;\x0d\x0a }\x0d\x0a public String getStudentId(){\x0d\x0a return studentId;\x0d\x0a }\x0d\x0a}\x0d\x0a這里面定義了一些得到當前學生對象數(shù)據(jù)的一些get方法,和成績修改的set方法,代碼很簡單,就不做詳細的解答。\x0d\x0a就下來就是我們的正文了。\x0d\x0a雖然我們暫時不用swing來做界面,但是總得要看的過去吧,所以,先做了一個比較簡單的界面:\x0d\x0a System.out.println("***************");\x0d\x0a System.out.println("*歡迎來到學生管理系統(tǒng) *");\x0d\x0a System.out.println("*1:增加學生 *");\x0d\x0a System.out.println("*2:刪除學生 *");\x0d\x0a System.out.println("*3:修改成績 *");\x0d\x0a System.out.println("*4:查詢成績 *");\x0d\x0a System.out.println("***************");\x0d\x0a System.out.println("您想選擇的操作是:");\x0d\x0a這里可以看到,我們的是用一個1234來選擇項目,說以不得不講一下Java如何獲取到鍵盤所輸入的數(shù)據(jù)---------Scanner ,要使用這個,首先需要import進來一個包:\x0d\x0a例如這里:\x0d\x0aimport java.util.*;\x0d\x0a之后的兩行代碼搞定輸入:\x0d\x0aScanner sc = new Scanner(System.in);\x0d\x0a int choice = sc.nextInt();\x0d\x0a接下來就是各個功能的實現(xiàn):\x0d\x0a\x0d\x0apackage test;\x0d\x0aimport java.util.*;\x0d\x0aimport bean.Student;\x0d\x0apublic class Manager {\x0d\x0a static List StudentList = new LinkedList();\x0d\x0a public static void main(String[] agrs){\x0d\x0a select(StudentList); \x0d\x0a }\x0d\x0a private static void select(List StudentList ){\x0d\x0a System.out.println("***************");\x0d\x0a System.out.println("*歡迎來到學生管理系統(tǒng) *");\x0d\x0a System.out.println("*1:增加學生 *");\x0d\x0a System.out.println("*2:刪除學生 *");\x0d\x0a System.out.println("*3:修改成績 *");\x0d\x0a System.out.println("*4:查詢成績 *");\x0d\x0a System.out.println("***************");\x0d\x0a System.out.println("您想選擇的操作是:");\x0d\x0a Scanner sc = new Scanner(System.in);\x0d\x0a int choice = sc.nextInt(); \x0d\x0a switch(choice){\x0d\x0a //增加學生\x0d\x0a case 1:\x0d\x0a System.out.print("請輸入學生的姓名:");\x0d\x0a Scanner Sname = new Scanner(System.in);\x0d\x0a String name = Sname.nextLine();\x0d\x0a System.out.print("請輸入學生的性別:");\x0d\x0a Scanner Ssex = new Scanner(System.in);\x0d\x0a String sex = Ssex.nextLine();\x0d\x0a System.out.print("請輸入學生的學號:");\x0d\x0a Scanner SId = new Scanner(System.in);\x0d\x0a String studentId = SId.nextLine();\x0d\x0a System.out.print("請輸入學生的成績:");\x0d\x0a Scanner Sgrade = new Scanner(System.in);\x0d\x0a int grade = Sgrade.nextInt();\x0d\x0a StudentList.add(new Student(name,studentId,sex,grade));\x0d\x0a System.out.println("添加成功?。。。。?);\x0d\x0a select(StudentList);\x0d\x0a break;\x0d\x0a //刪除學生成績\x0d\x0a case 2:\x0d\x0a System.out.print("請告訴我需要刪除學生的學號:");\x0d\x0a Scanner Sid = new Scanner(System.in);\x0d\x0a String SstudentId = Sid.nextLine();\x0d\x0a boolean isfindDelete = false;\x0d\x0a for (int i = 0; i
回答于?2022-11-16
代碼如下,隨便附一句,一定要看寫的源碼,我已經(jīng)盡量馬馬虎虎的寫了,你更容易看懂。
public?class?Test?{
//?第八題
public?static?final?int?NUM?=?100;
public?static?final?double?GOOD?=?99.99;
public?static?final?String?CLASSNAME?=?"Test.Class";
public?static?final?long?MAX?=?9999999;
public?static?void?main(String[]?args)?{
//?第一題
byte?byte1?=?1;
short?short1?=?1;
int?int1?=?1;
long?long1?=?1;
float?float1?=?1;
double?double1?=?1.0;
System.out.println("byte1?-?"?+?byte1);
System.out.println("short1?-?"?+?short1);
System.out.println("int1?-?"?+?int1);
System.out.println("long1?-?"?+?long1);
System.out.println("float1?-?"?+?float1);
System.out.println("double1?-?"?+?double1);
//?第二題
String?name;
char?sex;
int?age;
boolean?isMember;
//?第三題
int?score1;
double?score2?=?98.5;
//?第四題
double?f1?=?10.1,?f2?=?34.2;
System.out.println("f1,f2的和:"?+?(f1?+?f2));
System.out.println("f1,f2的差:"?+?(f1?-?f2));
System.out.println("f1,f2的積:"?+?(f1?*?f2));
System.out.println("f1,f2的商:"?+?(f1?/?f2));
//?第五題
int?f3?=?5;
double?f4?=?45.6;
System.out.println("f3,f4的和:"?+?(f3?+?f4));
System.out.println("f3,f4的差:"?+?(f3?-?f4));
System.out.println("f3,f4的積:"?+?(f3?*?f4));
System.out.println("f3,f4的商:"?+?(f3?/?f4));
//?第六題
int?A?=?65;
char?a?=?(char)?A;
System.out.println("整型互轉(zhuǎn)char:"?+?a);
//?第七題
double?timor?=?123.456789;
int?x?=?Integer
.parseInt(new?java.text.DecimalFormat("0").format(timor));//?四舍五入
System.out.println("double?-?int?:"?+?x);
//?第八題(定義在最開始)
System.out.println("常量NUM的值:?"?+?NUM);
System.out.println("常量GOOD的值:?"?+?GOOD);
System.out.println("常量CLASSNAME的值:?"?+?CLASSNAME);
System.out.println("常量MAX的值:?"?+?MAX);
//?第九題(自定義商品類)
class?Goods?{
private?String?name;
private?double?price;
private?int?count;
private?double?total;
public?Goods(String?name,?double?price,?int?count)?{
this.name?=?name;
this.price?=?price;
this.count?=?count;
}
public?void?print()?{
total?=?price?*?count;
System.out.println("商品名 ??價格??????數(shù)量 ?總價");
System.out.println(name?+?" ?"?+?price?+?" ?"?+?count?+?" ?"
+?total);
}
}
Goods?goods?=?new?Goods("蘋果",?2,?10);
goods.print();
//?第十題
double?pi?=?3.14,?r,?d;
r?=?4;
d?=?2?*?r;
System.out.println("圓的周長:?"?+?(pi?*?d));
System.out.println("圓的面積:?"?+?(pi?*?r?*?r));
//?第十一題
String?qqname?=?"1234567890";
String?qqpassword?=?"asd!#@#$%66";
Date?birth?=?new?Date(2014,?5,?1);
boolean?isVIP?=?false;
char?sex1?=?'男';
StringBuilder?personInfo?=?new?StringBuilder();
personInfo.append("我是一個快樂的騷年");
personInfo
.append("然后a!#$%^*asdasdasdasdsa9d87a9s8d79asdjidauisdhausdihiasd");
//?第十二題
class?Swaper?{
public?void?change(int?num1,?int?num2)?{
int?temp?=?num1;
num1?=?num2;
num2?=?temp;
System.out.printf("a=%d,b=%d\n",?num1,?num2);
}
}
int?a1?=?2;
int?b1?=?5;
Swaper?swaper?=?new?Swaper();
swaper.change(a1,?b1);
}
}