Results 1 to 12 of 12
  1. #1
    Snizz is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default 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:

    Java 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); 
        }
    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.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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default 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.

  3. #3
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default Re: Code not compiling, stating ";" is expected

    If you read this line carefully you'll notice the error:

    Java Code:
    return DeliveryCost = (Distance / 1.6) * 2.00);
    It clearly you have unwanted closing parenthesis in there.

  4. #4
    Snizz is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default 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;
    }

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default 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.

    ** This space for rent **

  6. #6
    Snizz is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default 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

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default 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.

    ** This space for rent **

  8. #8
    Snizz is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Code not compiling, stating ";" is expected

    im still confused

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: Code not compiling, stating ";" is expected

    That is a warning, not an error.
    It is telling you that this:
    Java Code:
    (Distance / 1.6) * 2.00
    produces a double, which you are assigning to DeliveryCost, which is an int.
    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.

    ** This space for rent **

  10. #10
    Snizz is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default Re: Code not compiling, stating ";" is expected

    ohhh ok thanks alot if i have any other problems il post it up

  11. #11
    Snizz is offline Member
    Join Date
    Dec 2012
    Posts
    24
    Rep Power
    0

    Default 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. #12
    monkeyjr97 is offline Senior Member
    Join Date
    Nov 2012
    Posts
    258
    Rep Power
    2

    Default 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

  1. I'm new and in desperate need of help
    By Bdufty in forum Introductions
    Replies: 4
    Last Post: 04-30-2012, 06:18 AM
  2. Replies: 16
    Last Post: 12-24-2011, 04:06 PM
  3. Replies: 1
    Last Post: 01-20-2011, 04:59 PM
  4. help i'm desperate
    By AniMaind in forum New To Java
    Replies: 17
    Last Post: 01-08-2011, 01:05 AM
  5. Desperate for some help if possible :(
    By SBOSlayer in forum New To Java
    Replies: 1
    Last Post: 11-30-2010, 10:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •