Results 1 to 4 of 4
Like Tree2Likes
  • 2 Post By JosAH

Thread: Java code not compiling!

  1. #1
    tanveerahmed is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default Java code not compiling!

    Java Code:
    /**
     * Write a description of class Order here.
     * 
     * @author (your name) 
     * @version (a version number or a date)
     */
    public class Order
    {
        // instance variables - replace the example below with your own
        private String CustomersName;   //This is the customers name
        private String description;     //This is the description
        private double totalcost;          //This is the total cost
        private Time deliveredTime;     //This is the time it got delivered
        private Time callInTime;        //This is the Time it was called-in
        private int orderRef;               //This is the order reference number
    
        public void setOrderReference(String cn, String de, double tcost, Time dt, int or) 
        {
            CustomersName = cn;
            description = de;
            totalcost = tcost;
            deliveredTime = dt;
            orderRef = or;
        }
        
            public int getOrderNo()
        {
            return orderRef;
        }
        
            public void getDescription()
        {
            return dt;
        }
        
            public Time getCallInTime()
        {
            return callInTime;
        }
        
        /**
         * An example of a method - replace this comment with your own
         * 
         * @param  y   a sample parameter for a method
         * @return     the sum of x and y 
         */
        public int sampleMethod(int y)
        {
            // put your code here
            return x + y;
        }
    }
    But my program is not returning "dt" or "delieveredtime" to be precise Its seriously pissing me off i feel like throwing my computer out the window

    this is exactly what is not allowing me to compile

    public void getDescription()
    {
    return dt;
    }

    what on earth is going wrong?!!!

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

    Default Re: Java code not compiling!

    What is that method declared to return?
    For instance this method is declared to return an int:
    Java Code:
    public int foo() { // this line shows the method is declaring that it will return an int
        return 3;
    }

    What is it in fact trying to return?

  3. #3
    tanveerahmed is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default Re: Java code not compiling!

    Quote Originally Posted by Fubarable View Post
    What is that method declared to return?
    For instance this method is declared to return an int:
    Java Code:
    public int foo() { // this line shows the method is declaring that it will return an int
        return 3;
    }

    What is it in fact trying to return?
    ok I see, the problem was

    public Time getDescription()
    {
    return deliveredTime;
    }
    its meant to be "Time" lol

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,043
    Blog Entries
    7
    Rep Power
    23

    Default Re: Java code not compiling!

    You fixed two things:

    1) the return type of the method and
    2) what it returns.

    The method couldn't return 'dt' because it only existed in another method; 'deliverTime' can be returned because:

    1) it exists (it's an object member variable) and
    2) it has the right type.

    kind regards,

    Jos
    Fubarable and bigsonny like this.
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Replies: 1
    Last Post: 01-31-2012, 09:48 AM
  2. Help compiling code dynamically
    By anarelle in forum Java Applets
    Replies: 13
    Last Post: 07-30-2011, 10:07 PM
  3. Issue compiling Java Code
    By AggressiveFish in forum Java Applets
    Replies: 4
    Last Post: 01-04-2011, 10:10 PM
  4. Compiling java code from the command line
    By alman9898 in forum New To Java
    Replies: 5
    Last Post: 10-13-2010, 03:35 AM
  5. Help me out in compiling the source code
    By aks.nitw in forum Advanced Java
    Replies: 3
    Last Post: 10-17-2008, 08:33 AM

Tags for this Thread

Posting Permissions

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