Question: I have a question about my computer science homework. One of the things it asks me to do is create a boolean charge method that

I have a question about my computer science homework. One of the things it asks me to do is create a boolean charge method that will return true or false based on the value of variables price and limit. These are the directions:

initial balance to 0 and limit to 10000, choose whatever value you want to initial the other data fields

The charge method will remove price from limit and decrease the balance (when you own money, you have a negative balance), this operation will be rejected if price exceed limit

And this is what I have:

public boolean charge(double price) { if( price <= limit) { limit -= price; balance -= price; return true; }else if (price > limit){ return false; } }

I'm getting an error message where it is saying that it needs a return statement but I have a return statement. What is the issue here? Java please and let me know if you need any other information.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!