I need to preface this with I am not allowed to use an IDE in class, I must use TextPad to compile and run. Any help would be greatly appreciated.
There are two files associated with this assignment, one called Lab5 and the data file called StateCapitals. When I compile the program, I get the following errors. I "think" it cant find the files in the same folder, but they are.
The purpose of the assignment is to generate a dialog box that asks for the capital of a randomly chosen state from the StateCapitals file. If the answer matches the data in the array contained in that file, the dialog box closes and a new one opens telling the user that the answer is correct or wrong whichever is applicable. Once the user has had 10 attempts, the program displays a new dialog box with the number of correct and wrong answers.
Program Code:
import java.util.*;
import javax.swing.*;
import java.util.Random;
public class Lab5
{
public static void main(String[] args)
{
StateCapitals caps = new StateCapitals();
String [][] stateCapital = caps.GetCapital();
Random rand = new Random();
String [][] answer = new String [49][2];
int col = 0;
// Declare the variables
String stateName = "";
int count = 0;
String capital = "";
int correct = 0;
int wrong = 0;
// Create a scanner
Scanner input = new Scanner(System.in);
while (count < 10)
{
int randNum = rand.nextInt (48) + 1;
// Input box for the capital
String stateCapitalQuestionString = JOptionPane.showInputDialog(
"What is the capital of " + stateCapital[randNum][0] + "?");
capital = input.next();
if (capital.matches(stateCapital[randNum][1]))
{
String stateCapitalRespString = JOptionPane.showInputDialog(
"That is CORRECT!");
correct++;
}
else
{
String stateCapitalRespString = JOptionPane.showInputDialog(
"Incorrect Response!");
wrong++;
}
count++;
}
String stateCapitalSummaryString = JOptionPane.showInputDialog(
("You answered " + correct + "correctly!\n) (There were " + wrong + "incorrect answers."));
}
}
Compile Error:
F:\Java\Lab 5\Lab5.java:14: error: cannot find symbol
StateCapitals caps = new StateCapitals();
^
symbol: class StateCapitals
location: class Lab5
F:\Java\Lab 5\Lab5.java:14: error: cannot find symbol
StateCapitals caps = new StateCapitals();
^
symbol: class StateCapitals
location: class Lab5
Any help would be appreciated! Thanks!
javac ...I am not allowed to use an IDE in class,but you are allowed to ask other people to help you by using their IDEs, or do I have to use TextPad too?