算是最簡單的吧
創(chuàng)新互聯(lián)建站長期為上千家客戶提供的網(wǎng)站建設(shè)服務(wù),團隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為雞東企業(yè)提供專業(yè)的網(wǎng)站建設(shè)、做網(wǎng)站,雞東網(wǎng)站改版等技術(shù)服務(wù)。擁有10余年豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
package cn.job01;
import java.util.Scanner;
public class Lx07 {
public static void choice() {
System.out.println("登陸菜單 ");
System.out.println("1登陸系統(tǒng)");
System.out.println("2退出");
}
static void choice1() {
System.out.println("購物管理系統(tǒng)客戶信息");
System.out.println("1顯示所有客戶信息");
System.out.println("2添加客戶信息");
System.out.println("3修改客戶信息");
System.out.println("4查詢客戶信息");
}
static void choice2() {
System.out.println("購物管理系統(tǒng)真情回饋");
System.out.println("1幸運大放送");
System.out.println("2幸運抽獎");
System.out.println("3生日問候");
}
public static void main(String[] args) {
choice();
Scanner input = new Scanner(System.in);
System.out.println("請輸入1or2");
int num = input.nextInt();
switch (num) {
case 1:
System.out.println("主菜單");
System.out.println("1客戶信息管理");
System.out.println("2購物結(jié)算");
System.out.println("3真情回饋");
System.out.println("4注銷");
break;
}
System.out.println("選擇輸入數(shù)字");
int num1 = input.nextInt();
switch (num1) {
case 1:
choice1();
break;
case 2:
System.out.println("購物結(jié)算");
break;
case 3:
choice2();
break;
case 4:
choice();
break;
}
}
}
使用結(jié)構(gòu)體+數(shù)組,就可以 了
~
~
~
~
~~~~~~~~~~~~~~~~~~~~~~~~~
package?entity;
public?class?Market?{
private?int?id;//id
private?int?num;//數(shù)量
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("-------超市計價系統(tǒng)-------");
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("請輸入商品的數(shù)量");
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");
}
}
//測試結(jié)果:
-------超市計價系統(tǒng)-------
編號????????????商品??????????價格
1?????可口可樂??????????3.0¥
2?????爆米花??????????5.0¥
3?????益達??????????10.0¥
請輸入商品的編號:
3
請輸入商品的數(shù)量
5
您消費共計:50.0¥
1. java2s
這個網(wǎng)站非常好,分成三大類,分別是Example 、Products 、 Articles ,每個大類下又分別設(shè)許多小類,還有搜索功能,這樣查找起來非常方便。。比如,如果要學(xué)習(xí)SWT/JFace,只要把Example下的SWT JFace Eclipse 研究一下也就可以了。另外,這個網(wǎng)站還有JavaScript DHTML 、 C# / C Sharp 、 C / ANSI-C 、 SQL / MySQL 等類??傊?,非常好。
2. codeZoo
這是O'Reily旗下的,除了Java之外,還有Ruby、Python。
3. Java學(xué)習(xí)源代碼檢索系統(tǒng)
難得看見國產(chǎn)的,好歹也要支持一下,分類也算清楚。
4. Koders
是個綜合查詢的網(wǎng)站,不過它好像是從代碼中查找關(guān)鍵詞,包含的語言挺多的。
5. Resources for Java server-side developers
確切的說,它是一個資源收集的網(wǎng)站,代碼查詢并不多。不過它分類相當(dāng)細,如Articles、Books、Examples、Extensions、Frameworks等類,你可以輸入Spring或Hibernate作為關(guān)鍵詞搜索一下看看。
-----
import?java.util.Scanner;
//看這樣的行嗎?
public?class?StoreCharge?{
public?static?void?main(String[]?args)?{
Scanner?sc?=?new?Scanner(System.in);
System.out.println("輸入應(yīng)付金額:");
double?x?=?sc.nextDouble();
Price?p1?=?ampayable(x);
System.out.println(p1.toString());
System.out.println("輸入實付金額:");
double?y?=?sc.nextDouble();
Price?p2?=?ampaid(y);
System.out.println(p2.toString());
System.out.println("找零:"+charge(p1,p2).toString());
charge(p1,p2);
}
public?static?Price?charge(Price?p1,Price?p2){//p1總貨價?p2收款
int?c,b;
if(p2.connerp1.conner){
b?=?p2.conner+10-p1.conner;
p2.element?=?p2.element-1;
}else
b?=?p2.conner-p1.conner;
c?=?p2.element?-?p1.element;
return?new?Price(c,b);????????
}
public?static?Price?ampayable(double?x){//應(yīng)付金額
Price?a?=?new?Price();
a.element?=?(int)x;
a.conner??=?(int)(x*10?-((int)x)*10);
return?a;
}
public?static?Price?ampaid(double?x){//實付金額
Price?a?=?new?Price();
a.element?=?(int)x;
a.conner??=?(int)(x*10?-((int)x)*10);
return?a;
}
}
class?Price{
int?element;//元
int?conner;//角
public?Price(){}
public?Price(int?e,int?c){
element?=?e;
conner?=?c;
}
public?String?toString(){
return?element+"元"+conner+"角";
}
}