Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Making a Java quiz with Classes

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Making a Java quiz with Classes

    I have to make yet another quiz and I am COMPLETELY lost.
    I have to make use of classes, so one java file that uses the class file of another java code that tells the other what to do.

    I have one class file containing:
    /**
       Rectangle class, phase 3
       Under construction!
    */
     
    public class FillInBlank
    {
       private String question;
       private String answer;
       private String cans; // correct ans
       private String gans; // given ans
     
    /**		Constructor
    */
     
    	public FillInBlank(String Q, String A) // Question and Answer
    		{
    			question = Q;
    			cans = A;
    		}
     
       public String getQuestion()
       {
          return question;
       }
     
       public String getcans()
       {
          return cans;
       }
     
       public String getgans()
       {
          return gans;
       }
     
    	public void setans(String correctAns)
    	{
    		cans = correctAns;
    	}
     
       public boolean check()
       {
    	if (gans.equals(cans))
    		return true;
    	else
    		return false;
     
    	}
     
    	//needs setter for given ans
    }

    Then I have another java file that has the actual quiz in it but I am SO lost of where to go from here

    import java.util.Scanner;
     
    public class HW7
    {
       public static void main(String[] args)
       {
    	String input;
    	Scanner keyboard = new Scanner(System.in);
     
     
        FillInBlank Q1 = new FillInBlank("What programming lang?","java");
        FillInBlank Q2 = new FillInBlank("what command makes summary","javadoc");
     
          System.out.println(Q1.getQuestion());
    	  input = keyboard.nextLine();
     
    }

    How do I get a user's answer and how do I output if it's correct or not.
    I am sorry if I am being very vague but to be honest not even I understand what my professor wants this week.


  2. #2
    Member
    Join Date
    Mar 2012
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Making a Java quiz with Classes

    I would have it show a GUI to make things a bit easier
    I would have in that gui your question on top then 4 buttons which can lead to new windows and one which will go to the next window and also have the answer next to the button.
    Good luck

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Making a Java quiz with Classes

    How do I get a user's answer
    If this is a console window application, you can use one of the next... methods of the Scanner class to read input from a user.

    Then use an if statement to test if the input is correct.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Making A Quiz With Loops, Incompatible Type Error
    By diagnonsense in forum Java Theory & Questions
    Replies: 3
    Last Post: February 17th, 2012, 05:50 PM
  2. Free Java quiz .
    By skoiloth in forum Totally Off Topic
    Replies: 11
    Last Post: January 9th, 2012, 11:16 AM
  3. AppInventor Quiz App
    By FA2 in forum The Cafe
    Replies: 4
    Last Post: October 10th, 2011, 03:03 PM
  4. [SOLVED] Addition Quiz
    By javaneedhelp in forum Loops & Control Statements
    Replies: 5
    Last Post: October 9th, 2011, 12:55 AM
  5. Quiz application
    By JonoF in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: May 10th, 2010, 06:06 AM