Welcome to Dream.In.Code
Become a Java Expert!

Join 149,594 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,857 people online right now. Registration is fast and FREE... Join Now!




please help me with the main class

 
Reply to this topicStart new topic

please help me with the main class, this code needs a main class; what should i do?

BreadStix
5 Oct, 2007 - 10:52 AM
Post #1

New D.I.C Head
*

Joined: 5 Oct, 2007
Posts: 3


My Contributions
CODE

import javax.swing.*;

public class MainMP {

    /**
     * @author BDAndaya
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        Codebreaker alpha= new Codebreaker();

        alpha.setMaxguess(10);
        
        
        int white=0;
        int black=0;

        
        char[] karakter = new char[100];
        char[] usercodeguess = new char[4];
        

        do{
        userChoice = JOptionPane.showInputDialog(null, "Choose path:");
        
        if(userChoice==0){
            
            
            alpha.newGameMessage(alpha.showMaxguess());
            
            //reset white and black and lastinput
            alpha.setWhiteValue(0);
            alpha.setBlackValue(0);
            

            //generate the code
            do{
            alpha.generateCode(9);
            }
            while(alpha.showCode()<1000);
            
            String code = (alpha.showCode() + " ");

            int m=1;
            
            for(int x=0;x<alpha.showMaxguess();x++){
                

                int y=x+1;
                String input=JOptionPane.showInputDialog(null, "Try #" + y + "\n\nClue: WHITE[" + alpha.showWhite() + "]; BLACK[" + alpha.showBlack() + "]" + "\n\nEnter a 4-digit code\n", lastinput);
                lastinput = input;


                
                }
                

                //this checks the code entered by the user
                for(int r=0;r<input.length();r++){
                    karakter[x] = input.charAt®;
                    if(Character.isLetter(karakter[x])){
                        if(!input.equals("uncle")){
                            JOptionPane.showMessageDialog(null, "A code should not contain letters");
                            lastinput="Wrong Input";

                            break;
                        }
                    }
                    //next line gets only the digits inside the string that was inputted by the user
                    if(Character.isDigit(karakter[r])){
                        //filters the entered digits, so that the program will only accept 4 digits
                        if(p==4){
                        JOptionPane.showMessageDialog(null, "You've entered more than 4 characters");
                        lastinput="Wrong Input";
                        break;
                        }

                        usercodeguess[p]=karakter[r];
                        p++;

                        //next line, the program checks the acquired codes and adds the increments/decrements the values of white/black according to the given code
                        for(int z=0;z<4;z++){
                            if(karakter[r]==code.charAt(x)){
                                alpha.changeWhiteValue('+',1);
                                for(int j=0;j<4;j++){
                                    if(z==r){
                                        continue;
                                    }
                                    else{
                                        if(usercodeguess[r]==usercodeguess[j]){
                                            alpha.changeWhiteValue('-',1);
                                        }
                                        
                                    }
                                }
                                if(r==j){

                                    alpha.changeBlackValue('+',1);
                                }
                            }
                        }
                    }
                }
                //output here
                if(alpha.showBlack()==4){
                    alpha.win(alpha.showCode(),y);
                    break;
                }
                if(m==alpha.showMaxguess()){
                    alpha.lose(alpha.showCode());
                }
                m++;
            }
        }
        
        }
        }while(userChoice!=2);
    }

}

User is offlineProfile CardPM
+Quote Post

spullen
RE: Please Help Me With The Main Class
5 Oct, 2007 - 12:19 PM
Post #2

D.I.C Regular
Group Icon

Joined: 22 Mar, 2007
Posts: 330



Thanked: 1 times
Dream Kudos: 50
My Contributions
you have a main method, what's the problem?
User is offlineProfile CardPM
+Quote Post

BreadStix
RE: Please Help Me With The Main Class
5 Oct, 2007 - 03:44 PM
Post #3

New D.I.C Head
*

Joined: 5 Oct, 2007
Posts: 3


My Contributions
QUOTE(spullen @ 5 Oct, 2007 - 01:19 PM) *

you have a main method, what's the problem?


imen, i need a class that supports it.. please help me..
User is offlineProfile CardPM
+Quote Post

spullen
RE: Please Help Me With The Main Class
10 Oct, 2007 - 03:44 PM
Post #4

D.I.C Regular
Group Icon

Joined: 22 Mar, 2007
Posts: 330



Thanked: 1 times
Dream Kudos: 50
My Contributions
What do you mean a class that supports it, the main method is just the entry point into the program.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:18PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

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