算是最簡(jiǎn)單的吧
成都創(chuàng)新互聯(lián)是一家企業(yè)級(jí)云計(jì)算解決方案提供商,超15年IDC數(shù)據(jù)中心運(yùn)營(yíng)經(jīng)驗(yàn)。主營(yíng)GPU顯卡服務(wù)器,站群服務(wù)器,德陽(yáng)機(jī)房服務(wù)器托管,海外高防服務(wù)器,服務(wù)器機(jī)柜,動(dòng)態(tài)撥號(hào)VPS,海外云手機(jī),海外云服務(wù)器,海外服務(wù)器租用托管等。
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("購(gòu)物管理系統(tǒng)客戶(hù)信息");
System.out.println("1顯示所有客戶(hù)信息");
System.out.println("2添加客戶(hù)信息");
System.out.println("3修改客戶(hù)信息");
System.out.println("4查詢(xún)客戶(hù)信息");
}
static void choice2() {
System.out.println("購(gòu)物管理系統(tǒng)真情回饋");
System.out.println("1幸運(yùn)大放送");
System.out.println("2幸運(yùn)抽獎(jiǎng)");
System.out.println("3生日問(wèn)候");
}
public static void main(String[] args) {
choice();
Scanner input = new Scanner(System.in);
System.out.println("請(qǐng)輸入1or2");
int num = input.nextInt();
switch (num) {
case 1:
System.out.println("主菜單");
System.out.println("1客戶(hù)信息管理");
System.out.println("2購(gòu)物結(jié)算");
System.out.println("3真情回饋");
System.out.println("4注銷(xiāo)");
break;
}
System.out.println("選擇輸入數(shù)字");
int num1 = input.nextInt();
switch (num1) {
case 1:
choice1();
break;
case 2:
System.out.println("購(gòu)物結(jié)算");
break;
case 3:
choice2();
break;
case 4:
choice();
break;
}
}
}
有時(shí)間幫你搞個(gè)
import?java.util.Calendar;
import?java.util.Scanner;
/*
*?功能說(shuō)明,只能輸入1?2?或者3如果輸入其他就視為下訂單或者取消訂單
*/
public?class?ShoppingSystem?{
private?static?final?String?SPACE="????????";
private?int?count=1;
private?boolean?go?=true;
int[]?book_p?=new?int[3];
int[]?book_n?=?new?int[3];
private?book[]?books?=?{
new?book(1,?"Java教程",?30.6,?30),
new?book(2,?"JSP?指南",?42.1,?40),
new?book(3,?"SSH?架構(gòu)",?47.3,?15)
};
//圖書(shū)列表
public?void?booklist(){
System.out.println("圖書(shū)列表:");
System.out.println("圖書(shū)編號(hào)??圖書(shū)名稱(chēng)?????圖書(shū)單價(jià)?庫(kù)存數(shù)量");
System.out.println("-----------------------------------------");
for?(int?i?=?0;?i??books.length;?i++)?{
System.out.println(books[i].id+SPACE+books[i].name+SPACE+books[i].moneny+SPACE+books[i].number);
}
System.out.println("-----------------------------------------");
}
//購(gòu)買(mǎi)行為
public?void?buy(){
Scanner?in?=?new?Scanner(System.in);
try?{
int?chooses;?
while(go){
System.out.println("請(qǐng)輸入圖書(shū)的編號(hào)選擇圖書(shū)");
chooses?=?in.nextInt();
if(chooses?==?1?||?chooses?==?2?||?chooses?==?3){
}
else{?
buylist();
go?=false;
return;
}
if(chooses?==?1){
book_p[0]=1;
System.out.print("請(qǐng)輸入購(gòu)買(mǎi)圖書(shū)的數(shù)量?");
chooses?=?in.nextInt();
if(chooses?=?books[0].number){
book_n[0]=book_n[0]+chooses;
}
}else?if(chooses?==?2){
book_p[1]=1;
System.out.print("請(qǐng)輸入購(gòu)買(mǎi)圖書(shū)的數(shù)量?");
chooses?=?in.nextInt();
if(chooses?=?books[1].number){
book_n[1]=book_n[1]+chooses;
}
}else?if(chooses?==?3){
book_p[2]=1;
System.out.print("請(qǐng)輸入購(gòu)買(mǎi)圖書(shū)的數(shù)量?");
chooses?=?in.nextInt();
if(chooses?=?books[2].number){
book_n[2]=book_n[2]+chooses;
}
}????????????????????
}
}?catch?(Exception?e)?{
//?TODO:?handle?exception
}
}
//訂單列表
private?void?buylist(){
double?sum=0;
System.out.println(SPACE+"圖書(shū)訂單:");
System.out.println("圖書(shū)訂單號(hào):"+count);
System.out.println("圖書(shū)名稱(chēng)?購(gòu)買(mǎi)數(shù)量?圖書(shū)單價(jià)");
System.out.println("-------------------------------");
for?(int?i?=?0;?i??3;?i++)?{
if(book_p[i]?!=?0){
System.out.println(books[i].name?+?SPACE+book_n[i]+SPACE+books[i].moneny);
sum?=sum?+?book_n[i]*books[i].moneny;
}
}
System.out.println("-------------------------------");
System.out.print("訂單的總額???????????????????????");
System.out.println(sum);
Calendar?c?=?Calendar.getInstance();
System.out.println("日期"+c.getTime());
}
public?static?void?main(String[]?args)?{
ShoppingSystem?sh?=?new?ShoppingSystem();
sh.booklist();
sh.buy();
}
class?book{
private?int?id;
private?String?name;
private?double?moneny;
private?int?number;
public?book(int?id,?String?name,?double?moneny,?int?number)?{
this.id?=?id;
this.name?=?name;
this.moneny?=?moneny;
this.number?=?number;
}
public?int?getId()?{
return?id;
}
public?void?setId(int?id)?{
this.id?=?id;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?double?getMoneny()?{
return?moneny;
}
public?void?setMoneny(double?moneny)?{
this.moneny?=?moneny;
}
public?int?getNumber()?{
return?number;
}
public?void?setNumber(int?number)?{
this.number?=?number;
}
}
}
/**
*?書(shū)籍
*/
public?class?Book?{
private?String?name;?//書(shū)名
private?String?author;?//作者
private?String?publisher;?//出版社
private?Integer?price;?//價(jià)格,分為單位,不使用浮點(diǎn)數(shù)防止精度丟失
public?Book(String?name,?String?author,?String?publisher,?Integer?price)?{
this.name?=?name;
this.author?=?author;
this.publisher?=?publisher;
this.price?=?price;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?String?getAuthor()?{
return?author;
}
public?void?setAuthor(String?author)?{
this.author?=?author;
}
public?String?getPublisher()?{
return?publisher;
}
public?void?setPublisher(String?publisher)?{
this.publisher?=?publisher;
}
public?Integer?getPrice()?{
return?price;
}
public?void?setPrice(Integer?price)?{
this.price?=?price;
}
@Override
public?String?toString()?{
return?"Book{"?+
"name='"?+?name?+?'\''?+
",?author='"?+?author?+?'\''?+
",?publisher='"?+?publisher?+?'\''?+
",?price="?+?price?+
'}';
}
}
import?java.util.ArrayList;
import?java.util.List;
/**
*?購(gòu)物車(chē)
*?Created?by?admin?on?2016/5/17.
*/
public?class?Cart?{
ListBook?books?=?new?ArrayList();
/**
*?添加書(shū)籍
*
*?@param?book
*/
public?void?addBook(Book?book)?{
books.add(book);
}
/**
*?獲取book信息
*
*?@return
*/
public?String?getBookInfo()?{
return?books.toString();
}
/**
*?獲取book總價(jià)
*
*?@return
*/
public?Integer?getTotalPrice()?{
Integer?totalPrice?=?0;
if?(null?!=?books??books.size()??0)?{
for?(Book?book?:?books)?{
totalPrice?+=?book.getPrice();
}
}
return?totalPrice;
}
public?String?getTotalInfo()?{
return?"書(shū)籍信息:\r\n"?+?getBookInfo()?+?"\r\n"?+?"總價(jià)格:"?+?getYuanPrice(getTotalPrice())?+?"元";
}
/**
*?把分轉(zhuǎn)換成元
*
*?@param?price
*?@return
*/
public?static?String?getYuanPrice(Integer?price)?{
String?strPrice?=?String.valueOf(price);
while?(strPrice.length()??3)?{
strPrice?=?"0"?+?strPrice;
}
strPrice?=?strPrice.substring(0,?strPrice.length()?-?2)?+?"."?+?strPrice.substring(strPrice.length()?-?2);
return?strPrice;
}
public?static?void?main(String?args[])?{
Cart?cart?=?new?Cart();
cart.addBook(new?Book("書(shū)名",?"作者",?"出版社",?1245));
cart.addBook(new?Book("書(shū)名1",?"作者1",?"出版社1",?3458));
cart.addBook(new?Book("書(shū)名2",?"作者2",?"出版社2",?7859));
System.out.println(cart.getTotalInfo());
}
}
這是兩個(gè)類(lèi),分別放到Book.java?跟Cart.java兩個(gè)類(lèi)文件中,直接執(zhí)行Cart里的main方法就可以了
輸出如下:
就算是溫故知新吧。
我試著把你這兩個(gè)文件放在c:\jdk\test文件夾里,
然后先 javac Aaa.java 編譯成功.
然后再 javac Hello.java 編譯出錯(cuò):
Hello.java:1: 錯(cuò)誤: 程序包a不存在
import a.Aaa;
^
Hello.java:4: 錯(cuò)誤: 無(wú)法訪(fǎng)問(wèn)Aaa
Aaa a=new Aaa();
^
錯(cuò)誤的類(lèi)文件: .\Aaa.class
類(lèi)文件包含錯(cuò)誤的類(lèi): a.Aaa
請(qǐng)刪除該文件或確保該文件位于正確的類(lèi)路徑子目錄中。
2 個(gè)錯(cuò)誤
上面的提示,大概意思是說(shuō) Aaa.class的位置放錯(cuò)了。
我直接在dos下輸入: javac 查看語(yǔ)法
-d 目錄 指定放置生成的類(lèi)文件的位置
然后按上面這個(gè)提示,重新編譯一個(gè) Aaa.java文件
javac Aaa.java -d .
這個(gè)時(shí)候我發(fā)現(xiàn)新生成了一個(gè)a文件夾,里面存放的是 Aaa.class
然后我再編譯 javac Hello.java 編譯成功。
C:\jdk\testjava Hello
Hello!
java中的包其實(shí)你完全可以理解為“文件夾”。
一個(gè)包里有很多的類(lèi)文件,一個(gè)“文件夾”里存放著很多的類(lèi)文件。
希望對(duì)你能有所幫助。