请java高手进,帮忙解决一个很简单的问题。急急急急急
题目:用java编写,要完整的,详细的,能运行通过的代码,谢谢。某百货公司为了促销,采用购物打折的办法。(1)在1000元以上者,按九五折优惠;(2)在2000元以上者,...
题目:用java编写,要完整的,详细的,能运行通过的代码,谢谢。
某百货公司为了促销,采用购物打折的办法。
(1) 在1000元以上者,按九五折优惠;
(2) 在2000元以上者,按九折优惠;
(3) 在3000元以上者,按八五折优惠;
(4) 在5000元以上者,按八折优惠。
编写程序,输入购物款数,计算并输出优惠价。
补充下,不要控制台输出的那种,要建立新界面输入、输出的,谢谢。 展开
某百货公司为了促销,采用购物打折的办法。
(1) 在1000元以上者,按九五折优惠;
(2) 在2000元以上者,按九折优惠;
(3) 在3000元以上者,按八五折优惠;
(4) 在5000元以上者,按八折优惠。
编写程序,输入购物款数,计算并输出优惠价。
补充下,不要控制台输出的那种,要建立新界面输入、输出的,谢谢。 展开
13个回答
展开全部
图形界面的:
import javax.swing.JOptionPane;
public class Du {
public static void main(String[] args) {
String str = JOptionPane.showInputDialog("请输入购物款");
double money = Double.parseDouble(str);
if(money > 5000){
money = money * 0.8;
}else if(money > 3000){
money = money * 0.85;
}else if(money > 2000){
money = money * 0.9;
}else if(money > 1000) {
money = money * 0.95;
}
JOptionPane.showMessageDialog(null, "应该支付: " + money);
}
}
import javax.swing.JOptionPane;
public class Du {
public static void main(String[] args) {
String str = JOptionPane.showInputDialog("请输入购物款");
double money = Double.parseDouble(str);
if(money > 5000){
money = money * 0.8;
}else if(money > 3000){
money = money * 0.85;
}else if(money > 2000){
money = money * 0.9;
}else if(money > 1000) {
money = money * 0.95;
}
JOptionPane.showMessageDialog(null, "应该支付: " + money);
}
}
展开全部
import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
/*
* NewJFrame.java
*
* Created on 2011-6-22, 12:57:16
*/
/**
*
* @author 丁乔武
*/
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
private void initComponents() {
javax.swing.JPanel jPanel1 = new javax.swing.JPanel();
javax.swing.JPanel jPanel2 = new javax.swing.JPanel();
javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
txtCount = new javax.swing.JTextField();
javax.swing.JPanel jPanel3 = new javax.swing.JPanel();
javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
txtM = new javax.swing.JTextField();
javax.swing.JButton btnSub = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new java.awt.GridLayout(3, 1));
jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.LINE_AXIS));
jLabel1.setText("购物款数");
jPanel2.add(jLabel1);
jPanel2.add(txtCount);
jPanel1.add(jPanel2);
jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.LINE_AXIS));
jLabel2.setText("优 惠 价");
jPanel3.add(jLabel2);
jPanel3.add(txtM);
jPanel1.add(jPanel3);
btnSub.setText("计算");
btnSub.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSubActionPerformed(evt);
}
});
jPanel1.add(btnSub);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-282)/2, (screenSize.height-103)/2, 282, 103);
}
private void btnSubActionPerformed(java.awt.event.ActionEvent evt) {
String txtC = this.txtCount.getText();
int i = Integer.parseInt(txtC);
double b = 0;
if (i >= 1000) {
b = i * 0.95;
} else if (i >= 2000) {
b = i * 0.9;
} else if (i >= 3000) {
b = i * 0.85;
} else if (i >= 5000) {
b = i * 0.8;
}
this.txtM.setText(String.valueOf(b));
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
UIManager.setLookAndFeel(new NimbusLookAndFeel());
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField txtCount;
private javax.swing.JTextField txtM;
// End of variables declaration
}
下次麻烦说明要求
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
/*
* NewJFrame.java
*
* Created on 2011-6-22, 12:57:16
*/
/**
*
* @author 丁乔武
*/
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
private void initComponents() {
javax.swing.JPanel jPanel1 = new javax.swing.JPanel();
javax.swing.JPanel jPanel2 = new javax.swing.JPanel();
javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
txtCount = new javax.swing.JTextField();
javax.swing.JPanel jPanel3 = new javax.swing.JPanel();
javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
txtM = new javax.swing.JTextField();
javax.swing.JButton btnSub = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new java.awt.GridLayout(3, 1));
jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.LINE_AXIS));
jLabel1.setText("购物款数");
jPanel2.add(jLabel1);
jPanel2.add(txtCount);
jPanel1.add(jPanel2);
jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.LINE_AXIS));
jLabel2.setText("优 惠 价");
jPanel3.add(jLabel2);
jPanel3.add(txtM);
jPanel1.add(jPanel3);
btnSub.setText("计算");
btnSub.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSubActionPerformed(evt);
}
});
jPanel1.add(btnSub);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-282)/2, (screenSize.height-103)/2, 282, 103);
}
private void btnSubActionPerformed(java.awt.event.ActionEvent evt) {
String txtC = this.txtCount.getText();
int i = Integer.parseInt(txtC);
double b = 0;
if (i >= 1000) {
b = i * 0.95;
} else if (i >= 2000) {
b = i * 0.9;
} else if (i >= 3000) {
b = i * 0.85;
} else if (i >= 5000) {
b = i * 0.8;
}
this.txtM.setText(String.valueOf(b));
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
UIManager.setLookAndFeel(new NimbusLookAndFeel());
} catch (UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField txtCount;
private javax.swing.JTextField txtM;
// End of variables declaration
}
下次麻烦说明要求
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.text.DecimalFormat;
import javax.swing.*;
public class CountJFrame extends JFrame {
private static final long serialVersionUID = 6714526588714256018L;
private void init() {
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JLabel jLabel1 = new JLabel();
interCount = new JTextField();
JButton btnSub = new JButton();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new java.awt.GridLayout(2, 1));
jPanel2.setLayout(new BoxLayout(jPanel2, BoxLayout.LINE_AXIS));
jLabel1.setText("购物金额");
jPanel2.add(jLabel1);
jPanel2.add(interCount);
jPanel1.add(jPanel2);
btnSub.setText("结算");
btnSub.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
countMoney(evt);
}
});
jPanel1.add(btnSub);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-282)/2, (screenSize.height-103)/2, 450, 103);
this.setVisible(true);
}
private void countMoney(ActionEvent evt) {
double count = Double.parseDouble(this.interCount.getText());
double discount = 1.00;
if (count >= 5000) {
discount = 0.8;
}else if (count >= 3000) {
discount = 0.85;
} else if (count >= 2000) {
discount = 0.9;
}else if (count >= 1000) {
discount = 0.95;
}
DecimalFormat df=new DecimalFormat(".##");
count = count * discount ;
JOptionPane.showMessageDialog(null, "您的折扣为:"+discount+"\n应付金额为: " + df.format(count));
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
CountJFrame countJFrame = new CountJFrame();
countJFrame.init();
}
private JTextField interCount;
}
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.text.DecimalFormat;
import javax.swing.*;
public class CountJFrame extends JFrame {
private static final long serialVersionUID = 6714526588714256018L;
private void init() {
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JLabel jLabel1 = new JLabel();
interCount = new JTextField();
JButton btnSub = new JButton();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new java.awt.GridLayout(2, 1));
jPanel2.setLayout(new BoxLayout(jPanel2, BoxLayout.LINE_AXIS));
jLabel1.setText("购物金额");
jPanel2.add(jLabel1);
jPanel2.add(interCount);
jPanel1.add(jPanel2);
btnSub.setText("结算");
btnSub.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
countMoney(evt);
}
});
jPanel1.add(btnSub);
getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-282)/2, (screenSize.height-103)/2, 450, 103);
this.setVisible(true);
}
private void countMoney(ActionEvent evt) {
double count = Double.parseDouble(this.interCount.getText());
double discount = 1.00;
if (count >= 5000) {
discount = 0.8;
}else if (count >= 3000) {
discount = 0.85;
} else if (count >= 2000) {
discount = 0.9;
}else if (count >= 1000) {
discount = 0.95;
}
DecimalFormat df=new DecimalFormat(".##");
count = count * discount ;
JOptionPane.showMessageDialog(null, "您的折扣为:"+discount+"\n应付金额为: " + df.format(count));
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
CountJFrame countJFrame = new CountJFrame();
countJFrame.init();
}
private JTextField interCount;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
import java.util.Scanner;
public class market {
/**
* @by
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入价格");
int price = input.nextInt();
double dis =getDis(price);
System.out.print("折扣后的价格为"+price*dis);
}
//判断折扣类型
private static double getDis(int p){
double discode = 0;
if(p<2000&&p>1000){
discode=9.5;
}else if(p<3000&&p>2000){
discode=9.0;
}else if(p<5000&&p>3000){
discode=8.5;
}else if(p>5000){
discode=8.0;
}else{
discode=1.0;
}
return discode;
}
}
这样的话就可以实现了,楼上的都大同小异,其实也都这样就可以实现了。楼主接受咯。
public class market {
/**
* @by
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入价格");
int price = input.nextInt();
double dis =getDis(price);
System.out.print("折扣后的价格为"+price*dis);
}
//判断折扣类型
private static double getDis(int p){
double discode = 0;
if(p<2000&&p>1000){
discode=9.5;
}else if(p<3000&&p>2000){
discode=9.0;
}else if(p<5000&&p>3000){
discode=8.5;
}else if(p>5000){
discode=8.0;
}else{
discode=1.0;
}
return discode;
}
}
这样的话就可以实现了,楼上的都大同小异,其实也都这样就可以实现了。楼主接受咯。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
double sum;(消费金额)
if(sum>=1000 && sum < 2000){sum = sum*0.95;return sum;}
else if (sum >=2000 && sum < 3000){sum = sum*0.9;return sum;}
else if (sum >=3000 && sum < 5000){sum = sum*0.85;return sum;}
else if (sum >=2000 && sum < 3000){sum = sum*0.8;return sum;}
else {return sum;}
if(sum>=1000 && sum < 2000){sum = sum*0.95;return sum;}
else if (sum >=2000 && sum < 3000){sum = sum*0.9;return sum;}
else if (sum >=3000 && sum < 5000){sum = sum*0.85;return sum;}
else if (sum >=2000 && sum < 3000){sum = sum*0.8;return sum;}
else {return sum;}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int a;
int b;
b=a;
if(a>=1000)
b=a*0.95;
if(a>=2000)
b=a*0.9;
if(a>=3000)
b=a*0.85;
if(a>=5000)
b=a*0.8;
int b;
b=a;
if(a>=1000)
b=a*0.95;
if(a>=2000)
b=a*0.9;
if(a>=3000)
b=a*0.85;
if(a>=5000)
b=a*0.8;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询