javaweb期末考试题截图-找零钱-sql创建表
2022/4/9 2:19:04
本文主要是介绍javaweb期末考试题截图-找零钱-sql创建表,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1、找零钱
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
function change()
{
money=Number(document.form1.txt1.value);
if(money!=parseInt(money)||money<1||money>100){
alert("请输入一个1-100的整数")
}
else{
var a=Math.floor(money/50);
var b=Math.floor((money-50*a)/20);
var c=Math.floor((money-50*a-20*b)/10);
var d=Math.floor((money-50*a-20*b-10*c)/5);
var e=(money-50*a-20*b-10*c-5*d);
alert("找零:"+"50元"+a+"张;20元"+b+"张;10元"+c+"张;5元"+d+"张;1元"+e+"张。")
}
}
</script>
输入要找的零钱
<form name="form1">
<input name="txt1" type="text"><br>
<input type="button" onclick="change()" value="找零"><br>
</form>
</body>
</html>
2、JavaBean(1)
//Book.java
package JavaBean;
public class Book {
private String bookid;
private String bookname;
private double bookprice;
public String getBookid() {
return bookid;
}
public void setBookid(String bookid) {
this.bookid = bookid;
}
public String getBookname() {
return bookname;
}
public void setBookname(String bookname) {
this.bookname = bookname;
}
public double getBookprice() {
return bookprice;
}
public void setBookprice(double bookprice) {
this.bookprice = bookprice;
}
}
3、JavaBean(2)
//Customer.java
package JavaBean;
public class Customer {
private String account;
private String password;
private String cname;
private boolean member;
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getCname() {
return cname;
}
public void setCname(String cname) {
this.cname = cname;
}
public boolean isMember() {
return member;
}
public void setMember(boolean member) {
this.member = member;
}
}
4、Dao与JavaBean
//StudentDao
package Dao;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import JavaBean.Student;
public class StudentDao {
private Connection conn =null;
private void initConnection() throws Exception{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/jyy";
conn = DriverManager.getConnection(url, "root", "123");
}
public Student getStudentByStuno(String stuno) throws Exception{
Student st=null;
initConnection();
String sql="select stuno,stuname from t_student where stuno=?";
PreparedStatement ps=conn.prepareStatement(sql);
ps.setString(1, stuno);
ResultSet rs=ps.executeQuery();
if(rs.next()){
st=new Student();
st.setStuno(rs.getString("stuno"));
st.setStuname(rs.getString("stuname"));
}
closeConnection();
return st;
}
public void closeConnection() throws Exception{
conn.close();
}
}
//JavaBean的student.java
package JavaBean;
public class Student {
private String stuno;
private String stuname;
private String stusex;
public String getStuno() {
return stuno;
}
public void setStuno(String stuno) {
this.stuno = stuno;
}
public String getStuname() {
return stuname;
}
public void setStuname(String stuname) {
this.stuname = stuname;
}
public String getStusex() {
return stusex;
}
public void setStusex(String stusex) {
this.stusex = stusex;
}
}
//ans03.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<body>
<h3>学生登陆</h3>
<form action="ans03_1.jsp" method="post">
请输入学生学号:<input type ="text" name ="stuno"><br>
请输入学生姓名:<input type ="text" name ="stuname"><br>
<input type ="submit" value="登陆">
</form>
</body>
</html>
//ans03_1.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="Dao.StudentDao"%>
<%@ page import="JavaBean.Student"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<%
request.setCharacterEncoding("UTF-8");
String stuno= request.getParameter("stuno");
String stuname= request.getParameter("stuname");
StudentDao sdao= new StudentDao();
Student student=sdao.getStudentByStuno(stuno);
if(student!=null&&student.getStuname().equals(stuname)){
out.println(stuno);
out.println(stuname);
}else{
%>
登录失败,<a href="ans03.jsp">返回登陆页面</a>
<%
}
%>
</body>
</html>
这篇关于javaweb期末考试题截图-找零钱-sql创建表的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24怎么修改Kafka的JVM参数?-icode9专业技术文章分享
- 2024-12-23线下车企门店如何实现线上线下融合?
- 2024-12-23鸿蒙Next ArkTS编程规范总结
- 2024-12-23物流团队冬至高效运转,哪款办公软件可助力风险评估?
- 2024-12-23优化库存,提升效率:医药企业如何借助看板软件实现仓库智能化
- 2024-12-23项目管理零负担!轻量化看板工具如何助力团队协作
- 2024-12-23电商活动复盘,为何是团队成长的核心环节?
- 2024-12-23鸿蒙Next ArkTS高性能编程实战
- 2024-12-23数据驱动:电商复盘从基础到进阶!
- 2024-12-23从数据到客户:跨境电商如何通过销售跟踪工具提升营销精准度?