python定义一个学生类_使用面向对象思想,定义一个学生类Student,该类包括以下字段:姓名name,学号stuNo和成绩score。...

展开全部

你好,纯手打,建议看一下是62616964757a686964616fe4b893e5b19e31333365663530否符合你的要求。public class Student {

private String name;

private Integer stuNo;

private Double score;

//省略get set方法

public Student(){

}

public Student(String name,Integer stuNo,Double score){

this.name = name;

this.stuNo = stuNo;

this.score = score;

}

public String toString(){

return this.name+"\t"+this.stuNo+"\t"+this.score;

}

}

public class TestStudent {

public static void main(String[] args){

List list = new ArrayList();

list.add(new Student("Jack",1001,67.0d));

list.add(new Student("Rose",1002,89.0d));

list.add(new Student("James",1003,45.0d));

list.add(new Student("Lucy",1004,95.0d));

list.add(new Student("Anna",1005,80.0d));

Systen.out.println("姓名\t学号\t成绩");

for(Student stu : list){

System.out.println(stu.toString());

}

}

}

  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,谢谢您的提问。根据您的要求,我可以生成一个可以查询和添加student表的jsp页面。下面是代码示例: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>学生信息管理系统</title> </head> <body> <h1>学生信息管理系统</h1> <% // 数据库连接信息 String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8"; String user = "root"; String password = "123456"; // 数据库操作相关变量 Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; // 查询所有学生信息 String sql = "SELECT * FROM student"; conn = DriverManager.getConnection(url, user, password); pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); %> <h2>学生信息列表</h2> <table border="1"> <tr> <th>学号</th> <th>姓名</th> <th>年龄</th> </tr> <% while (rs.next()) { %> <tr> <td><%= rs.getString("stuNo") %></td> <td><%= rs.getString("stuName") %></td> <td><%= rs.getString("stuAge") %></td> </tr> <% } %> <% rs.close(); %> <% pstmt.close(); %> <% conn.close(); %> </table> <br> <h2>添加学生信息</h2> <form action="add_student.jsp" method="post"> <label for="stuNo">学号:</label> <input type="text" name="stuNo" required><br> <label for="stuName">姓名:</label> <input type="text" name="stuName" required><br> <label for="stuAge">年龄:</label> <input type="number" name="stuAge" required><br> <input type="submit" value="提交"> </form> </body> </html> 请注意,这只是一个简单的示例页面,具体实现细节还需要根据您的实际需求进行修改和完善。如果需要其他帮助,请随时与我联系。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值