重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
算是最简单的吧
成都创新互联主要从事做网站、网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务武冈,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108
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;
}
}
}
不是很理解你的问题,你是想问为什么返回的Phone是匿名么?
因为不需要名称啊,你也可以写成这样:
public Phone sellPhone(){
Phone p = new Phone("iPhone", 6000);
return p;
}
效果完全相同的
下附代码,可以在键盘输入加入判断,比如是否输入的是数字而不是字母等等,是否输入的是正数而不是其他符号... 另外可以将下面代码优化,封装,在main方法只做调用即可
package test;
import java.util.Scanner;
public class test {
public static void main(String[] args) {
boolean flag = true;
while(flag){
System.out.println("欢迎使用自动饮料售卖机");
System.out.println("1.雪碧 3.00");
System.out.println("2.可乐 3.00");
System.out.println("3.特仑苏 5.00");
System.out.println("4.农夫山泉 2.00");
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
System.out.print("请输入你的选择是:");
int choise = input.nextInt();
System.out.print("请投币:");
int money = input.nextInt();
money(money, choise);
System.out.print("是否继续'1.继续 0.退出' :");
int goon = input.nextInt();
if(goon==1){
flag = true;
}else{
flag = false;
}
}
}
public static void money(int money,int choise){
switch(choise){
case 1:
if(money-30){
System.out.println("找零"+(money-3)+"元");
}else if(money-30){
System.out.println("请再投入"+(3-money)+"元");
}else if(money-3==0){
System.out.println("生活愉快");
}else{
System.out.println("输入有误!");
}
break ;
case 2:
if(money-30){
System.out.println("找零"+(money-3)+"元");
}else if(money-30){
System.out.println("请再投入"+(3-money)+"元");
}else if(money-3==0){
System.out.println("生活愉快");
}else{
System.out.println("输入有误!");
}
break ;
case 3:
if(money-50){
System.out.println("找零"+(money-5)+"元");
}else if(money-50){
System.out.println("请再投入"+(5-money)+"元");
}else if(money-5==0){
System.out.println("生活愉快");
}else{
System.out.println("输入有误!");
}
break ;
case 4:
if(money-20){
System.out.println("找零"+(money-2)+"元");
}else if(money-20){
System.out.println("请再投入"+(2-money)+"元");
}else if(money-2==0){
System.out.println("生活愉快");
}else{
System.out.println("输入有误!");
}
break ;
}
}
}
平时在线10k人大概是让你创建一个数据库连接池,大小设置10k。
下面是一个图书商城的数据库表部分,供你参考
set utf8
DROP TABLE IF EXISTS d_product;
CREATE TABLE d_product (//用来存放总商品,入图书种类
id int(12) NOT NULL auto_increment,
product_name varchar(100) NOT NULL,
description varchar(100) default NULL,
add_time bigint(20) default NULL,
fixed_price double NOT NULL,
dang_price double NOT NULL,
keywords varchar(200) default NULL,
has_deleted int(1) NOT NULL default '0',
product_pic varchar(200) default NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO d_product VALUES (23,'上课睡觉的故事','上课睡觉的故事',1237873000234,200,180,'key',0,'15.jpg');
DROP TABLE IF EXISTS d_book;
CREATE TABLE d_book (//用来存放图书的具体内容
id int(12) NOT NULL,
author varchar(200) NOT NULL,
publishing varchar(200) NOT NULL,
publish_time bigint(20) NOT NULL,
word_number varchar(15) default NULL,
which_edtion varchar(15) default NULL,
total_page varchar(15) default NULL,
print_time int(20) default NULL,
print_number varchar(15) default NULL,
isbn varchar(25) default NULL,
author_summary text NOT NULL,
catalogue text NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO d_book VALUES (24,'阿斗,'地球出版社',1237873000234,'1万','1','100',1,NULL,'12345678','无描述,'好书!');
DROP TABLE IF EXISTS d_category;
CREATE TABLE d_category (//商城图书目录
id int(12) NOT NULL auto_increment,
turn int(10) NOT NULL,
en_name varchar(200) NOT NULL,
name varchar(200) NOT NULL,
description varchar(200),
parent_id int(10),
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO d_category VALUES (1,1,'Book','图书',NULL,0);
DROP TABLE IF EXISTS d_category_product;
CREATE TABLE d_category_product (//这个是连接目录和书籍具体信息的表
id int(12) NOT NULL auto_increment,
product_id int(10) NOT NULL,
cat_id int(10) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO d_category_product VALUES (72,24,1);
DROP TABLE IF EXISTS d_item;
CREATE TABLE d_item (//这个订单条目表
id int(12) NOT NULL auto_increment,
order_id int(10) NOT NULL,
product_id int(10) NOT NULL,
product_name varchar(100) NOT NULL,
dang_price double NOT NULL,
product_num int(10) NOT NULL,
amount double NOT NULL,
PRIMARY KEY (id)
)
DROP TABLE IF EXISTS d_order;
CREATE TABLE d_order (//订单表
id int(10) NOT NULL auto_increment,
user_id int(10) NOT NULL,
status int(10) NOT NULL,
order_time bigint(20) NOT NULL,
order_desc varchar(100) default NULL,
total_price double NOT NULL,
receive_name varchar(100) default NULL,
full_address varchar(200) default NULL,
postal_code varchar(8) default NULL,
mobile varchar(20) default NULL,
phone varchar(20) default NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB;
DROP TABLE IF EXISTS d_receive_address;
CREATE TABLE d_receive_address (//收件人信息表
id int(12) NOT NULL auto_increment,
user_id int(11) NOT NULL,
receive_name varchar(20) NOT NULL,
full_address varchar(200) NOT NULL,
postal_code varchar(8) NOT NULL,
mobile varchar(15) default NULL,
phone varchar(20) default NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB;
insert into d_receive_address values(1, 6,'Java','sun.cn','10000800','12345','67890');
insert into d_receive_address values(2, 6,'JavaJavaJava','ibm.cn','10000600','12345','67890');
DROP TABLE IF EXISTS d_user;
CREATE TABLE d_user (//用户表,用户信息
id int(12) NOT NULL auto_increment,
email varchar(50) NOT NULL,
nickname varchar(50) default NULL,
password varchar(50) NOT NULL,
user_integral int(12) NOT NULL default '0',
is_email_verify char(3),
email_verify_code varchar(50) default NULL,
last_login_time bigint default NULL,
last_login_ip varchar(15) default NULL,
PRIMARY KEY (id),
UNIQUE KEY email (email)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
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¥
//Example类文件Example.java
package cn.zhouhan;
import java.util.Scanner;
public class Example {
static Drink cola, fanta, blacktea, greentea;
static int money;
public static void main(String[] args) {
// TODO Auto-generated method stub
cola = new Drink("可乐", 50, 2.0, 1);
fanta = new Drink("芬达", 40, 3.0, 2);
blacktea = new Drink("红茶", 30, 4.0, 3);
greentea = new Drink("绿茶", 20, 5.0, 4);
money = 500;
for(;;)
{
System.out.println("-------------自动售货机-------------");
cola.UserPrintDrinkInfo();
fanta.UserPrintDrinkInfo();
blacktea.UserPrintDrinkInfo();
greentea.UserPrintDrinkInfo();
System.out.println("----------------------------------");
System.out.println("1.购买饮料");
System.out.println("2.管理员查询");
System.out.println("3.返回");
System.out.println("请输入要执行的操作序号:");
Scanner scannerIndex = new Scanner(System.in);
int indexScanner = scannerIndex.nextInt();
switch(indexScanner)
{
case 1:
System.out.println("请选择购买的饮料(1.可乐,2.芬达,3红茶,4.绿茶):");
Scanner numberScanner = new Scanner(System.in);
int buyIndex = numberScanner.nextInt();
Drink drink = getDrink(buyIndex);
System.out.println("请输入购买的数量:");
Scanner countScanner = new Scanner(System.in);
int buyCount = countScanner.nextInt();
if (buyCount 0)
{
System.out.println("您选择了" + buyCount + "瓶" + drink.getName() + "." );
System.out.println("总价格:" + drink.getPrice() * buyCount + "元,请投入1元或5元纸币。");
System.out.println("确定购买?(1.确定,2.退款):");
Scanner sureScanner = new Scanner(System.in);
int sure = sureScanner.nextInt();
if (sure == 1)
{
drink.sellDrink(buyCount);
money += drink.getPrice() * buyCount;
System.out.println("您购买了" + buyCount + "瓶" + drink.getName() + ",交易成功." );
}
if (sure ==2 )
{
System.out.println("退款成功!");
}
}
else
System.out.println("输入的数量有误!");
break;
case 2:
System.out.println("请输入管理员密码:");
Scanner pwScanner = new Scanner(System.in);
int password = pwScanner.nextInt();
if (password == 123)
{
System.out.println("密码正确,目前的余额为:" + money + "元。");
}
else
System.out.println("密码错误。");
break;
case 3:
break;
default:
System.out.println("请输入正确的数字。");
break;
}
}
}
public static Drink getDrink(int drinkIndex)
{
Drink drink = null;
switch(drinkIndex)
{
case 1:
drink = cola;
System.out.println("您选择了可乐。");
break;
case 2:
drink = fanta;
System.out.println("您选择了芬达。");
break;
case 3:
drink = blacktea;
System.out.println("您选择了红茶。");
break;
case 4:
drink = greentea;
System.out.println("您选择了绿茶。");
break;
default:
//drink = null;
System.out.println("输入错误,请输入1~4的数字!");
}
return drink;
}
}
//创建的Drink类文件Drink.java
package cn.zhouhan;
public class Drink {
private String name;
private int number;
private double price;
private double drinkMoney;
private int index;
public Drink(String name, int number, double price, int index)
{
this.name = name;
this.number = number;
this.price = price;
this.drinkMoney = number * price;
this.index = index;
}
public String getName()
{
return this.name;
}
public int getNumber()
{
return this.number;
}
public double getPrice()
{
return this.price;
}
public void sellDrink(int count)
{
this.number -= count;
this.drinkMoney += this.price * count;
}
public void UserPrintDrinkInfo()
{
System.out.println("品名:"+ this.name +",单价:" + this.price + "元,剩余数量:" + this.number + "瓶。");
}
}