}
} // end anonymous inner class
);
// set up displayJTextField
displayJTextArea = new JTextArea();
displayJTextArea.setBounds( 10, 237,515, 70 );
displayJTextArea.setEditable( false );
contentPane.add( displayJTextArea );
// set properties of application's window
setTitle( "My car Shop" ); // set title bar string
setSize( 550, 360 );// set window size
setVisible( true );// display window
} // end method createUserInterface
private void clearJButtonActionPerformed( ActionEvent event )
{
// clear the JTextFields
inputJTextField2.setText( "" );
displayJTextArea.setText("");
} // end method clearJButtonActionPerformed
private void enterJButtonActionPerformed( ActionEvent event )
{
double z;
double c;
int x;
int y;
x=selectCountryJComboBox.getSelectedIndex();
y=Integer.parseInt(inputJTextField2.getText());
double discountRate;
int amount = Integer.parseInt( inputJTextField2.getText());
switch (amount/5)
{
case 0:
discountRate = 0;
break;
case 1:
discountRate = 1;
break;
case 2:
discountRate = 2;
break;
case 3:
discountRate = 3;
break;
default:
discountRate = 4;
} // end switch statement
c=1-discountRate/100;
z=jiage[x]*y*c;
displayJTextArea.append("你选择的是:"+cars[x]+";"+
"它的单价是:"+jiage[x]+";" +"你购买该产品的数量是:"+y+"," +"\n"+"该数量的折扣是:"
+discountRate + " %"+";"+"本次消费的总价格是:"+z+"元"+"!"+"\n");
}
public static void main( String args[] )
{
carshop application = new carshop();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
} // end method main
} // end class carshop
求一个随机出题的小程序 用java语言编写package ccut.lxn.BaiduKnows;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Random;
public class RandomQuestion {
public static void main(String[] args) {
Random random = new Random();// 声明实例化一个random对象 。
int a = random.nextInt(50);// 随机出现0-50间的数字 。
int b = random.nextInt(50);
boolean flag = random.nextBoolean();
if (flag) {
System.out.print(a + " + " + b + " = ");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));// 从键盘上输入字符
try {// 抛出异常
String str = br.readLine();// 按字符串接收,接收键盘上输入的字符
if (str.matches("\\d+")) {// 正则表达式,为了当你输入除整数外的其他字符时,报错 。
int result = Integer.parseInt(str);// 把输入的字符串转成int型
if (result == a + b) {
System.out.println("right");
} else {
System.out.println("error");
}
} else {
System.out.println("请输入数字!");
}
} catch (Exception e) {
System.out.println("出现错误:-----" + e.toString());
}
} else {
System.out.print(a + " - " + b + " = ");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));// 从键盘上输入字符
try {// 抛出异常
String str = br.readLine();// 按字符串接收,接收键盘上输入的字符
if (str.matches("\\d+")) {// 正则表达式,为了当你输入除整数外的其他字符时,报错 。
int result = Integer.parseInt(str);// 把输入的字符串转成int型
if (result == a - b) {
System.out.println("right");
} else {
System.out.println("error");
}
} else {
System.out.println("请输入数字!");
}
} catch (Exception e) {
System.out.println("出现错误:-----" + e.toString());
}
推荐阅读
- 久久小说下载网,全本小说免费大全app下载
- flutter引入安卓sdk,flutter支持平台
- 4s店新媒体发展趋势如何,汽车新媒体营销
- 视频号直播广场,视频号直播广场是什么意思
- linux7看网卡命令 linux看网卡配置命令
- 包含python怎么缩写3个公式的词条
- java中关联源代码,java 关联
- 直播卖商品技巧,直播卖商品诀窍
- go语言运动力 go语言运行原理