重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
lListStudent students = new ArrayListStudent();
成都创新互联公司是一家专注于网站设计制作、成都做网站与策划设计,道里网站建设哪家好?成都创新互联公司做网站,专注于网站建设十年,网设计领域的专业建站公司;建站业务涵盖:道里等地区。道里做网站价格咨询:028-86922220
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();
}
//创建一个学生实体类 封装stuId stuName stuYW stuSx stuYY 这5个属性。。。
//已经帮你把数据拆分出来 并以Student 对象的形式放入集合中了 接下来 给分吧 哇咔咔
用java写的话,可以用List来实现学生管理系统:\x0d\x0a首先,管理系统是针对学生对象的,所以我们先把学生对象就写出来:\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这里面定义了一些得到当前学生对象数据的一些get方法,和成绩修改的set方法,代码很简单,就不做详细的解答。\x0d\x0a就下来就是我们的正文了。\x0d\x0a虽然我们暂时不用swing来做界面,但是总得要看的过去吧,所以,先做了一个比较简单的界面:\x0d\x0a System.out.println("***************");\x0d\x0a System.out.println("*欢迎来到学生管理系统 *");\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如何获取到键盘所输入的数据---------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接下来就是各个功能的实现:\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("*欢迎来到学生管理系统 *");\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
我也是初学写的不好
public class Student {
static int[] gradesArray={87,68,94,100,83,78,85,91,76,87};
public Student(int[]gradesArray){
}
public void printAllGrade(){
for (int i = 0; i gradesArray.length; i++) {
System.out.println("学号"+(i+1)+"成绩是"+gradesArray[i]);
}
}
public void printAvarage(){
double sum = 0;
for (int i = 0; i gradesArray.length; i++) {
sum+=gradesArray[i];
}
System.out.println("\n平均成绩是"+sum/gradesArray.length);
}
public void printMax(){
int max=gradesArray[0];
for (int i = 0; i gradesArray.length; i++) {
if(gradesArray[i]max){
max=gradesArray[i];
}
}
System.out.println("\n最高分时"+max);
}
public void printMin(){
int min=gradesArray[0];
for (int i = 0; i gradesArray.length; i++) {
if (gradesArray[i]min){
min=gradesArray[i];
}
}
System.out.println("\n最低分时"+min);
}
public void printDistribution(){
int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,j=0,k=0;
for (int i = 0; i gradesArray.length; i++) {
if(gradesArray[i]10){
a++;
}else if (gradesArray[i]=10gradesArray[i]20) {
b++;
}
else if (gradesArray[i]=20gradesArray[i]30) {
c++;
}
else if (gradesArray[i]=30gradesArray[i]40) {
d++;
}
else if (gradesArray[i]=40gradesArray[i]50) {
e++;
}
else if (gradesArray[i]=50gradesArray[i]60) {
f++;
}
else if (gradesArray[i]=60gradesArray[i]70) {
g++;
}
else if (gradesArray[i]=70gradesArray[i]80) {
h++;
}
else if (gradesArray[i]=80gradesArray[i]90) {
j++;
}
else if (gradesArray[i]=90gradesArray[i]100) {
k++;
}
}
System.out.println("\n成绩分布是");
System.out.print("0-10:");
for (int i = 0; i =a; i++) {
System.out.print("*");
}
System.out.print("10-20:");
for (int i = 0; i =b; i++) {
System.out.print("*");
}
System.out.print("20-30:");
for (int i = 0; i =c; i++) {
System.out.print("*");
}
System.out.print("30-40:");
for (int i = 0; i =d; i++) {
System.out.print("*");
}
System.out.print("40-50:");
for (int i = 0; i =e; i++) {
System.out.print("*");
}
System.out.print("50-60:");
for (int i = 0; i =f; i++) {
System.out.print("*");
}
System.out.print("60-70:");
for (int i = 0; i =g; i++) {
System.out.print("*");
}
System.out.print("70-80:");
for (int i = 0; i =h; i++) {
System.out.print("*");
}
System.out.print("80-90:");
for (int i = 0; i =j;i++) {
System.out.print("*");
}
System.out.print("90-100:");
for (int i = 0; i =k; i++) {
System.out.print("*");
}
}
public static void main(String[] args) {
Student student=new Student(gradesArray);
student.printAllGrade();
student.printAvarage();
student.printMax();
student.printMin();
student.printDistribution();
}
}
import java.util.ArrayList;
import java.util.List;
public class Student {
private String name;
private int grade;
private ListStudent students= new ArrayListStudent();
//增加学生
public void addStudent(Student student){
students.add(student);
}
//根据姓名删除学生
public void removeStudent(String name){
for(int i = 0;i students.size();i++){
if(students.get(i).name.equals(name)){
students.remove(i);
}
}
}
//
public Student(String name, int grade) {
this.name = name;
this.grade = grade;
}
public String getName() {
return name;
}
public ListStudent getStudents() {
return students;
}
public void setStudents(ListStudent students) {
this.students = students;
}
public void setName(String name) {
this.name = name;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
}
累了,不写了睡觉
稍等吧 现在帮你写个 不是难事 写出来通知你 需要数据库吗?
还在不?
Student 类
public class Student
{
private int id;
private int age;
private int score;
private String name;
public Student()
{
}
public Student(int id, int age, int score, String name)
{
this.id = id;
this.age = age;
this.score = score;
this.name = name;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
public int getScore()
{
return score;
}
public void setScore(int score)
{
this.score = score;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
@Override
public String toString()
{
return "学号:" + id + " 姓名:" + name + " 年龄:" + age + " 成绩:" + score;
}
}
Manager类
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Manager
{
private ListStudent list;
public Manager(ListStudent list)
{
this.list = list;
}
public ListStudent getList()
{
return list;
}
public void setList(ListStudent list)
{
this.list = list;
}
//添加学生
public void add(Student s)
{
list.add(s);
}
//根据学生学号返回学生年龄
public int search(int id)
{
for(IteratorStudent iter = list.iterator(); iter.hasNext();)
{
Student s = iter.next();
if(s.getId() == id)
{
return s.getAge();
}
}
return -1;
}
//删除学生
public void remove(int id)
{
for(IteratorStudent iter = list.iterator(); iter.hasNext();)
{
Student s = iter.next();
if(s.getId() == id)
{
list.remove(s);
}
}
}
//计算总成绩
public int allScore()
{
int score = 0;
int temp = 0;
for(IteratorStudent iter = list.iterator(); iter.hasNext();)
{
Student s = iter.next();
temp = s.getScore();
score += temp;
}
return score;
}
//修改成绩
public void update(int id)
{
for(IteratorStudent iter = list.iterator(); iter.hasNext();)
{
Student s = iter.next();
if(s.getId() == id)
{
s.setScore(s.getScore() + 10);
}
}
}
}
测试类 Client
import java.util.ArrayList;
import java.util.List;
public class Client
{
public static void main(String[] args)
{
ListStudent list = new ArrayListStudent();
Manager manager = new Manager(list);//创建一个管理者
Student s1 = new Student();//无参构造方法创建的学生实例
//通过方法设置s1的属性
s1.setId(201105);
s1.setAge(20);
s1.setScore(100);
s1.setName("zhangsan");
Student s2 = new Student(201101,21,98,"lisi");//通过带参数的构造方法创建实例
Student s3 = new Student(201108,25,95,"zhaoliu");
Student s4 = new Student(201110,23,80,"xiaoming");
Student s5 = new Student(201106,28,78,"hello");
//放到集合当中
manager.getList().add(s1);//添加学生
manager.getList().add(s2);
manager.getList().add(s3);
manager.getList().add(s4);
manager.getList().add(s5);
System.out.println(list);
System.out.println(manager.allScore());
System.out.println(manager.search(201110));//根据学生学号查询学生年龄
manager.remove(201110);//删除学生
manager.update(201101);//修改成绩
}
}
可以完成你上述的基本要求,如果改动可以自行修改 很简单。