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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java Problem

  • 06-11-2008 10:57am
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 17,727 ✭✭✭✭Sherifu


    Some errors would help...

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


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 495 ✭✭jakedixon2004


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


  • Advertisement
  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 495 ✭✭jakedixon2004


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


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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,363 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, Registered Users 2 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, Registered Users 2 Posts: 495 ✭✭jakedixon2004


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


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 495 ✭✭jakedixon2004


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


  • Registered Users, Registered Users 2 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, Registered Users 2 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");
    
    
                          }
                        }
    


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


    I feel that i have paired my brackets , but i may be wrong (as i have been before :o)

    Check the closing bracket on your class.


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


    DamoKen wrote: »
    this is where google is your best mate.

    Wrong, this is where indentation is your best friend. :pac:

    OP, notice how when you indent properly, all open brackets have an easily distinguishable closing bracket directly below it. See if you can find your missing bracket now :)

    PS; Indent properly and you'll probably be marked higher on your project too.
    public class customer2 
    {
    	private String address;
    	private  double overdraftLimit;
    	private String name;
    	
    	public customer2(String Address, String fullName, double overdraftLimit)
    	{
    		name = fullName;
    		address = Address;
    		overdraftLimit = overdraftLimit;
    	}
    
    	public String getName()
    	{
    		return name;
    
    	}
    
    	public String getAddress()
    	{
    		return address;
    	}
    
    	public double getoverdraftLimit()
    	{
    		return overdraftLimit;
    	}
    
    	public void changeAddress(String newAddress)
    	{
    		address = newAddress;
    	}
    
    	public void changeName(String newName)
    	{
    		name = newName;
    	}
    
    	public void changeoverdraftLimit(double newoverdraftLimit)
    	{
    		overdraftLimit = newoverdraftLimit;
    	}
    	
    	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");
    		}
    	}
    


  • Registered Users, Registered Users 2 Posts: 594 ✭✭✭eden_my_ass


    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");
    
    
                          }
                        }
    

    In fairness since you've posted this you have had plenty of time to tidy up your formatting....and failed, and also you've failed to paste your full code, so I'm done with helping....have fun and better luck next time, this isn't the "Boards will fix it" service you know :P


  • Registered Users, Registered Users 2 Posts: 594 ✭✭✭eden_my_ass


    Wrong, this is where indentation is your best friend. :pac:

    OP, notice how when you indent properly, all open brackets have an easily distinguishable closing bracket directly below it. See if you can find your missing bracket now :)
    public class customer2 
    {
    	private String address;
    	private  double overdraftLimit;
    	private String name;
    	
    	public customer2(String Address, String fullName, double overdraftLimit)
    	{
    		name = fullName;
    		address = Address;
    		overdraftLimit = overdraftLimit;
    	}
    
    	public String getName()
    	{
    		return name;
    
    	}
    
    	public String getAddress()
    	{
    		return address;
    	}
    
    	public double getoverdraftLimit()
    	{
    		return overdraftLimit;
    	}
    
    	public void changeAddress(String newAddress)
    	{
    		address = newAddress;
    	}
    
    	public void changeName(String newName)
    	{
    		name = newName;
    	}
    
    	public void changeoverdraftLimit(double newoverdraftLimit)
    	{
    		overdraftLimit = newoverdraftLimit;
    	}
    	
    	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");
    		}
    	}
    

    Thats just rubbing it in now....formatting it for him :D


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


    Thats just rubbing it in now....formatting it for him :D

    Sorry :p
    But hopefully it will make him/her see how much of a difference it makes, plus, if he Ctrl+C Ctrl+V's it, it'll still break :D.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 54 ✭✭ejvilla


    Capitalize your class names... I'm suprised it compiles with the lowercase 'c', i've never tried it though so it could, but it's definitely bad practice.

    Read this for more, it is important:
    http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html


  • Registered Users, Registered Users 2 Posts: 495 ✭✭jakedixon2004


    I appologise for the manor in which i am posting .I would normally have done this myself but it is just i have like 4 projects to hand in by the end of next week and i am in a bit of a rush .Once again i would like to thank all who have helped me and appologise for the neatness of my work


  • Registered Users, Registered Users 2 Posts: 594 ✭✭✭eden_my_ass


    I appologise for the manor in which i am posting .I would normally have done this myself but it is just i have like 4 projects to hand in by the end of next week and i am in a bit of a rush .Once again i would like to thank all who have helped me and appologise for the neatness of my work

    Did you get it to compile?


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


    I appologise for the manor in which i am posting .I would normally have done this myself but it is just i have like 4 projects to hand in by the end of next week and i am in a bit of a rush .Once again i would like to thank all who have helped me and appologise for the neatness of my work

    you'll find as your classes get longer bad naming and indentation practises will cost you a lot more time. Get into the habit of indenting after each {, just one tab will do it :). Not sure with BlueJ but most IDE's will automatically align your closing braces. It'll become second nature and cost no time.

    Clarity of code is extremely important for practical reasons.


  • Registered Users, Registered Users 2 Posts: 495 ✭✭jakedixon2004


    Well i find that it is a way messier compiler than others i have used .
    and no , it did not compile


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


    Well i find that it is a way messier compiler than others i have used .
    and no , it did not compile

    you're not looking at it properly or reading the clues. You've been told the reason for the compile error, your indentation has been done for you...BUT...the missing bracket was left for you to find. Last clue, last time, LAST bracket :)


  • Registered Users, Registered Users 2 Posts: 495 ✭✭jakedixon2004


    ha ha , success
    It compiled .Thanks for all the help lads , would have been lost without it .
    Now onto the next part of the project


  • Registered Users, Registered Users 2 Posts: 594 ✭✭✭eden_my_ass


    ha ha , success
    It compiled .Thanks for all the help lads , would have been lost without it .
    Now onto the next part of the project

    And I bet you won't go back and format it either, a cranky lecturer will mark that down :D You're welcome though :)


  • Registered Users, Registered Users 2 Posts: 495 ✭✭jakedixon2004


    No , i will if i have enough time .The work is building up and i wont have enough time to finish all of them , i dont think


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


    No, i will if i have enough time.

    /Sigh


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    ejvilla wrote: »
    Capitalize your class names... I'm suprised it compiles with the lowercase 'c',

    Yea it is a coding convention. Should throw up warnings only.


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


    And so our brave OP struggles to the end. The indent advice will save you time in the long run.


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    The problem i think is the last part

    I count 13 things wrong with your code. I would of pushed for 14 but it was a close call.

    If you refuse to format your code then 14 (potenically 15). If I was petty 16.
    The indent advice will save you time in the long run.

    Not only that it is standard coding practice and I would say you would be marked down for not doing it.


  • Closed Accounts Posts: 324 ✭✭radioactiveman


    If it's not due until monday go out on the lash
    leave it til sunday:D


  • Registered Users, Registered Users 2 Posts: 6,240 ✭✭✭hussey


    public customer2(String Address, String fullName, double overdraftLimit)
    	{
    		name = fullName;
    		address = Address;
    		[B]this[/B].overdraftLimit = overdraftLimit;
    	}
    

    you also need the this, so you know you are trying to set the class variable rather than the function variable.
    (this refers to the class)


  • Advertisement
Advertisement