Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Problem

Options
  • 06-11-2008 11:57am
    #1
    Registered Users Posts: 495 ✭✭


    I am a first year computer forencis student and i have this huge assignment due by monday and for some reason this wont compile.I was wondering if maybe someone knew what my problem was.
    public class customer2 
    {
        /**
         * Fields
         */
    
        private String address;
        
        private  double overdraftLimit;
        
        private String name;
    
    
        /**
         * Constructor
         */
        public customer2(String Address, String fullName, double overdraftLimit)
        {
            name = fullName;
            address = Address;
            overdraftLimit = overdraftLimit;
        
        }   
        
    
        /**
         * Getter's
         */
    
        public String getName()
        {
            return name;
            
        }
        
        public String getAddress()
        {
           return address;
        }
        
        public double getoverdraftLimit()
        {
            return overdraftLimit;
        }
    
        /**
         * Setter's
         */
        
        public void changeAddress(String newAddress)
        {
            address = newAddress;
        }
        
        public void changeName(String newName)
        {
            name = newName;
        }
    
        public void changeoverdraftLimit(double newoverdraftLimit)
        {
            overdraftLimit = newoverdraftLimit;
        }
    
       /**
        * Compare method
        */ 
        
       public void compare(String cust_1 , String cust_2)
          
         {
              if(String customer1 == String customer2)  
            
             
                
                
                          System.out.println("True");
                         
                      
           )
                      else{
                             System.out.println("False");
                             System.out.println("Customer details are different");
    
    
                          }
      }
    

    The problem i think is the last part (the compare method).This part is suppose to compare two different bank customers and i think that I have the code right


«1

Comments

  • Registered Users Posts: 17,727 ✭✭✭✭Sherifu


    Some errors would help...

    if(String customer1 == String customer2) - this looks wrong.


  • Registered Users Posts: 495 ✭✭jakedixon2004


    well it says that a bracket is expected
    The program i am using is Bluej


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Yes, but where? I don't want to come across as an ass, but the entire text of the error is there for a reason.

    Anyway, I don't see an opening ( on the if in compare(), or a closing } for the class.


  • Registered Users Posts: 594 ✭✭✭eden_my_ass


    You 'should' capitalise the O in

    public double getoverdraftLimit()

    and

    public double getoverdraftLimit()

    if(String customer1 == String customer2)
    should be
    if(cust_1.equals(cust_2)) {


  • Registered Users Posts: 495 ✭✭jakedixon2004


    Wait , are u sayin that all of what i have written is wrong or that there are several errors in what i have written


  • Advertisement
  • Closed Accounts Posts: 3,285 ✭✭✭Smellyirishman


    Your indentation and naming conventions make your program hard to read. Try to use a standard style and stick with it.

    There are a few errors in your compare method, what are you using to compile?


  • Closed Accounts Posts: 3,285 ✭✭✭Smellyirishman


    Wait , are u sayin that all of what i have written is wrong or that there are several errors in what i have written

    Several errors, most of which have been pointed out to you by now (unfortunately) :pac:


  • Registered Users Posts: 594 ✭✭✭eden_my_ass


    Wait , are u sayin that all of what i have written is wrong or that there are several errors in what i have written

    You're almost there....but aren't we all always :D


  • Registered Users Posts: 495 ✭✭jakedixon2004


    I appologise for the lack of structure in my program but i am in kind of a rush.
    I am using bluej to compile


  • Registered Users Posts: 495 ✭✭jakedixon2004


    I tried ur method eden and all i got was "error .... 'else without 'if' "


  • Advertisement
  • Registered Users Posts: 17,727 ✭✭✭✭Sherifu


    o/t post ahead ;)
    I appologise for the lack of structure in my program but i am in kind of a rush.
    I am using bluej to compile
    I have fond memories of bluej from college days. I liked their icon. :)


  • Closed Accounts Posts: 3,285 ✭✭✭Smellyirishman


    OK, so look at your if statement, anything look out of place?
    if(String customer1 == String customer2)  
       System.out.println("True");
    )
    


  • Registered Users Posts: 495 ✭✭jakedixon2004


    I have changed that staement to :
    if (cust_1.equals(cust_2)) {
    


  • Registered Users Posts: 495 ✭✭jakedixon2004


    I have fond memories of bluej from college days. I liked their icon

    I too hope to have fond memories of bluej when i am older


  • Registered Users Posts: 1,269 ✭✭✭DamoKen


    Wait , are u sayin that all of what i have written is wrong or that there are several errors in what i have written

    Look at your parameter names in the other methods and then those in the compare method. You are passing two parameters into the compare and then for some reason trying to declare two new Strings Customer1 & customer2 in your equality expression.

    You should just be comparing the parameters you passed in, and as they are String objects you should use the String.equals(String) method as previously pointed out.

    Forgot to mention the bracket. Never used that compiler, a handy feature in Eclipse is it highlights your opening and corresponding closing brackets in a block of code if you place the cursor on one of them, is there an equivalent in BlueJ?


  • Registered Users Posts: 17,727 ✭✭✭✭Sherifu


    @jakedixon2004: Did you get rid of that stray bracket as pointed out in post #13?


  • Closed Accounts Posts: 3,285 ✭✭✭Smellyirishman


    I have changed that staement to :
    if (cust_1.equals(cust_2)) {
    

    So now it looks like this?
    if(cust_1.equals(cust_2)){
       System.out.println("True");
    )
    

    Let's style it a little differently and see if you spot the mistake; it's subtle enough.
    if(cust_1.equals(cust_2))
    {
       System.out.println("True");
    )
    


  • Registered Users Posts: 594 ✭✭✭eden_my_ass


    Sherifu wrote: »
    Did you get rid of that stray bracket as pointed out in post #13?

    All thats wrong at this stage is bracketing....read your own code, of course I could correct the lot and paste it, but it teaches nothing...read it, open close open close....and you'll see your errors, btw i added an { to your if, so naturally you'll need to } after the body of the if is done.


  • Moderators, Music Moderators Posts: 23,361 Mod ✭✭✭✭feylya


    if(String customer1 == String customer2)  
            
             
                
                
                          System.out.println("True");
                         
                      
           )
    

    should be
    if (cust_1.equals(cust_2))
    {       
       System.out.println("True");
    }
    


  • Registered Users Posts: 594 ✭✭✭eden_my_ass


    So now it looks like this?
    if(cust_1.equals(cust_2)){
       System.out.println("True");
    )
    

    Let's style it a little differently and see if you spot the mistake; it's subtle enough.
    if(cust_1.equals(cust_2))
    {
       System.out.println("True");
    )
    

    I need glasses, even I didn't see the round bracket....get out of computers lads, they're bad for the eyes!


  • Advertisement
  • Closed Accounts Posts: 3,285 ✭✭✭Smellyirishman


    Hurray, now the OP can just copy and paste that and have no idea what the difference is.


  • Registered Users Posts: 495 ✭✭jakedixon2004


    I suppose ye are talkin about the normal bracket at the end of the 'if' statement .


  • Registered Users Posts: 594 ✭✭✭eden_my_ass


    Hurray, now the OP can just copy and paste that and have no idea what the difference is.

    Yup, thats the point I was trying to make, I've helped people by doing that before, and its no help at all to them really.


  • Closed Accounts Posts: 3,285 ✭✭✭Smellyirishman


    I suppose ye are talkin about the normal bracket at the end of the 'if' statement .

    Correct.

    if(boolean)
    {
    statements
    }

    Is the proper form for an if statement. So the compiler was expecting the closing bracket } but you had a ).

    I know you say you're in a rush so you can't indent but trust me, you will save yourself so much more time if you indent appropriately as you can match up opening/closing brackets easily and quickly distinguish blocks of code.


  • Registered Users Posts: 495 ✭✭jakedixon2004


    Well if it makes you feel any better , i saw it before that post by feylya
    And , the compiler has now decided to pull up the error "reached end of file while parsing"


  • Registered Users Posts: 1,269 ✭✭✭DamoKen


    Hurray, now the OP can just copy and paste that and have no idea what the difference is.

    that's what the internet is for I guess, why think when others will do it for you

    OP if you read through the other posts and don't just copy and paste you'll get it. It can be hard when you're just starting to spot the errors, simple ones become less common over time, the trick is to take on board every compiler error you encounter and the cause behind it. Gets easier with experience ;)


  • Registered Users Posts: 594 ✭✭✭eden_my_ass


    Well if it makes you feel any better , i saw it before that post by feylya
    And , the compiler has now decided to pull up the error "reached end of file while parsing"

    Lets see the whole class now....I have a feeling you are still missing a final }


  • Registered Users Posts: 495 ✭✭jakedixon2004


    Yes , i would say that experience is key in the world of programming


  • Registered Users Posts: 1,269 ✭✭✭DamoKen


    Well if it makes you feel any better , i saw it before that post by feylya
    And , the compiler has now decided to pull up the error "reached end of file while parsing"

    this is where google is your best mate. First result from pasting the above error in is -> http://forums.java.net/jive/thread.jspa?messageID=215473 . The cause and solution to your error is more than likely the post at the bottom.


  • Advertisement
  • Registered Users Posts: 495 ✭✭jakedixon2004


    I feel that i have paired my brackets , but i may be wrong (as i have been before :o)
    public void compare(String cust_1 , String cust_2)
          
         {
              if (cust_1.equals(cust_2))
    {       
       System.out.println("True");
    }
    
            
             
                
                
                          
                         
                      
           
                      else {
                             System.out.println("False");
                             System.out.println("Customer details are different");
    
    
                          }
                        }
    


Advertisement