I am trying to make a multiple choice quiz that includes a "for" and a "do-while" statement as well as a "switch" statement. I understand that the current do-while statements that are in the code are not needed, but they were an attempt to squeeze them in somehow. I have been doing research on these loops and understand how they work, but am not sure how to make them work in this situation.
As of right now the quiz application works perfectly, and does exactly what I want it to do, I just want to include a for loop and make better use of a do-while loop. Any suggestions would be greatly appreciated. Thanks.
import java.util.Scanner;
public class quiz4
{
public static void main (String []args)
{
System.out.println( "WELCOME TO THE QUIZ\n");
int c = 0;
Scanner scan = new Scanner ( System.in );
System.out.println( "What Language is this coded in?" );
System.out.println( "1 = C++");
System.out.println( "2 = C#");
System.out.println( "3 = PC");
System.out.println( "4 = Java");
String in;
in = scan.nextLine();
if (in.equals("4"))
{
do
{
System.out.println("Correct\n");
c++;
}
while (c>1);
}
else
{
System.out.println("wrong\n");
}
System.out.println( "What is the capital of Montana?" );
System.out.println( "1 = Big Sky");
System.out.println( "2 = Helena");
System.out.println( "3 = Missoula");
System.out.println( "4 = Billings");
in=scan.nextLine();
if (in.equals("2"))
{
do
{
System.out.println("Correct\n");
c++;
}
while (c>2);
}
else
{
System.out.println("wrong\n");
}
System.out.println( "What color is the sky?" );
System.out.println( "1 = Orange");
System.out.println( "2 = White");
System.out.println( "3 = Blue");
System.out.println( "4 = Red");
in=scan.nextLine();
if (in.equals("3"))
{
do
{
System.out.println("Correct\n");
c++;
}
while (c>3);
}
else
{
System.out.println("wrong\n");
}
System.out.println( "What year is it?" );
System.out.println( "1 = 1994");
System.out.println( "2 = 1776");
System.out.println( "3 = 2012");
System.out.println( "4 = 3033");
in=scan.nextLine();
if (in.equals("3"))
{
do
{
System.out.println("Correct\n");
c++;
}
while (c>4);
}
else
{
System.out.println("wrong\n");
}
System.out.println( "What is the name of our current president?" );
System.out.println( "1 = Barrack Obama");
System.out.println( "2 = Bill Clinton");
System.out.println( "3 = Mitt Romney");
System.out.println( "4 = Ron Paul");
in=scan.nextLine();
if (in.equalsIgnoreCase("1"))
{
do
{
System.out.println("Correct\n");
c++;
}
while (c>5);
}
else
{
System.out.println("wrong\n");
}
System.out.println("You answered " + c + " out of 5 correctly");
System.out.println("Your Score is " + 100 * c/5 + "%");
int answer;
answer = c;
switch (answer)
{
case 0:
System.out.println ("Were you even trying?");
break;
case 1:
System.out.println ("Time to brush up on your knowledge");
break;
case 2:
System.out.println ("Time to brush up on your knowledge");
break;
case 3:
System.out.println ("Time to brush up on your knowledge");
break;
case 4:
System.out.println ("Very Good");
break;
case 5:
System.out.println ("Excellent");
break;
}
}
}

New Topic/Question
Reply



MultiQuote



|