十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
算是最简单的吧
成都创新互联是一家企业级云计算解决方案提供商,超15年IDC数据中心运营经验。主营GPU显卡服务器,站群服务器,德阳机房服务器托管,海外高防服务器,服务器机柜,动态拨号VPS,海外云手机,海外云服务器,海外服务器租用托管等。
package cn.job01;
import java.util.Scanner;
public class Lx07 {
public static void choice() {
System.out.println("登陆菜单 ");
System.out.println("1登陆系统");
System.out.println("2退出");
}
static void choice1() {
System.out.println("购物管理系统客户信息");
System.out.println("1显示所有客户信息");
System.out.println("2添加客户信息");
System.out.println("3修改客户信息");
System.out.println("4查询客户信息");
}
static void choice2() {
System.out.println("购物管理系统真情回馈");
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购物结算");
System.out.println("3真情回馈");
System.out.println("4注销");
break;
}
System.out.println("选择输入数字");
int num1 = input.nextInt();
switch (num1) {
case 1:
choice1();
break;
case 2:
System.out.println("购物结算");
break;
case 3:
choice2();
break;
case 4:
choice();
break;
}
}
}
有时间帮你搞个
import java.util.Calendar;
import java.util.Scanner;
/*
* 功能说明,只能输入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 架构", 47.3, 15)
};
//图书列表
public void booklist(){
System.out.println("图书列表:");
System.out.println("图书编号 图书名称 图书单价 库存数量");
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("-----------------------------------------");
}
//购买行为
public void buy(){
Scanner in = new Scanner(System.in);
try {
int chooses;
while(go){
System.out.println("请输入图书的编号选择图书");
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("请输入购买图书的数量 ");
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("请输入购买图书的数量 ");
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("请输入购买图书的数量 ");
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+"图书订单:");
System.out.println("图书订单号:"+count);
System.out.println("图书名称 购买数量 图书单价");
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;
}
}
}
/**
* 书籍
*/
public class Book {
private String name; //书名
private String author; //作者
private String publisher; //出版社
private Integer price; //价格,分为单位,不使用浮点数防止精度丢失
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;
/**
* 购物车
* Created by admin on 2016/5/17.
*/
public class Cart {
ListBook books = new ArrayList();
/**
* 添加书籍
*
* @param book
*/
public void addBook(Book book) {
books.add(book);
}
/**
* 获取book信息
*
* @return
*/
public String getBookInfo() {
return books.toString();
}
/**
* 获取book总价
*
* @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 "书籍信息:\r\n" + getBookInfo() + "\r\n" + "总价格:" + getYuanPrice(getTotalPrice()) + "元";
}
/**
* 把分转换成元
*
* @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("书名", "作者", "出版社", 1245));
cart.addBook(new Book("书名1", "作者1", "出版社1", 3458));
cart.addBook(new Book("书名2", "作者2", "出版社2", 7859));
System.out.println(cart.getTotalInfo());
}
}
这是两个类,分别放到Book.java 跟Cart.java两个类文件中,直接执行Cart里的main方法就可以了
输出如下:
就算是温故知新吧。
我试着把你这两个文件放在c:\jdk\test文件夹里,
然后先 javac Aaa.java 编译成功.
然后再 javac Hello.java 编译出错:
Hello.java:1: 错误: 程序包a不存在
import a.Aaa;
^
Hello.java:4: 错误: 无法访问Aaa
Aaa a=new Aaa();
^
错误的类文件: .\Aaa.class
类文件包含错误的类: a.Aaa
请删除该文件或确保该文件位于正确的类路径子目录中。
2 个错误
上面的提示,大概意思是说 Aaa.class的位置放错了。
我直接在dos下输入: javac 查看语法
-d 目录 指定放置生成的类文件的位置
然后按上面这个提示,重新编译一个 Aaa.java文件
javac Aaa.java -d .
这个时候我发现新生成了一个a文件夹,里面存放的是 Aaa.class
然后我再编译 javac Hello.java 编译成功。
C:\jdk\testjava Hello
Hello!
java中的包其实你完全可以理解为“文件夹”。
一个包里有很多的类文件,一个“文件夹”里存放着很多的类文件。
希望对你能有所帮助。