I am following along with JAVA book for CS101 and trying to wrap my head around this exercise, but when I run my code, I keep getting this error
Error: Could not find or load main class Riddle
Caused by: java.lang.ClassNotFoundException: Riddle
JAVA CODE
public class Riddle{
private String question; //instance variables
private String answer;
public Riddle( String q, String a) //constructor
{
question = q;
answer = a;
}
public String getQuestion() //instance method
{
return question;
}
public String getAnswer()
{
return answer;
}
}
public class RiddleUser{
public static void main ( String argv [] ){
Riddle riddle1= new Riddle (
"What is black and white and red all over?",
"An embarrassed zebra.");
Riddle riddle2= new Riddle (
"What is black and white and read all over?",
"A newspaper." );
System.out.println("Here are two riddles:");
System.out.println(riddle1.getQuestion());
System.out.println(riddle2.getQuestion());
System.out.println("The answer to the first riddle is:");
System.out.println(riddle1.getAnswer());
System.out.println("The answer to the second riddle is:");
System.out.println(riddle2.getAnswer());
}
}
Here is the exercise I am doing, I also uploaded the PDF of the book, the exercise is on pages 71-73. Basically, it wants to show you how to write a class and test it, If I am getting this correctly.