我必须为我的编程课程制作一个项目。这是我的代码

时间:2015-11-21 08:02:52

标签: java joptionpane degrees

public class Project1{

    public static void main(String[] args)

    int noOfPhotocopy;
    float totalprice;

    String customer's_name;
    customer's_name = JOptionPane.showInputDialog("Enter customer's name: ");

    String type;
    type = JOptionPane.showInputDialog("Choose type of photocopy: G/C");

    if (type==G){
    noOfPhotocopy = JOptionPane.showInputDialog("Enter no of photocopy: ");

    if (noOfPhotocopy<10){
    totalprice = noOfPhotocopy * 0.10;
    JOptionPane.showMessageDialog(null, "Total price is RM" +totalprice);
    } else if(noOfPhotocopy>=10) {
    totalprice = noOfPhotocopy * 0.05;
    JOptionPane.showMessageDialog(null, "Total price is RM" +totalprice);
    }

    else if (type==C){
    noOfPhotocopy = JOptionPane.showInputDialog("Enter no of photocopy: ");

    if (noOfPhotocopy<10){
    totalprice = noOfPhotocopy * 0.20;
    JOptionPane.showMessageDialog(null, "Total price is RM" +totalprice);
    } else if(noOfPhotocopy>=10) {
    totalprice = noOfPhotocopy * 0.10;
    JOptionPane.showMessageDialog(null, "Total price is RM" +totalprice);
    }
 }

我必须为我的编程课程制作一个项目,我的项目是帮助人们用不同类型的复印件计算复印的总价格。

1 个答案:

答案 0 :(得分:-1)

有错误,我修复了它们。 喜欢

if (type==G){// to compare use type.equals("G")

 String customer = "s_name";// not String customer"s_name;

 float totalprice; // to double totaleprice

试试这个解决方案,确定

import javax.swing.JOptionPane;

公共类Project1 {

public static void main(String[] args) {

    int noOfPhotocopy;
    double totalprice;

    String customer = "s_name";
    customer = JOptionPane.showInputDialog("Enter customer's name: ");

    String type = JOptionPane.showInputDialog("Choose type of photocopy: G/C").toUpperCase();

    if (type.equals("G")) {
        noOfPhotocopy = Integer.parseInt(JOptionPane
                .showInputDialog("Enter no of photocopy: "));

        if (noOfPhotocopy < 10) {
            totalprice = noOfPhotocopy * 0.10;
            JOptionPane.showMessageDialog(null, "Total price is RM"
                    + totalprice);
        } else if (noOfPhotocopy >= 10) {
            totalprice = noOfPhotocopy * 0.05;
            JOptionPane.showMessageDialog(null, "Total price is RM"
                    + totalprice);
        }
    }
        else if (type.equals("C")) {
            noOfPhotocopy = Integer.parseInt(JOptionPane
                    .showInputDialog("Enter no of photocopy: "));

            if (noOfPhotocopy < 10) {
                totalprice = noOfPhotocopy * 0.20;
                JOptionPane.showMessageDialog(null, "Total price is RM"
                        + totalprice);
            } else if (noOfPhotocopy >= 10) {
                totalprice = noOfPhotocopy * 0.10;
                JOptionPane.showMessageDialog(null, "Total price is RM"
                        + totalprice);
            }
        }       
    }
}