-3
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);
    }
 }

i have to make a project for my Programming course and my project is to help people to calculate total price of photocopying with different type of photocopy.

Abdelhak
  • 8,299
  • 4
  • 22
  • 36

1 Answers1

-1

There are error, I fixed them. like

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

and

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

and

 float totalprice; // to double totaleprice

Try this solution it's OK

import javax.swing.JOptionPane;

public class 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);
            }
        }       
    }
}
Abdelhak
  • 8,299
  • 4
  • 22
  • 36