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创建表的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程