public class Shop
{
private String coffee="咖啡做早厅"
private String coke="可乐"
private String tea="茶"
private double coffeeprice=2.00
private double cokeprice=3.00
private double teaprice=5
private double price=0.0
public Shop()
{
}
public void getName(int i)
{
if(i==1)
{
System.out.println("你选择的是咖啡")
}
if(i==2)
{
System.out.println("你纯隐选择的是可乐")
}
if(i==3)
{
System.out.println("你选择的是茶")
}
}
public double getShopping(int i,double p)
{
if(i==1)
{
if(p<coffeeprice)
{
System.out.println("您的钱不够买此商品")
}
else
{
price=p-coffeeprice
}
}
if(i==2)
{
if(p<cokeprice)
{
System.out.println("您的钱不够买此商品")
}
else
{
price=p-cokeprice
}
}
if(i==3)
{
if(p<teaprice)
{
System.out.println("您的钱不够买此商品")
}
else
{
price=p-teaprice
}
}
return price
}
public static void main(String[] args)
{
Shop shop=new Shop()
try
{
System.out.println("请选择你睁缓想要的商品\n 1.咖啡 2.可乐 3.茶")
Scanner si=new Scanner(System.in)
int i=si.nextInt()
System.out.println(" ")
if(i>3||i<1)
{
System.out.println("没有此产品")
}
else
{
shop.getName(i)
System.out.println(" ")
System.out.print("请付账:")
Scanner sp=new Scanner(System.in)
double p=sp.nextDouble()
System.out.println(" ")
if(shop.getShopping(i,p)!=0.0)
{
System.out.println("找你的钱:"+shop.getShopping(i,p))
}
}
}
catch(Exception ex)
{
System.out.println("请正确输入!")
}
}
}
importjava.util.Scanner\x0d\x0a\x0d\x0apublicclassShop\x0d\x0a{\x0d\x0aprivateStringcoffee="咖啡"\x0d\x0aprivateStringcoke="可乐"\x0d\x0aprivateStringtea="茶"\x0d\x0aprivatedoublecoffeeprice=2.00\x0d\x0aprivatedoublecokeprice=3.00\x0d\x0aprivatedoubleteaprice=5\x0d\x0aprivatedoubleprice=0.0\x0d\x0apublicShop()\x0d\x0a{\x0d\x0a}\x0d\x0apublicvoidgetName(inti)\x0d\x0a{\x0d\x0aif(i==1)\x0d\x0a{\x0d\x0aSystem.out.println("你选择的是咖啡")\x0d\x0a}\x0d\x0a\x0d\x0aif(i==2)\x0d\x0a{\x0d\x0aSystem.out.println("你选择的是岩喊可乐")\x0d\x0a}\x0d\x0a\x0d\x0aif(i==3)\x0d\x0a{\x0d\x0aSystem.out.println("你选择的是茶")\x0d\x0a}\x0d\x0a}\x0d\x0apublicdoublegetShopping(inti,doublep)\x0d\x0a{\x0d\x0aif(i==1)\x0d\x0a{\x0d\x0aif(p欢迎分享,转载请注明来源:内存溢出
评论列表(0条)