Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,424 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,345 people online right now. Registration is fast and FREE... Join Now!




HiLo Game

 
Reply to this topicStart new topic

HiLo Game

didi2005
15 Oct, 2008 - 07:09 AM
Post #1

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 24

HiLo class
CODE

//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
CODE

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?


User is offlineProfile CardPM
+Quote Post

BetaWar
RE: HiLo Game
15 Oct, 2008 - 07:18 AM
Post #2

#include <soul.h>
Group Icon

Joined: 7 Sep, 2006
Posts: 2,022



Thanked: 81 times
Dream Kudos: 1175
My Contributions
All that means if you have to call the function from within the class. Try something like so:

Call the rules:
CODE
User.rules();


In the HiLo class:
CODE
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.
User is offlineProfile CardPM
+Quote Post

didi2005
RE: HiLo Game
16 Oct, 2008 - 03:14 AM
Post #3

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 24

QUOTE(BetaWar @ 15 Oct, 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:
CODE
User.rules();


In the HiLo class:
CODE
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...


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 01:22PM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month