I have a problem with my program. When i try to compile it it says i need a ; can someone try to compile it and please help me?

//This program will represent a pizza

public class Pizza
{
	private double cost; 		//the cost of the pizze
	private String crust;		//the type of crust
	private int size;		//the diameter in inches
	private int numToppings; 	//the number of toppings
	private String toppingList;	//a list of the toppings

	//Constructor creates a 12" Hand-Tossed pizza
	public Pizza()
	{
		cost = 12.99;
		crust = "Hand-Tossed";
		size = 12;
		numToppings = 0;
		toppingList=null;

	}

	//adds the parameter amount to the cost
	public void setCost (double amount)
	{
		cost +=amount;
	}

	//sets the crust type
	public void setCrust (String type)
	{
		crust=type;
	}

	//changes the size of the pizza to the parameter diameter
	public void setSize (int diameter)
	{
		size = diameter;
	}

	//sets the number of toppings to the parameter number
	public void setNumToppings(int number)
	{
		numToppings=number;
	}

	//sets the list of toppings
	public void setToppingsList (String newTopping)
	{
		toppingList = newTopping;
	}

	//returns the cost of the pizze
	public double getCost()
	{
		return cost;
	}

	//returns the crust type
	public String getCrust()
	{
		return crust;
	}

	//returns the size of the pizza
	public int getSize()
	{
		return size;
	}

	//returns the number of toppings
	public int getNumToppings()
	{
		return numToppings;
	}

	//returns the list of toppings
	public String getToppingsList()
	{
		return toppingList;
	}
}
//This program allows the user to order a pizza

import java.util.Scanner;
import java.text.*;

public class PizzaOrder
{
	public static void main(String [] args)
	{



		//create a Scanner object to readinput
		Scanner keyboard = new Scanner (System.in);

		//creat an instance of a Pizza
		Pizza order = new Pizza ();

		String firstName;				//user's first name
		boolean discount = false;		//flag, true if user is eligible for discount
		int inches;						//size of the pizza
		char crustType;					//type of crust
		double cost;					//cost of the pizza
		final double TAX_RATE = .08;	//sales tax rate
		double tax;						//amount of tax
		char choice;					//user's choice
		String input;					//user's input
		String toppings= "Cheese";	 	//list of toppings
		int numberOfToppings = 0;		//number of toppings

		//prompt user and get first name
		System.out.println("Welcome to Jack and Diane's Pizza");
		System.out.print("Enter your first name:");
		firstName = keyboard.nextLine();

		//determine if user is eligible for discount by having the same first name as one of the owners
		//TASK #1
		if (discount)
		{
			firstName= "Jack";
		}
		else if (discount)
		{
			firstName= "Diane";
		}
		else
		{
			discount = false;
		}

		//prompt user and get pizza size choice
		System.out.println("Pizza Size(inches) Cost");
		System.out.println("	10	$10.99");
		System.out.println("	12	$12.99");
		System.out.println("	14	$14.99");
		System.out.println("	16	$16.99");
		System.out.println("What size pizza would you like?");
		System.out.println("10, 12, 14, or 16 (enter the number only):");
		inches = keyboard.nextInt();

		//set price and size of pizza ordered
		//ADD LINES HERE FOR TASK #2
		Pizza PizzaInfo = new Pizza();

		if (inches = 10)
		{
			call setSize();
			call setCost();
			cost -=2;
		}

		//consume the remaining newline character
		keyboard.nextLine();

		//prompt user and get crust choice
		System.out.println("What type of crust would you like?");
		System.out.println("(H)Hand-tossed, (T)Thin-crust, or " + "(D)Deep-dish (enter H, T, or D):");
		input = keyboard.nextLine();
		crustType = input.charAt(0);

		//set user's crust choice on pizza ordered
		//ADD LINES FOR TASK #3

		//prompt user and get topping choices one at a time
		System.out.println("All pizzas come with cheese.");
		System.out.println("Additional toppings are $1.25 each," + " choose from");
		System.out.println("Pepperoni, Sausage, Onion, Mushroom");

		//if topping is desired, add to topping list and number of toppings
		System.out.print("Do you want Pepperoni? (Y/N): ");
		input = keyboard.nextLine();
		choice =input.charAt(0);
		if (choice == 'Y' || choice == 'y')
		{
			numberOfToppings +=1;
			toppings = toppings + "Pepperoni";
		}

		System.out.print("Do you want Sausage? (Y/N): ");
		input = keyboard.nextLine();
		choice =input.charAt(0);
		if (choice == 'Y' || choice == 'y')
		{
			numberOfToppings +=1;
			toppings = toppings + "Sausage";
		}
		System.out.print("Do you want Onion? (Y/N): ");
		input = keyboard.nextLine();
		choice =input.charAt(0);
		if (choice == 'Y' || choice == 'y')
		{
			numberOfToppings +=1;
			toppings = toppings + "Onion";
		}
		System.out.print("Do you want Mushroom? (Y/N): ");
		input = keyboard.nextLine();
		choice =input.charAt(0);
		if (choice == 'Y' || choice == 'y')
		{
			numberOfToppings +=1;
			toppings = toppings + "Mushroom";
		}

		//set number of toppings and topping list on pizza ordered
		order.setNumToppings (numberOfToppings);
		order.setToppingsList(toppings);

		//add additional toppings cost to cost of pizza
		order.setCost(1.25*numberOfToppings);

		//display cost of pizza
		cost = order.getCost();

		//apply discount if user is eligible
		//ADD LINES FOR TASK #4 HERE

		//TASK #5
		DecimalFormat form = new DecimalFormat("#.##"); //creates 2 decimal places

		//SO ALL MONEY OUTPUT APPREARS WITH 2 DECIMAL PLACES
		System.out.println("The cost of your order is:$" + form.format(cost));

		//calc and display tax and total cost
		tax = cost * TAX_RATE;
		System.out.println("The tax is: $" + form.format(tax));
		System.out.println("The total due is:$" + form.format((tax+cost)));

		System.out.println("Your order will be ready" + " for pickup in 30 minutes.");
		}
	}
if (inches = 10)
{
	call setSize();
	call setCost();
	cost -=2;
}

This is where I believe your errors are. First of all, your if statement does not resolve, you need to use == to compare, like so

if(inches==10)

Next, if you want to call a method, you don't write call setSize(). What you need to do is specify who is calling the method followed by a full stop (period) followed by the method name with any parameters. In the first case of setSize, you would do this:

PizzaInfo.setSize();

I will let you work out how to call setCost. Then, after you call setCost, you try to adjust cost, but this won't work because cost is a private field. You need to call setCost with the parameter that you want to set the cost to.

Hope this helps,
darkagn

    if (inches = 10)
    {
        call setSize(); ???
        call setCost(); ???
        cost -=2;
    }

call them properly.

call them properly.

what do you mean call them properly?

Read darkagn #2 carefully. There is a more clear answer.

Im still getting an error after i put in

if (inches == 10)
        {
            PizzaInfo.setSize();
            PizzaInfo.setCost();
            cost -=2;
        }

You didn't read my note about setCost...

Sorry peedi, I just realised that your setSize method also takes a parameter (as most set methods do). So the call should look like this:

PizzaInfo.setSize(10);
// although a better call would be PizzaInfo.setSize(inches)
// but I wanted you to see what I was doing

Similarly, setCost needs a parameter to tell it what to set the cost to.

In order to tell what parameters you need to pass to the method, you can look at the method signature. In your Pizza class, let's look at how the setSize method is described:

public void setSize (int diameter)

Let's break this signature up into each part so that we can describe what the signature does:

  • public: This is the access identifier of the method. In this case, public, indicates that the method can be called by an instance of Pizza from anywhere.
  • void: This is the return type of the method. In this case, the method returns void, meaning that nothing is returned.
  • setSize: The name of the method. This is how we call the method.
  • int diameter: The type and name of the first parameter of the method. Other parameters could be added to a method if needed, separated by a comma, and when the method is called the parameters MUST match. In this case when calling the setSize method we must pass a single variable of type int. Inside the method it is known by the name it is given, diameter, even though we may pass it by another name, such as inches.
commented: very helpful +9

thanks alot i got it to work!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.