SillyStudent
SillyStudent

Reputation: 3

Where am I missing a curly bracket?

Am I missing a curly bracket or is something else going on and I've totally broken Java and this is the only error it can provide? I've been at this for ages and I can't see where it's missing. I've tried removing and putting in brackets. I keep getting this error:

Pizza.java:40: error: missing return statement } ^ 1 error

Tool completed with exit code 1


public class Pizza {

    private String customerName;
    private String pizzaSize;
    private int toppings;

    Pizza (String name, String size, int number){
        customerName = name;
        pizzaSize = size;
        toppings = toppings;
    }


    public String getCustomerName(){
        return customerName;
    }

    public void setCustomerName(String name){
        customerName = name;    
    }



    public double calculateCharge(){
        final double SMALL_BASE_CHARGE = 6.50;
        final double SMALL_TOPPING_CHARGE = .75;
        final double MEDIUM_BASE_CHARGE = 10.50;
        final double MEDIUM_TOPPING_CHARGE = 1.25;
        final double LARGE_BASE_CHARGE = 14.50;
        final double LARGE_TOPPING_CHARGE = 1.75;

        double charge = 0.0;
    }
}

Upvotes: 0

Views: 905

Answers (2)

D. Schreier
D. Schreier

Reputation: 1788

A bracket is not missing, the message is clear

error: missing return statement

You specified that your calculateCharge() function will return double but you forgot to return something.

public double calculateCharge()
{
    final double SMALL_BASE_CHARGE = 6.50;
    final double SMALL_TOPPING_CHARGE = .75;
    final double MEDIUM_BASE_CHARGE = 10.50;
    final double MEDIUM_TOPPING_CHARGE = 1.25;
    final double LARGE_BASE_CHARGE = 14.50;
    final double LARGE_TOPPING_CHARGE = 1.75;

    double charge = 0.0;

    // HERE
    return charge;
}

Upvotes: 1

Skident
Skident

Reputation: 326

your compiler says that you are missing a return statement in the end of calculateCharge() method.

So, just add a return statement, like this

public double calculateCharge()
{
    final double SMALL_BASE_CHARGE = 6.50;
    final double SMALL_TOPPING_CHARGE = .75;
    final double MEDIUM_BASE_CHARGE = 10.50;
    final double MEDIUM_TOPPING_CHARGE = 1.25;
    final double LARGE_BASE_CHARGE = 14.50;
    final double LARGE_TOPPING_CHARGE = 1.75;

    double charge = 0.0;
    // TODO: Do your math here
    return charge;
}

Upvotes: 2

Related Questions