import java.awt.BorderLayout;
10多年專注成都網(wǎng)站制作,企業(yè)網(wǎng)站設(shè)計(jì),個(gè)人網(wǎng)站制作服務(wù),為大家分享網(wǎng)站制作知識(shí)、方案,網(wǎng)站設(shè)計(jì)流程、步驟,成功服務(wù)上千家企業(yè)。為您提供網(wǎng)站建設(shè),網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì)及定制高端網(wǎng)站建設(shè)服務(wù),專注于企業(yè)網(wǎng)站設(shè)計(jì),高端網(wǎng)頁(yè)制作,對(duì)紙箱等多個(gè)領(lǐng)域,擁有多年建站經(jīng)驗(yàn)。
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[] { "上網(wǎng)總時(shí)間", "上網(wǎng)花費(fèi)金額" ,"上網(wǎng)單價(jià)"});
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,?"網(wǎng)球鞋",?570),?WQP(3,?"網(wǎng)球拍",?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("請(qǐng)選擇購(gòu)買的商品編號(hào):");
for?(Huo?item?:?Huo.values())?{
System.out.print(item.getId()?+?":"?+?item.getName()?+?"??");
}
System.out.println();
System.out.println("**********************************************");
System.out.print("輸入購(gòu)買商品編號(hào):");
int?id?=?in.nextInt();
System.out.print("輸入購(gòu)買商品數(shù)量:");
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("是否繼續(xù)(y/n):");
String?jixu?=?in.next();
if?("Y".equalsIgnoreCase(jixu))?{
break;
}?else?if?("N".equalsIgnoreCase(jixu))?{
System.out.print("請(qǐng)支付:");
double?zhifu?=?in.nextDouble();
System.out.println("應(yīng)付金額:"?+?sum);
System.out.println("客戶支付:"?+?zhifu);
System.out.println("找錢:"?+?(zhifu?-?sum));
System.exit(0);
}?else?{
System.out.print("輸入錯(cuò)誤");
}
}
}
}
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()?+?"???數(shù)量:"?+?count?+?"????合計(jì):"?+?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("請(qǐng)輸入一個(gè)字符:");
str = sc.nextLine();
if(str=="exit") // 如果字符串為"exit",退出循環(huán)
break;
if(str.length()==1) {
char c = str.charAt(0);
System.out.println("它對(duì)應(yīng)的ASCII碼為:" + (int)c); //(int)c將c強(qiáng)制轉(zhuǎn)換為它的ascii碼
}
else
System.out.println("請(qǐng)輸入一位字符。");
}
sc.close();
}
}
import?java.util.Scanner;
public?class?JieZhang?{
public?static?void?main(String[]?args)?{
System.out.println("請(qǐng)輸入要結(jié)賬的顧客數(shù):");
Scanner?s?=?new?Scanner(System.in);
int?num?=?s.nextInt();
for(int?i=0;inum;i++){
int?flag?=?1;
double?sum?=?0;//總價(jià)
while(flag==1){
flag?=?1;
System.out.println("請(qǐng)輸入單價(jià):");
double?price?=?s.nextDouble();
System.out.println("請(qǐng)輸入數(shù)量:");
int?number?=?s.nextInt();
sum?=?sum?+?price?*?number;
System.out.println("請(qǐng)選擇是否繼續(xù)計(jì)算:1繼續(xù)");
flag?=?s.nextInt();
}
System.out.println("第"+(i+1)+"位顧客消費(fèi):"+sum);
}
}
}
剛幫你調(diào)測(cè)了一下,當(dāng)你輸入"n"的時(shí)候,已經(jīng)跳出循環(huán)了,只不過(guò)你沒(méi)有輸出提示,以為沒(méi)出來(lái),
又輸入字符了所有報(bào)錯(cuò)了,應(yīng)該是輸入金額的,我?guī)湍慵恿讼螺敵瞿憧梢钥聪陆Y(jié)果;
public static void main(String args[]){
System.out.println("********************");
System.out.println("");
System.out.println("請(qǐng)選擇購(gòu)買商品編號(hào):");
System.out.println("1.T恤(¥245.0) 網(wǎng)球鞋(¥570.0) 網(wǎng)球拍(¥500.0)");
System.out.println("********************");
System.out.println("");
double s=0;
String d;
do{
System.out.println("請(qǐng)輸入商品編號(hào):");
Scanner input=new Scanner(System.in);
int a=input.nextInt();
if(a==1){
System.out.println("請(qǐng)輸入購(gòu)買數(shù)量:");
int b=input.nextInt();
double c=245*b;
System.out.println("T恤¥245.0 數(shù)量:"+b+" "+"合計(jì):"+c);
s=s+c;
}
else if(a==2){
System.out.println("請(qǐng)輸入購(gòu)買數(shù)量:");
int b=input.nextInt();
double c=570*b;
System.out.println("網(wǎng)球鞋¥245.0 數(shù)量:"+b+" "+"合計(jì):"+c);
s=s+c;
}
else if(a==3){
System.out.println("請(qǐng)輸入購(gòu)買數(shù)量:");
int b=input.nextInt();
double c=500*b;
System.out.println("網(wǎng)球拍¥245.0 數(shù)量:"+b+" "+"合計(jì):"+c);
s=s+c;
}
else {System.out.println("無(wú)此商品");}
System.out.println("否繼續(xù)(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("應(yīng)付金額:"+m);
System.out.println("實(shí)際金額:"+x);
double p=x-m;
System.out.println("找錢:"+p);
}