import java.awt.BorderLayout;
10多年专注成都网站制作,企业网站设计,个人网站制作服务,为大家分享网站制作知识、方案,网站设计流程、步骤,成功服务上千家企业。为您提供网站建设,网站制作,网页设计及定制高端网站建设服务,专注于企业网站设计,高端网页制作,对纸箱等多个领域,拥有多年建站经验。
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;
public class TestFrame extends javax.swing.JFrame {
private JScrollPane jScrollPane1;
private JTable jTable1;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
TestFrame inst = new TestFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public TestFrame() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
{
jScrollPane1 = new JScrollPane();
getContentPane().add(jScrollPane1, BorderLayout.CENTER);
{
TableModel jTable1Model =
new DefaultTableModel(
new String[][] { {"","",""},{} ,{} ,{} },
new String[] { "上网总时间", "上网花费金额" ,"上网单价"});
jTable1 = new JTable();
jScrollPane1.setViewportView(jTable1);
jTable1.setModel(jTable1Model);
}
}
pack();
setSize(400, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
enum Huo {
TX(1, "T恤", 245), WQX(2, "网球鞋", 570), WQP(3, "网球拍", 320);
private int id;
private String name;
private double price;
private Huo(int id, String name, double price) {
this.id = id;
this.name = name;
this.price = price;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
public static Huo getById(int id) {
for (Huo item : Huo.values()) {
if (item.id == id) {
return item;
}
}
return null;
}
}
public class Test {
private static MapInteger, Integer countMap = new HashMapInteger, Integer();
private static double sum = 0;
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
while (true) {
System.out.println("**********************************************");
System.out.println("请选择购买的商品编号:");
for (Huo item : Huo.values()) {
System.out.print(item.getId() + ":" + item.getName() + " ");
}
System.out.println();
System.out.println("**********************************************");
System.out.print("输入购买商品编号:");
int id = in.nextInt();
System.out.print("输入购买商品数量:");
int count = in.nextInt();
Integer tmp = countMap.get(id);
if (tmp == null) {
tmp = 0;
}
countMap.put(id, tmp + count);
show();
while (true) {
System.out.print("是否继续(y/n):");
String jixu = in.next();
if ("Y".equalsIgnoreCase(jixu)) {
break;
} else if ("N".equalsIgnoreCase(jixu)) {
System.out.print("请支付:");
double zhifu = in.nextDouble();
System.out.println("应付金额:" + sum);
System.out.println("客户支付:" + zhifu);
System.out.println("找钱:" + (zhifu - sum));
System.exit(0);
} else {
System.out.print("输入错误");
}
}
}
}
private static void show() {
IteratorInteger it = countMap.keySet().iterator();
while (it.hasNext()) {
Integer key = it.next();
Integer count = countMap.get(key);
Huo huo = Huo.getById(key);
double heji = huo.getPrice() * count;
System.out.println(huo.getName() + "¥" + huo.getPrice() + " 数量:" + count + " 合计:" + heji);
sum += heji;
}
}
}
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = "";
while(true) {
System.out.println("请输入一个字符:");
str = sc.nextLine();
if(str=="exit") // 如果字符串为"exit",退出循环
break;
if(str.length()==1) {
char c = str.charAt(0);
System.out.println("它对应的ASCII码为:" + (int)c); //(int)c将c强制转换为它的ascii码
}
else
System.out.println("请输入一位字符。");
}
sc.close();
}
}
import java.util.Scanner;
public class JieZhang {
public static void main(String[] args) {
System.out.println("请输入要结账的顾客数:");
Scanner s = new Scanner(System.in);
int num = s.nextInt();
for(int i=0;inum;i++){
int flag = 1;
double sum = 0;//总价
while(flag==1){
flag = 1;
System.out.println("请输入单价:");
double price = s.nextDouble();
System.out.println("请输入数量:");
int number = s.nextInt();
sum = sum + price * number;
System.out.println("请选择是否继续计算:1继续");
flag = s.nextInt();
}
System.out.println("第"+(i+1)+"位顾客消费:"+sum);
}
}
}
刚帮你调测了一下,当你输入"n"的时候,已经跳出循环了,只不过你没有输出提示,以为没出来,
又输入字符了所有报错了,应该是输入金额的,我帮你加了下输出你可以看下结果;
public static void main(String args[]){
System.out.println("********************");
System.out.println("");
System.out.println("请选择购买商品编号:");
System.out.println("1.T恤(¥245.0) 网球鞋(¥570.0) 网球拍(¥500.0)");
System.out.println("********************");
System.out.println("");
double s=0;
String d;
do{
System.out.println("请输入商品编号:");
Scanner input=new Scanner(System.in);
int a=input.nextInt();
if(a==1){
System.out.println("请输入购买数量:");
int b=input.nextInt();
double c=245*b;
System.out.println("T恤¥245.0 数量:"+b+" "+"合计:"+c);
s=s+c;
}
else if(a==2){
System.out.println("请输入购买数量:");
int b=input.nextInt();
double c=570*b;
System.out.println("网球鞋¥245.0 数量:"+b+" "+"合计:"+c);
s=s+c;
}
else if(a==3){
System.out.println("请输入购买数量:");
int b=input.nextInt();
double c=500*b;
System.out.println("网球拍¥245.0 数量:"+b+" "+"合计:"+c);
s=s+c;
}
else {System.out.println("无此商品");}
System.out.println("否继续(y/n)");
d=input.next();
}while(d.equals("y"));
System.out.println("===========付款===========");
System.out.println("=====输入金额=====");
Scanner input=new Scanner(System.in);
int x=input.nextInt();
double m=s*0.8;
System.out.println("折扣:0.8");
System.out.println("应付金额:"+m);
System.out.println("实际金额:"+x);
double p=x-m;
System.out.println("找钱:"+p);
}