添加学生信息java代码 添加学生信息java代码
用Java编写学生录入信息的程序
这里有一个类
创新互联公司服务项目包括镇宁网站建设、镇宁网站制作、镇宁网页制作以及镇宁网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,镇宁网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到镇宁省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
实现学生学号,数学,语文,英语成绩录入
并且计算平均成绩,按照平均成绩高低输出信息
你可以改改!
//实现简单的学生信息输入输出和初步的成绩排序
public class Student {
private int id; //学号
private int mathScore; //数学成绩
private int chinScore; //语文成绩
private int foreScore; //外语成绩
public Student() {
id = 0;
mathScore = 0;
chinScore = 0;
foreScore = 0;
}
public Student(int newId, int newMathScore, int newChinSvore,
int newForeScore) {
id = newId;
mathScore = newMathScore;
chinScore = newChinSvore;
foreScore = newForeScore;
}
public double getAverageScore() { //求平均成绩
double averageScore = ((double) mathScore + chinScore + foreScore) / 3;
return averageScore;
}
public void output(Student student) { //输出对象的内容
System.out.println(" " + student.id + " " + student.mathScore +
" " + student.chinScore + " "
+ student.foreScore + " " +
student.getAverageScore());
}
public int max(Student a[], int n) { //Student类对象数组的前n项中的成绩最大值的索引
int position = 0;
for (int i = 1; i n; i++) {
if (a[i].getAverageScore() a[position].getAverageScore()) { //比较平均成绩
position = i;
}
}
return position;
}
public void selectSort(Student a[]) { //Student类对象数组的选择排序
for (int n = a.length; n 1; n--) {
int i = max(a, n);
Student temp = a[i];
a[i] = a[n - 1];
a[n - 1] = temp;
}
}
}
java中实现对学生信息的输入、输出、修改、查找,该如何做?
Java 代码如下:import java.util.ArrayList;
import java.util.Scanner;public class student{
private int number;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public student(){}
public student(int number, String name) {
this.number = number;
this.name = name;
}
public student writeInfo(){
student st = new student();
Scanner in = new Scanner(System.in);
System.out.println("请输入学生的学号:");
number = in.nextInt();
st.setNumber(number);
System.out.println("请输入学生的姓名:");
String name = in.next();
st.setName(name);
return st;
}
public void readInfo(ArrayList list){
for(int i=0;i=list.size()-1;i++){
student st = new student();
st = (student) list.get(i);
System.out.println("第"+(i+1)+"位学生的学号:" + st.getNumber());
System.out.println("第"+(i+1)+"位学生的姓名:" + st.getName());
}
}
public static void main(String[]args){ ArrayListstudent list = new ArrayListstudent();
student st = new student();
Scanner in = new Scanner(System.in);
while(true){
System.out.println("1、输入学生信息");
System.out.println("2、输出学生信息");
System.out.println("请选择:");
int option = in.nextInt();
switch (option) {
case 1:
list.add(st.writeInfo());
break;
case 2:
st.readInfo(list);
break;
default:
break;
}
}
}
}
java操作sql数据库,增加数据库的学生信息,求代码,谢谢了
String DBDRIVER = "oracle.jdbc.driver.OracleDriver" ;
String DBURL = "jdbc:oracle:thin:@IP地址:1521:数据库名" ;
String DBUSER = "数据库用户名" ;
String DBPASSWORD= "密码" ;
Connection con = null ;
PreparedStatement pstmt = null ;
String sql = "insert into 表a (字段a,字段b) values"+ " ('"
+ a
+ "','"
+b+"')";
Class.forName(DBDRIVER) ;
con = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
pstmt = con.prepareStatement(sql) ;
try {
pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
conn.rollback();
} finally{
pstmt.close();
con.close();
}
给点分
.给出存储班级三十名学生基本信息的Java代码,基本信息的具体赋值由考生自拟?
下面是一个存储班级三十名学生基本信息的 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 方法获取所
网站题目:添加学生信息java代码 添加学生信息java代码
文章分享:http://pwwzsj.com/article/hjgsdi.html