package?entity;
在劍河等地區,都構建了全面的區域性戰略布局,加強發展的系統性、市場前瞻性、產品創新能力,以專注、極致的服務理念,為客戶提供網站設計、做網站 網站設計制作按需求定制制作,公司網站建設,企業網站建設,成都品牌網站建設,營銷型網站建設,外貿網站制作,劍河網站建設費用合理。
public?class?Market?{
private?int?id;//id
private?int?num;//數量
private?String?goods;//商品
private?double?price;//價格
public?Market(int?id,?int?num,?String?goods,?double?price)?{
super();
this.id?=?id;
this.num?=?num;
this.goods?=?goods;
this.price?=?price;
}
public?int?getId()?{
return?id;
}
public?void?setId(int?id)?{
this.id?=?id;
}
public?int?getNum()?{
return?num;
}
public?void?setNum(int?num)?{
this.num?=?num;
}
public?String?getGoods()?{
return?goods;
}
public?void?setGoods(String?goods)?{
this.goods?=?goods;
}
public?double?getPrice()?{
return?price;
}
public?void?setPrice(double?price)?{
this.price?=?price;
}
public?double?calc(?){
double?sum=price*num;
System.out.println("您消費共計:"+sum+"¥");
return?sum;
}
}
package?test;
import?java.util.HashMap;
import?java.util.Map;
import?java.util.Scanner;
import?entity.Market;
public?class?Test?{
private?static?MapInteger,Market?goods=new?HashMapInteger,?Market();
public?static?void?main(String[]?args)?{
System.out.println("-------超市計價系統-------");
String?goods1="可口可樂";
String?goods2="爆米花";
String?goods3="益達";
printTable("編號","商品","價格");
printTable("1",goods1,"3.0¥");
printTable("2",goods2,"5.0¥");
printTable("3",goods3,"10.0¥");
goods.put(1,?new?Market(1,?1,?goods1,?3.0));
goods.put(2,?new?Market(2,?1,??goods2,?5.0));
goods.put(3,?new?Market(3,?1,?goods3,?10.0));
Scanner?input?=?new?Scanner(System.in);
System.out.println("請輸入商品的編號:");
int?num?=?input.nextInt();
System.out.println("請輸入商品的數量");
int?amount?=?input.nextInt();
Market?market?=?goods.get(num);
market.setNum(amount);
market.calc();
}
private?static?void?printTable(String?row1,String?row2,String?row3?)?{
System.out.print(row1);
int?times=12;
if?(row2!="商品")?{
times=5;
}
for?(int?i?=?0;?i??times;?i++)?{
System.out.print("?");
}
System.out.print(row2);
for?(int?i?=?0;?i??10;?i++)?{
System.out.print("?");
}
System.out.print(row3);
System.out.println("\n");
}
}
//測試結果:
-------超市計價系統-------
編號????????????商品??????????價格
1?????可口可樂??????????3.0¥
2?????爆米花??????????5.0¥
3?????益達??????????10.0¥
請輸入商品的編號:
3
請輸入商品的數量
5
您消費共計:50.0¥
那很簡單啊,界面用dreamweaver直接做就行 ,代碼就是JAVA訪問數據庫,就那幾行
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Conn {
private static final String driver="com.mysql.jdbc.Driver";
private static final String url="jdbc:mysql://localhost:3306/blog?user=rootpassword=root";
//獲得數據庫連接
public static Connection getConnection(){
Connection conn = null;
try {
Class.forName(driver);
conn = DriverManager.getConnection(url);
if(conn != null){
System.out.print("成功");
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;
}
//關閉Resultset
public static void closeResultSet(ResultSet rs)
{
try
{
if(rs != null)
{
rs.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}
//關閉Statement
public static void closeStatement(Statement st)
{
try
{
if(st != null)
{
st.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}
//關閉Connection
public static void closeConnection(Connection conn)
{
try
{
if(conn != null)
{
conn.close();
}
}catch (SQLException ex)
{
ex.printStackTrace();
}
}
//測試數據庫連接是否成功
public static void main(String[] args) {
Conn.getConnection();
}
}
import java.util.Vector; class Supermarket{ Vector market = null; Supermarket(){ market = new Vector(); } public void append(Goods g){ market.addElement(g); } public void delete(Goods g){ market.removeElement(g); } public void query(Goods g){ for(int i = 0;imarket.size();i++){ if((market.elementAt(i)).equals(g) == true){ g.showMe(); } } } } class Goods{ private String name; private double price; private int num; public Goods(String name,double price,int num){ this.name=name; this.price = price; this.num = num; } public void sale(double buyprice){ if(num==0){ System.out.println("購買商品已售空"); return; } if(buypricethis.price){ System.out.println("余額不足"); }else{ num--; } } public void add(int quantity){ num+=quantity; } public void showMe(){ System.out.println("商品名稱:"+this.name+" 商品價格:"+this.price+"$ "+"商品個數:"+this.num); } } //很多地方給的不是很詳細,只能這么憑理解寫,測試main方法自己寫。
文章標題:免費java超市代碼 java水果超市代碼如何講解
路徑分享:http://m.newbst.com/article6/hihjog.html
成都網站建設公司_創新互聯,為您提供網站排名、外貿網站建設、網站營銷、定制開發、標簽優化、響應式網站
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯