⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 itemorder.java

📁 一个网上书店的例子
💻 JAVA
字号:
package myshop;
import java.sql.ResultSet;

public class ItemOrder {
  private String sort;	
  private String bookId;
  private String title;
  private String author;
  private float price;
  private int numItems;

  public ItemOrder(){
  }
  public ItemOrder(String bid,String sort) {
    this.bookId=bid;
    this.sort=sort;
    ResultSet rs=getItemInfo(bid,sort);
    try{
    if(rs.next()){
    	this.title=rs.getString("title");
    	this.author=rs.getString("author");
    	this.price=rs.getFloat("price");
    	this.numItems=1;
    }
	}catch(Exception e){System.out.println(e);}
  }
	
  public String getSort(){
  	return(sort);
  } 		
  public String getBookId() {
    return(bookId);
  }
  public String getTitle() {
    return(title);
  }
  public String getAuthor() {
    return(author);
  }
  public float getPrice() {
    return(price);
  }
  
  public int getNumItems() {
    return(numItems);
  }
  public void setNumItems(int n) {
    this.numItems = n;
  }
  public void incrementNumItems() {
    setNumItems(getNumItems() + 1);
  }
  public void cancelOrder() {
    setNumItems(0);
  }
  
  public double getTotalCost() {
    return(getNumItems() * getPrice());
  }
  
  ResultSet getItemInfo(String id,String sort){
  	DbConnect db=new DbConnect();
  	String op="select  *  from "+sort+" where id='"+id+"'";
  	ResultSet rs=db.executeQuery(op);
  	return rs;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -