4 Replies - 967 Views - Last Post: 13 April 2008 - 11:38 AM Rate Topic: -----

#1 dreamer1963  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 31-March 08

Only 1 error left and I can't figure it out!

Post icon  Posted 11 April 2008 - 10:18 PM

This is supposed to give 3 quizzes each time and randomly select them. I have 1 error and can not figure it out.
/*Author: Plynia Welty
Random Quizzes
April 8, 2008
*/

import java.io.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Random;
import java.util.Scanner;

 class Randomquiz
{
	Scanner input = new Scanner (System.in);
	String start = input.next();


	String Randomquiz;
	String answer;



public static void main(String[]args) throws IOException;
	{
	Random quizzes = new Random quiz;
	 Randomgenerator = new Random();
					int r1 = generator.next; Int(3);
					int r2 = generator.next; Int(3);
					int r3 = generator.next; Int(3);
					int r4 = generator.next; Int(3);
					int r5 = generator.next; Int(3);
					int r6 = generator.next; Int(3);
					int r7 = generator.next; Int(3);
					int r8 = generator.next; Int(3);
					int r9 = generator.next; Int(3);
					int r10 = generator.next; Int(3);
	}

	  public Random Quizzes() throws IOException
	  {

	 	 BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
	 	 String getAnswer=null;

	 	 System.out.println("Welcome to Random Quizzes");

	 		String[] quiz = new String[10];


	 			 quiz[0] = "1. How many days in leap year?"+("\na)365 b)465 c)366 d)364\n");

	 	 System.out.println(quiz[0]);
	 	 getAnswer=keyboard.readLine();

	 	 if (getAnswer.equals("c"))
	 	 {
	 	 System.out.println("\n You are right!\n");

	 	 }
	 	 	else
	 	 	{
	 	 	System.out.println("Always a day behind huh? The right answer is c=366 .\n");
	 	 	}

	quiz[1] ="2. What is the name of this class?"
	+"\na)Java Programming 1 b)Headaches 101 c)I am so lost d)Major changer";

	System.out.println (quiz[1]);

	getAnswer = keyboard.readLine();

		if(getAnswer.equals("a"))
		{
		System.out.println("\n Well, that is the technical name at least.\n");
		}
			else
			{
			System.out.println("The politically correct answer is a=Java Programming 1.\n");


  quiz[2] = "3. Finish this quote The grass is always greener......."+"\na)over the septic tank b)on the other side c)when it rains d)if it is planted right";

	  System.out.println(quiz[2]);

	  getAnswer = keyboard.readLine();

		  if(getAnswer.equals("b"))
		  {
		  System.out.println("\n Well, of course\n");
		  }
			  else
			  {
			  System.out.println("Are you serious?! Try b=on the other side.\n");
			  }


  quiz[3] = "4. What is your name?"
	  +"\na)I do not know b)I do not care c)You tell me d)None of the above";
	  System.out.println(quiz[3]);


	  getAnswer = keyboard.readLine();

			  if(getAnswer.equals("d"))
			  {
			  System.out.println("\n Good job!\n");
			  }
				  else
				  {
				  System.out.println("Now you are being silly. Try d)None of the above.\n");
				  }

   quiz[4]= "5. What are humans called?"
	+"\na) homogonized b)homogenious c)homosapiens d)uhh, what?";
	System.out.println(quiz[4]);


		getAnswer = keyboard.readLine();

					  if(getAnswer.equals("c"))
					  {
					  System.out.println("\n Way to go!\n");
					  }
						  else
						  {
						  System.out.println("You are the weakest link! Try c)homosapiens.\n");
				  }

	 quiz[5]= "6. What color is the Pink Panther?"
	 +"\na) pink b)blue c)green d)red";
	 System.out.println(quiz[5]);

		getAnswer = keyboard.readLine();

							  if(getAnswer.equals("a"))
							  {
							  System.out.println("\n Certainly!\n");
							  }
								  else
								  {
								  System.out.println("Duh! I told you he was pink! Try a)pink.\n");
				  }


		  quiz[6]= "7. In the Pepsi logo where is the red located at?"
			 +"\na)top b)bottom c)middle d)letters";
			 System.out.println(quiz[6]);

				getAnswer = keyboard.readLine();

									  if(getAnswer.equals("a"))
									  {
									  System.out.println("\n Wow! A Pepsi-holic!\n");
									  }
										  else
										  {
										  System.out.println("Don't sweat it, I had to look too! Try a)top.\n");
				  }


		  quiz[7]= "8. In the Lord of the Rings, what was Gandolf's horse named?"
			 +"\na)Shadowfax b)Overlord c)Day Dreamer d)My Precious";
			 System.out.println(quiz[7]);

						getAnswer = keyboard.readLine();

											  if(getAnswer.equals("a"))
											  {
											  System.out.println("\n You have won a free spell!\n");
											  }
												  else
												  {
												  System.out.println("Watch movies much? Try a)Shadowfax.\n");
				  }


			  quiz[8]= "9. What is a Phoenix?"
					 +"\na)School b)town c)mental institution d)mythical fire bird";
					 System.out.println(quiz[8]);

						getAnswer = keyboard.readLine();

											  if(getAnswer.equals("d"))
											  {
											  System.out.println("\n Yee Haw!\n");
											  }
												  else
												  {
												  System.out.println("Where have you been? In a cave! Try d)mythical fire bird.\n");
						  }


				  quiz[9]= "10. In the original Hobbitt movie, what was the name of Bilbo Baggins' sword??"
						   +"\na)Stingtop b)Swarm c)Precious d)Excalibur";
						   System.out.println(quiz[9]);

							  getAnswer = keyboard.readLine();

													if(getAnswer.equals("a"))
													{
													System.out.println("\n Excellent!\n");
													}
														else
														{
														System.out.println("Hmmm, I see trivial pursuit is not you cup of tea. Try a)Sting.\n");
								}


	System.out.println("Thank you for shopping at the Headbangers Cafe");

	}

}
}



Error message is...
line 25: '(' or'[' expected
Random quiz = new Random quiz
^

Is This A Good Question/Topic? 0
  • +

Replies To: Only 1 error left and I can't figure it out!

#2 skin_  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 33
  • Joined: 05-April 08

Re: Only 1 error left and I can't figure it out!

Posted 11 April 2008 - 11:30 PM

I'm very new, but shouldn't it be:
Random quiz = new Random();

Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5186
  • View blog
  • Posts: 13,916
  • Joined: 18-April 07

Re: Only 1 error left and I can't figure it out!

Posted 11 April 2008 - 11:36 PM

Hello dreamer,

You got quite a few things wrong with this program that I want to show you. First of all, the way you are setting up your random generator is not right. First take out the line referring to quizzes since you never end up using it anyways from what I can tell. Then you need to setup the generator variable like this....

// Notice the space between Random and generator
Random generator = new Random();

// Next to get our random integers, we call nextInt(). 
// This is all one word. Continue this all the way through to r10

int r1 = generator.nextInt(3);
int r2 = generator.nextInt(3);
int r3 = generator.nextInt(3);
...
int r10 = generator.nextInt(3);



But then the problem is, you close off the main function. So once you have setup your random numbers here in main, the program ends without having done anything else. Perhaps you meant to call the function quizzes?

The function quizzes has been defined to return a Random object as shown here....

// Notice the use of the word Random here means that this function 
// will return a result as a Random object. But your function never 
// returns anything (using the return statement) nor are you even trying
// to use it to return anything... you should probably make this "void"

public Random Quizzes() throws IOException



Now the overall design of the program could use some refinement, but after we fix these errors we can see what else pops up for you and help you get past those as well.

:)
Was This Post Helpful? 0
  • +
  • -

#4 dreamer1963  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 31-March 08

Re: Only 1 error left and I can't figure it out!

Posted 12 April 2008 - 12:07 AM

/*Author: Plynia Welty
Random Quizzes
April 8, 2008
*/

import java.io.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Random;
import java.util.Scanner;

class Randomquiz
{
	Scanner input = new Scanner (System.in);
	String start = input.next();


	String Randomquiz;
	String answer;


public static void main(String[]args) throws IOException;
	{

	// Notice the space between Random and generator
	Random generator = new Random();

	// Next to get our random integers, we call nextInt().
	// This is all one word. Continue this all the way through to r10

	int r1 = generator.nextInt(3);
	int r2 = generator.nextInt(3);
	int r3 = generator.nextInt(3);
	int r4 = generator.nextInt(3);
	int r5 = generator.nextInt(3);
	int r6 = generator.nextInt(3);
	int r7 = generator.nextInt(3);
	int r8 = generator.nextInt(3);
	int r9 = generator.nextInt(3);
	int r10 = generator.nextInt(3);

}

public void Random  quiz() throws IOException;
	  {

		  BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));
		  String getAnswer=null;

		  System.out.println("Welcome to Random Quizzes");

			 String[] quiz = new String[10];


				  quiz[0] = "1. How many days in leap year?"+("\na)365 b)465 c)366 d)364\n");

		  System.out.println(quiz[0]);
		  getAnswer=keyboard.readLine();

		  if (getAnswer.equals("c"))
		  {
		  System.out.println("\n You are right!\n");

		  }
			  else
			  {
			  System.out.println("Always a day behind huh? The right answer is c=366 .\n");
			  }

	quiz[1] ="2. What is the name of this class?"
	+"\na)Java Programming 1 b)Headaches 101 c)I am so lost d)Major changer";

	System.out.println (quiz[1]);

	getAnswer = keyboard.readLine();

		if(getAnswer.equals("a"))
		{
		System.out.println("\n Well, that is the technical name at least.\n");
		}
			else
			{
			System.out.println("The politically correct answer is a=Java Programming 1.\n");


  quiz[2] = "3. Finish this quote The grass is always greener......."+"\na)over the septic tank b)on the other side c)when it rains d)if it is planted right";

	  System.out.println(quiz[2]);

	  getAnswer = keyboard.readLine();

		  if(getAnswer.equals("b"))
		  {
		  System.out.println("\n Well, of course\n");
		  }
			  else
			  {
			  System.out.println("Are you serious?! Try b=on the other side.\n");
			  }


  quiz[3] = "4. What is your name?"
	  +"\na)I do not know b)I do not care c)You tell me d)None of the above";
	  System.out.println(quiz[3]);


	  getAnswer = keyboard.readLine();

			  if(getAnswer.equals("d"))
			  {
			  System.out.println("\n Good job!\n");
			  }
				  else
				  {
				  System.out.println("Now you are being silly. Try d)None of the above.\n");
				  }

   quiz[4]= "5. What are humans called?"
	+"\na) homogonized b)homogenious c)homosapiens d)uhh, what?";
	System.out.println(quiz[4]);


		getAnswer = keyboard.readLine();

					  if(getAnswer.equals("c"))
					  {
					  System.out.println("\n Way to go!\n");
					  }
						  else
						  {
						  System.out.println("You are the weakest link! Try c)homosapiens.\n");
				  }

	 quiz[5]= "6. What color is the Pink Panther?"
	 +"\na) pink b)blue c)green d)red";
	 System.out.println(quiz[5]);

		getAnswer = keyboard.readLine();

							  if(getAnswer.equals("a"))
							  {
							  System.out.println("\n Certainly!\n");
							  }
								  else
								  {
								  System.out.println("Duh! I told you he was pink! Try a)pink.\n");
				  }


		  quiz[6]= "7. In the Pepsi logo where is the red located at?"
			 +"\na)top b)bottom c)middle d)letters";
			 System.out.println(quiz[6]);

				getAnswer = keyboard.readLine();

									  if(getAnswer.equals("a"))
									  {
									  System.out.println("\n Wow! A Pepsi-holic!\n");
									  }
										  else
										  {
										  System.out.println("Don't sweat it, I had to look too! Try a)top.\n");
				  }


		  quiz[7]= "8. In the Lord of the Rings, what was Gandolf's horse named?"
			 +"\na)Shadowfax b)Overlord c)Day Dreamer d)My Precious";
			 System.out.println(quiz[7]);

						getAnswer = keyboard.readLine();

											  if(getAnswer.equals("a"))
											  {
											  System.out.println("\n You have won a free spell!\n");
											  }
												  else
												  {
												  System.out.println("Watch movies much? Try a)Shadowfax.\n");
				  }


			  quiz[8]= "9. What is a Phoenix?"
					 +"\na)School b)town c)mental institution d)mythical fire bird";
					 System.out.println(quiz[8]);

						getAnswer = keyboard.readLine();

											  if(getAnswer.equals("d"))
											  {
											  System.out.println("\n Yee Haw!\n");
											  }
												  else
												  {
												  System.out.println("Where have you been? In a cave! Try d)mythical fire bird.\n");
						  }


				  quiz[9]= "10. In the original Hobbitt movie, what was the name of Bilbo Baggins' sword??"
						   +"\na)Stingtop b)Swarm c)Precious d)Excalibur";
						   System.out.println(quiz[9]);

							  getAnswer = keyboard.readLine();

													if(getAnswer.equals("a"))
													{
													System.out.println("\n Excellent!\n");
													}
														else
														{
														System.out.println("Hmmm, I see trivial pursuit is not you cup of tea. Try a)Sting.\n");
								}


	System.out.println("Thank you for shopping at the Headbangers Cafe");

	}

}
}



Ok. I fixed things. Still getting error on line 44 expected '(' or '['

I am really confused on this one. Sorry. for not returning. How would I do that?
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Only 1 error left and I can't figure it out!

Posted 13 April 2008 - 11:38 AM

View Postdreamer1963, on 12 Apr, 2008 - 12:07 AM, said:

import java.io.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Random;
import java.util.Scanner;


// there should not be a ";" after IOException
public static void main(String[]args) throws IOException;
	{
	int r1 = generator.nextInt(3);
	int r2 = generator.nextInt(3);
				....
	int r8 = generator.nextInt(3);
	int r9 = generator.nextInt(3);
	int r10 = generator.nextInt(3);

}
// BTW you defined r1 to r10 but they are never used..... some logic missing here

// spaces between "Random" and "quiz"
// no ";" at the end of the line
public void Random  quiz() throws IOException;
	  {

		  BufferedReader keyboard= new BufferedReader(new InputStreamReader(System.in));


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1