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
2»

Comments

  • Registered Users 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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
  • Banned (with Prison Access) Posts: 6,201 ✭✭✭KamiKazi


    You should always indent, it doesn't take long to become second nature and is makes debugging your code 100x easier IMO.


  • Closed Accounts Posts: 287 ✭✭twasantis


    hussey wrote: »
    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)



    and also..

    this.name
    this.address

    i thinks anyway

    dont u need to compare accounts later???if so its

    this.name
    this.address


  • Registered Users Posts: 495 ✭✭jakedixon2004


    Thanks for the help guys .I redid most of the code and it is no longer messy.Now thats done ,BEER!!!:D


  • Closed Accounts Posts: 25 protective


    good stuff


  • Registered Users Posts: 1,119 ✭✭✭Donald-Duck


    It takes all of 2 minutes to format a hundred lines of code. Or no time if you format it in the first place:)


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


    Thanks for the help guys .I redid most of the code and it is no longer messy.Now thats done ,BEER!!!:D
    Fair play :)


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


    It takes all of 2 minutes to format a hundred lines of code.

    Eclipse = CTRL+ALT+F


Advertisement