Results 1 to 6 of 6
  1. #1
    mobosecomin is offline Member
    Join Date
    Oct 2010
    Posts
    23
    Rep Power
    0

    Default a little oo question

    Hi everyone :D only being learning java for the past few months and my first semester went well so even though im on holidays for xmas im playing around with some code as we are going to be moving onto oo next semester.

    Im trying to make a little program that returns the form of soccer teams.My problem is a little hard for me to explain as i am not used to the oo terms yet but I will do my best.
    In my class i have a method that i want to call on form the main.The data i want passed in is also done in the class and not when called but i dont seem to be allowed to do this.hopefully the code will make more sense of this.

    Java Code:
    class TeamForm {
    	
    	int hform8 = 0; //last 8 home games points
    	int aform8 = 0; //last 8 away game points
    	int yform  = 0; // overall year points
    	
    	TeamForm(int homepoints,int awaypoints,int yearpoints ){
    		hform8 = homepoints;
    		aform8 = awaypoints;
    		yform  =yearpoints;
    		}
    		
    		 void hreview (int hform8){
    			
    			 int x  = hform8;
    			
    			 if ((x>=18)&&(x<25)){
    				 System.out.println("Team form is above average ");
    				 }
    			 else if ((x>=12)&&(x<18)){
    				 System.out.println("Team form is average");
    			 }
    			 else if (x<12){
    				 System.out.println("Team form is poor");
    			 }
    			 
    			 void display(){
    			System.out.println(hform8 );
    			System.out.println(aform8 );
    			System.out.println(yform );
    			}
    	}
    here is the main

    Java Code:
    public class apptest {
    	
    		public static void main(String [] args){
    		
    		TeamForm team1 = new TeamForm(17,13,19);
    		
    		team1.hreview ();
    		team1.display();
    	}
    
    }
    since i have set the variables when i created team1 should i be able to call hreview as is ? it works when i pass in an int when calling hreview but this seems to defeat the purpose of creating team1.

    Im not sure whats going on really sorry im only a beginner so if this question silly please excuse me.any help would be appreciated .thanks :)

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Look at your method definition.

    Java Code:
    void hreview (int hform8){
         // body of the method
    }
    You have define an int argument.

    But when you invoke it didn't pass the value.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Look at your method definition.

    Java Code:
    void hreview (int hform8){
         // body of the method
    }
    You have define an int argument.

    But when you invoke it didn't pass the value.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default

    Quote Originally Posted by mobosecomin View Post
    since i have set the variables when i created team1 should i be able to call hreview as is ? it works when i pass in an int when calling hreview but this seems to defeat the purpose of creating team1.

    Im not sure whats going on really sorry im only a beginner so if this question silly please excuse me.any help would be appreciated .thanks :)
    Since, in order to get a TeamForm object, you need to pass in all the relevant dtaa, then there's no reason to declare your hreview() method with any parameters. So change it and get rid of the hform8 parameter. Unless that means something special in this case, but it really doesn't look like it.

  5. #5
    mobosecomin is offline Member
    Join Date
    Oct 2010
    Posts
    23
    Rep Power
    0

    Default

    ahh ok so since i had to put in the data to make the object that data is also available inside the objects methods. i think thats it anyway it works anyway so its step in the right direction. like i said im attempting this without instruction so i really appreciate the help if i have any more questions il post them in this thread. many thanks Eranga and Tolls.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Question concerning question marks and colons
    By jim01 in forum New To Java
    Replies: 17
    Last Post: 01-14-2011, 12:05 AM
  2. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  3. Do while question
    By felito in forum New To Java
    Replies: 14
    Last Post: 11-10-2010, 07:46 PM
  4. Question!
    By anjogomez in forum Java Applets
    Replies: 2
    Last Post: 02-21-2009, 03:24 AM
  5. Need help with a question please
    By sonal in forum New To Java
    Replies: 1
    Last Post: 11-29-2007, 09:17 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
  •