十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
1、代码如下:
企业建站必须是能够以充分展现企业形象为主要目的,是企业文化与产品对外扩展宣传的重要窗口,一个合格的网站不仅仅能为公司带来巨大的互联网上的收集和信息发布平台,创新互联面向各种领域:成都宣传片制作等成都网站设计、全网营销推广解决方案、网站设计等建站排名服务。
Main类
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* Main 主方法
* @author bufei
*
*/
public class Main {
public static void main(String[] args) {
stuGrad();
}
public static void stuGrad() {
int stuNum = 1;
Student[] stu = new Student[stuNum];
double[] totals = new double[stuNum];
MapDouble, Integer map = new HashMap(stuNum);
for (int i = 0; i stuNum; i++) {
System.out.println("请输入第 " + (i + 1) + " 个学生信息:");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("姓名:");
String name = reader.readLine();
System.out.println("学号:");
int id = Integer.parseInt(reader.readLine());
System.out.print("语文:");
double literature = Double.parseDouble(reader.readLine());
System.out.print("数学:");
double math = Double.parseDouble(reader.readLine());
System.out.print("英语:");
double english = Double.parseDouble(reader.readLine());
stu[i] = new Student(name, id, literature, math, english);
totals[i] = stu[i].getTotal();
map.put(stu[i].getTotal(), i);
} catch (Exception e) {
//TODO: handle exception
e.printStackTrace();
}
}
Arrays.sort(totals);
for (int j = stuNum - 1; j = 0; j--) {
int i = map.get(totals[j]);
System.out.println(stu[i].toString());
}
}
}
2、Student类
public class Student {
private String name;
private int stuId;
//总分
private double total;
private double english;
//数学
private double mathematical;
//文学
private double literature;
public String getName(){
return name;
}
public void SetName(String name) {
this.name = name;
}
public int getStuId() {
return stuId;
}
public void setStuId(int stuId) {
this.stuId = stuId;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
public Student() {
}
public double getTotal() {
return this.english + this.literature + this.mathematical;
}
public double getEnglish() {
return english;
}
public void setEnglish(double english) {
this.english = english;
}
public double getMathematical() {
return mathematical;
}
public void setMathematical(double mathematical) {
this.mathematical = mathematical;
}
public double getLiterature() {
return literature;
}
public void setLiterature(double literature) {
this.literature = literature;
}
public Student(int stuId, double total, double english, double mathematical, double literature) {
this.stuId = stuId;
this.total = total;
this.english = english;
this.mathematical = mathematical;
this.literature = literature;
}
public Student(String name, int stuId, double english, double mathematical, double literature) {
this.name=name;
this.stuId = stuId;
this.english = english;
this.mathematical = mathematical;
this.literature = literature;
}
@Override
public String toString() {
return "学生 " + name + ",学号 " + stuId + ",总分 =" + getTotal() + " [英语=" + english + ", 语文="
+ literature + ", 数学=" + mathematical + "]";
}
}
3、运行效果
import java.util.ArrayList;
import java.util.Scanner;import com.sun.org.apache.xpath.internal.Arg;
public class Student {
//两个私有属性
private int no ;
private String name ;
//默认构造函数
public Student(){}
//带参构造函数
public Student(int no,String name){
this.no=no;
this.name=name;
}
//添加学生信息
public void addStudentInfo(ArrayList list){
String flag1="yes";
do{
Student student=new Student();
Scanner in =new Scanner(System.in);
System.out.println("请输入学生学号:");
student.setNo(in.nextInt());
System.out.println("请输入学生姓名:");
student.setName(in.next());
list.add(student);
System.out.println("是否继续添加学生信息(yes/no)?");
flag1=in.next();
} while(flag1.equals("yes"));
}
//读取学生信息
public void showStudentInfo(ArrayListStudent list){
System.out.println(" 学生no: "+" 学生name: ");
for(Student student:list){
System.out.println(" "+student.getNo()+" "+student.getName());
}
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public static void main(String arg[]) {
ArrayListStudent studentList= new ArrayListStudent();
Student student= new Student();
Scanner inn= new Scanner(System.in);
while(true){
System.out.println("----------------- 欢迎使用学生管理系统------------------");
System.out.println("1.输入学生信息");
System.out.println("2.显示学生信息");
System.out.println("0.退出系统");
System.out.println("请选择....");
int nn= inn.nextInt();
switch (nn) {
case 1:
student.addStudentInfo(studentList);
break;
case 2:
System.out.println("学生信息如下:");
student.showStudentInfo(studentList);
break;
case 0:
System.exit(0);
System.out.println("系统退出!");
break;
default:
break;
}
}
} }
如下所示:
public class Student {
private int sNo; //学号
private String name; //姓名
private String sex; //性别
private int yu; //语文
private int shu; //数学
private int wai; //外语
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 String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getYu() {
return yu;
}
public void setYu(int yu) {
this.yu = yu;
}
public int getShu() {
return shu;
}
public void setShu(int shu) {
this.shu = shu;
}
public int getWai() {
return wai;
}
public void setWai(int wai) {
this.wai = wai;
}
Java是一种可以撰写跨平台应用程序的面向对象的程序设计语言。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。
Java 编程语言的风格十分接近C、C++语言。Java是一个纯的面向对象的程序设计语言,它继承了 C++ 语言面向对象技术的核心,Java舍弃了C ++语言中容易引起错误的指针(以引用取代)、运算符重载(operator overloading)、多重继承(以接口取代)等特性,增加了垃圾回收器功能用于回收不再被引用的对象所占据的内存空间,使得程序员不用再为内存管理而担忧。在 Java SE 1.5 版本中,Java 又引入了泛型编程(Generic Programming)、类型安全的枚举、不定长参数和自动装/拆箱等语言特性。
Java由四方面组成:
●Java编程语言,即语法。
●Java文件格式,即各种文件夹、文件的后缀。
●Java虚拟机(JVM),即处理*.class文件的解释器。
●Java应用程序接口(Java API)
下面是一个存储班级三十名学生基本信息的 Java 代码示例:
import java.util.ArrayList;
public class Student {
private String name;
private int age;
private String gender;
public Student(String name, int age, String gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getGender() {
return gender;
}
}
public class Classroom {
private ArrayListStudent students;
public Classroom() {
this.students = new ArrayListStudent();
}
public void addStudent(Student student) {
students.add(student);
}
public ArrayListStudent getStudents() {
return students;
}
}
public class Main {
public static void main(String[] args) {
Classroom classroom = new Classroom();
// 添加 30 名学生的基本信息
classroom.addStudent(new Student("Tom", 18, "Male"));
classroom.addStudent(new Student("Alice", 19, "Female"));
// ...
// 此处省略 28 名学生的信息
// 获取所有学生的信息
ArrayListStudent students = classroom.getStudents();
for (Student student : students) {
System.out.println("Name: " + student.getName());
System.out.println("Age: " + student.getAge());
System.out.println("Gender: " + student.getGender());
}
}
}
该代码定义了两个类:Student 类表示一个学生,包含了学生的姓名、年龄和性别等信息;Classroom 类表示一个班级,包含了一个学生的列表,并提供了添加学生和获取学生列表的方法。
在 Main 类的 main 方法中,我们首先实例化一个 Classroom 对象,然后依次添加 30 名学生的信息。最后,我们调用 getStudents 方法获取所