I compiled two java source codes, namely version.class and open.class
Basically, the version.class holds the public static void main clause, while the open.class is mainly a set of constructors that makes the whole program work.
Here is how I did it:
if ("n".equalsIgnoreCase(input)) {
new open();
} else if ("q".equalsIgnoreCase(input)) {
System.exit(0);
}
The problem is when I run it in CMD, where I did type this:
java version
it says that the command can not find or load the main class. What is the main problem why this happens? Thank you. I was hoping this would run in CMD as well when compiled, so I could make a bat file to make the program run in CMD as well.
Edit:
Here is the whole version class:
import java.util.Scanner;
public class version{
public static String input;
public static Scanner s = new Scanner (System.in);
public static void main (String [] args ) {
System.out.println("========================");
System.out.println("ANAGRAM MASTER VERSION 1.0");
System.out.println("Created by: Janrae Mendoza");
System.out.println("==========================");
System.out.println("Press the corresponding letters for your desired option: ");
System.out.println("<n> New Game");
System.out.println("<q> Quit Game");
input = s.nextLine();
if ("n".equalsIgnoreCase(input)) {
new open();
} else if ("q".equalsIgnoreCase(input)) {
System.exit(0);
}
}
}
while this is the open class:
import java.util.Random;
import java.util.Scanner;
public class open{
public String input;
public Scanner s = new Scanner (System.in);
public Random r = new Random();
//at least 25 words
public String scrambled[] = {"MICSECO", "LEPAIM", "ICHORE", "MLORTA", "TIEEXSUQI",
"MEERTO", "DESTOAK", "MLIBOE", "PHRAPARGA", "UALBILNGI", "DOXORTHRO",
"ZEIMESREM", "OKVEPRO", "ILAPRS", "TEMOED", "QUEMSADRAE", "LSEIMUP",
"CREUPRO", "BLRUNDE", "CKRENO", "UIPRSUT", "BINMEHLOGO", "DRKERA",
"SEACEDAP", "SOULEAZ"};
public String scrAns[] = {"ECONOMICS", "IMPALE", "HEROIC", "MORTAL", "EXQUISITE",
"REMOTE", "STOCKADE", "MOBILE", "PARAGRAPH", "BILINGUAL", "ORTHRODOX",
"MESMERIZE", "PROVOKE", "SPIRAL", "DEMOTE", "MASQUERADE", "IMPULSE",
"PROCIRE", "BLUNDER", "RECKON", "PURSUIT", "HEMOGLOBIN", "DARKER",
"ESCAPADE", "ZEALOUS"};
public int word;
public boolean stop = false;
public int scrnum;
public int timesplayed;
public void sleep() {
try {
Thread.sleep(1000);
} catch (Exception e) {}
}
public open() {
while (stop == false) {
sleep();
System.out.println("Guess out the scrambled word!");
word = r.nextInt(24);
scrnum = word;
System.out.println("ANAGRAM: " + scrambled[word]);
System.out.print("YOUR ANSWER: ");
input = s.nextLine();
if (input.equalsIgnoreCase(scrAns[scrnum])) {
System.out.println("You guessed the word right!");
System.out.println("Continue playing? <y> Yes and any other keys for No");
input = s.nextLine();
if ("y".equalsIgnoreCase(input)) {
timesplayed++;
} else {
stop = true;
}
}
}
System.out.println("Thank you for trying out version 1 of this game! You played " + timesplayed
+ " times! Enjoy your day, player!");
}
}
As per your question , I can see that you have created two classes and they are
where from you are getting “titleScreen” class ?
You have main method only in version.class .
So , the main() method of the version.class can only be the entry point .
You can run the program in like the following :
java version titleScreen
titleScreen can be the input of this program.