Results 1 to 12 of 12
- 12-03-2012, 11:05 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
Code not compiling, stating ";" is expected
the assignment is basically a take away service and ive been working through it as much as i can but now im stuck
- delivery cost is £2 per mile
heres the code that is giving me problems:
its the last line of code where i implement the calculation for the delivery cost that is giving me problems, the error message saying that ";" is expected right after the 2.00Java Code:// instance variables - replace the example below with your own private int OrderRefNo; private String CustomerName; private String Description; private int TotalCst; private int CallTime; private int DeliveryCost; private String TkeAway; private int Distance; /** * Constructor for objects of class Order */ public void Order() { // initialise instance variables OrderRefNo = 0; CustomerName = null; Description = null; TotalCst = 0; CallTime = 00; Distance = 0; } /** * Accessor for objects of class Order */ public int getOrderRefNo() { return OrderRefNo; } public String getCustomerName() { return CustomerName; } public String getDescription() { return Description; } public int CallTime() { return CallTime; } public int Distance() { return Distance; } public int getDeliveryCost() { return DeliveryCost = (Distance / 1.6) * 2.00); }
can anyone please explain what i must do??Last edited by Fubarable; 12-04-2012 at 02:31 AM. Reason: code tags added. "urgent" removed. Title updated
-
Re: Seriously stuck on blue j need desperate help!
Code tags added to aid in post's readability. Thread moved from the "Other IDE" forum to the "New to Java" forum since it has nothing really to do with BlueJ and all to do with Java. I've edited your title to one that describes the problem and have removed all mention of "urgency" and due date, since that is not this forum's concern.
Please post the entire class code since I don't think it's that big, and seeing everything can help us figure out what's wrong. Also please post your compiler's full error message.Last edited by Fubarable; 12-04-2012 at 02:35 AM.
- 12-04-2012, 02:36 AM #3
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: Code not compiling, stating ";" is expected
If you read this line carefully you'll notice the error:
It clearly you have unwanted closing parenthesis in there.Java Code:return DeliveryCost = (Distance / 1.6) * 2.00);
Website: Learn Java by Examples
- 12-04-2012, 01:26 PM #4
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
Re: Code not compiling, stating ";" is expected
i still cant see the error, heres the declerations:
public class Order
{
// instance variables - replace the example below with your own
private int OrderRefNo;
private String CustomerName;
private String Description;
private int TotalCst;
private int CallTime;
private int DeliveryCost;
private int Distance;
/**
* Constructor for objects of class Order
*/
public void Order()
{
// initialise instance variables
OrderRefNo = 0;
CustomerName = null;
Description = null;
TotalCst = 0;
CallTime = 00;
Distance = 0;
}
- 12-04-2012, 02:28 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Code not compiling, stating ";" is expected
Nothing to do with declarations.
Count the brackets on the line wsaryada has posted.Please do not ask for code as refusal often offends.
- 12-04-2012, 03:00 PM #6
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
Re: Code not compiling, stating ";" is expected
but even without the closing bracket it still wont compile
it has highlighted "* 2.00"
error message:
possible loss of precision required: int; found: double
- 12-04-2012, 03:06 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Code not compiling, stating ";" is expected
So that's a different error.
We cannot see what you have done if you don't tell us.
DeliveryCost is an int, so all that is telling you is that you will lose any fractions from your calculation.Please do not ask for code as refusal often offends.
- 12-04-2012, 03:15 PM #8
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
Re: Code not compiling, stating ";" is expected
im still confused
- 12-04-2012, 03:45 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Code not compiling, stating ";" is expected
That is a warning, not an error.
It is telling you that this:
produces a double, which you are assigning to DeliveryCost, which is an int.Java Code:(Distance / 1.6) * 2.00
An int has no decimal places, so you will lose precision.
If the above calculation produced a value of 2.5, then your DeliveryCost would be 2.Please do not ask for code as refusal often offends.
- 12-04-2012, 04:04 PM #10
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
Re: Code not compiling, stating ";" is expected
ohhh ok thanks alot if i have any other problems il post it up
- 12-04-2012, 06:54 PM #11
Member
- Join Date
- Dec 2012
- Posts
- 24
- Rep Power
- 0
Re: Code not compiling, stating ";" is expected
hi ive got another problem i was wondering if you could help, i was given this task in my assignment:
Define the method findOrderWaiting which has one parameter to represent the order reference number. It then iterates through the ordersWaiting list to find and return the job with that reference number. If there is no such job, it returns null.
i have declared findOrdersWaiting as a String so far
im not sure if it requires an if statement or not but ive attempted it anyway have a look and let me know if im on the right path at least please.
public String findOrdersWaiting(int OrderRefNo)
{
if (findOrdersWaiting = OrderRefNo)
{
findOrderWaiting = getOrderRefNo;
}
return null;
}
- 12-05-2012, 12:31 AM #12
Senior Member
- Join Date
- Nov 2012
- Posts
- 221
- Rep Power
- 1
Re: Code not compiling, stating ";" is expected
can you wrap any code on [ code] [ /code] tags please, (remove the spaces) it allows everybody to read the code more easily!
regarding the searching for an order. do you have an ArrayList or something along those lines that contains all the ordersWaiting?
if you dont have a way of holding the orders how will you be able to search for them?
Similar Threads
-
I'm new and in desperate need of help
By Bdufty in forum IntroductionsReplies: 4Last Post: 04-30-2012, 06:18 AM -
Stuck with KMeans Clustering Algorithm DESPERATE HELP NEEDED
By Suzanne M in forum Advanced JavaReplies: 16Last Post: 12-24-2011, 04:06 PM -
PLEASE SOMEONE HELP ME =( database.. im desperate
By santa in forum New To JavaReplies: 1Last Post: 01-20-2011, 04:59 PM -
help i'm desperate
By AniMaind in forum New To JavaReplies: 17Last Post: 01-08-2011, 01:05 AM -
Desperate for some help if possible :(
By SBOSlayer in forum New To JavaReplies: 1Last Post: 11-30-2010, 10:44 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks