2 Replies - 7685 Views - Last Post: 16 October 2008 - 04:14 AM Rate Topic: -----

#1 didi2005  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 15-September 08

HiLo Game

Posted 15 October 2008 - 08:09 AM

HiLo class
//class name
public class HiLo {
	
	//Attributes
	private int sysNum;
	private int userNum;
	private int iguesses;
	
		


//Constructor
public void HiLo (int system_number, int user_number, int user_guesses){
	sysNum = system_number;
	userNum = user_number;
	iguesses = user_guesses;
	
}

//Methods
public void start()throws IOException{
		
		int startNum;
		Pembaca read;
		read = new Pembaca();
		System.out.println("Welcome to HiLo game");
		System.out.println("To play a HiLo game, enter a number to continue. To quit enter -1.");
		startNum = read.bacaInt();
		if (startNum != -1)
			System.out.println("Please read the rules");
		else
			System.out.println("Good Bye.");	
		
}

private void describeRules(){
	
		System.out.println ("Rules:");
		System.out.println ("Enter a number between 1 and 100.");
		System.out.println ("Input number will be compared and reports Correct, High or Low");
		System.out.println ("Maximum number of tries allowed for each game is six.");
}



obj class
import java.util.Random;			// Include class for random number generation
import java.util.StringTokenizer;		// Include class for tokenizer
import java.io.*;

class obj{
	public static void main (String[]args)throws IOException{
		
		HiLo User = new HiLo();
		
		User.start();
		
		User.describeRules();
	}
}



My start() is OK, but when come to the describeRules() method, if failed to run due to private access on the HiLo class... I cant change to public access cosz instruction is given where describeRules() visibility is private...
Any idea?

Is This A Good Question/Topic? 0
  • +

Replies To: HiLo Game

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1156
  • View blog
  • Posts: 7,171
  • Joined: 07-September 06

Re: HiLo Game

Posted 15 October 2008 - 08:18 AM

All that means if you have to call the function from within the class. Try something like so:

Call the rules:
User.rules();


In the HiLo class:
public void rules(){
  describeRules();
}

private void describeRules(){
	
		System.out.println ("Rules:");
		System.out.println ("Enter a number between 1 and 100.");
		System.out.println ("Input number will be compared and reports Correct, High or Low");
		System.out.println ("Maximum number of tries allowed for each game is six.");
}


Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#3 didi2005  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 15-September 08

Re: HiLo Game

Posted 16 October 2008 - 04:14 AM

View PostBetaWar, on 15 Oct, 2008 - 08:18 AM, said:

All that means if you have to call the function from within the class. Try something like so:

Call the rules:
User.rules();


In the HiLo class:
public void rules(){
  describeRules();
}

private void describeRules(){
	
		System.out.println ("Rules:");
		System.out.println ("Enter a number between 1 and 100.");
		System.out.println ("Input number will be compared and reports Correct, High or Low");
		System.out.println ("Maximum number of tries allowed for each game is six.");
}


Hope that helps.


If put another public method on top of private method, then i just change private to public already enough...
but then the question is required to use private...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1