• 0

JAVA, incompatible types?


Question

//import all
import apcslib.*;
import java.awt.*;
import chn.util.*;
import javax.swing.JOptionPane;

public class Pizza
{
       
     public static void main(String[] args)
     {
     Parlor info = new Parlor();
     {
     info.buyCheesePizza();
     }	
      
     }
}

class Parlor
{
String owner; 
int cheesePizza;
int pepperoniPizza;
int veggiePizza;
int cheeseAmount;
int pepperoniAmount;
int veggieAmount;
double revenue;
double bankAccount;

Parlor()
{
	owner = "name";
	bankAccount = 1000;
	cheesePizza = 0;
	pepperoniPizza = 0;
	veggiePizza = 0;
	cheeseAmount = 400;
	pepperoniAmount = 200;
	veggieAmount = 200;
	revenue = 0;
}
public void buyCheesePizza()
{
// $8 per cheese 12 units of cheese
JOptionPane.showMessageDialog(null,"How many Cheese Pizzas were bought");
cheesePizza = JOptionPane.showInputDialog(null, "Enter pizzas bought");
bankAccount += 8*cheesePizza;
JOptionPane.showMessageDialog(null,"" +bankAccount);


}
}

I'm trying to do the first of the 3 orders, but I keep getting an "incompatible types" error for the line

"cheesePizza = JOptionPane.showInputDialog(null, "Enter pizzas bought");"

Anybody got an idea what the problem is?

Thanks

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

static void showMessageDialog(Component parentComponent, Object message)

Doesn't return an int as you expect it to. :/

You want to use:

static String showInputDialog(Component parentComponent, Object message)

then just cast the String to an int

Link to comment
Share on other sites

  • 0

mmm yeah. I guess you can't input anything in JOption pane except strings eh?

so I used(changed names a little):

JOptionPane.showMessageDialog(null,"How many Cheese Pizzas were bought");

strCheesePizza = JOptionPane.showInputDialog(null, "Enter pizzas bought");

dblCheesePizza = Double.parseDouble(strCheesePizza);

bankAccount += 8*dblCheesePizza;

JOptionPane.showMessageDialog(null,"" +bankAccount);

and it worked

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.