Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help. I cant make my code read my questions file using joption.pane. HOMEWORk File name: javaGamev4.java (3) Create an algorithm. (6) Create a

I need help. I cant make my code read my questions file using joption.pane. HOMEWORk

File name: javaGamev4.java (3) Create an algorithm. (6) Create a text file that saves the questions, 4 answers, correct answer and point value in a file called questions.txt. The file should contain only raw data and should use the following format for each question: Question1 Answer1A Answer1B Answer1C Answer1D Question1CorrectAnswer PointValue Example Data: questions.txt (10) Replace the code in your project that currently prompts for the questions separately with a for loop that completes the following tasks for each question: Read the data from the file Display the question and answers Prompt the user for an answer Determine if the user is correct/incorrect Display whether or not the user is correct Update the score accumulator What is the command to display a line of output on the screen? SystemOut.print() System.out.print() System.out.println() System.outPrintln() B 100

MY CODE

package teamProjectV3;

import java.util.Random;

import java.util.Scanner;

import java.io.*;

import javax.swing.JOptionPane;

public class teamProjectV3 {

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

// TODO Auto-generated method stub

// variables

String userName;

int menuChoice;

int score = 0;

String file_path = "C:\\Users\\aoliveira\\Documents\\Ana Oliveira personal\\SCHOOL\\questions.txt";

String menuDisplay = "Please choose from the following options: 1) See Rules 2) Play Game 3) Exit ";

String invalidMessage = "Invalid input! Choose 1, 2, or 3.";

String seeRules = ("1. Be honest to yourself. 2. Do not consult your books. . Do not search internet for answers.");

// intro

JOptionPane.showMessageDialog(null, "Hello and welcome to my game. This game will test your knowledge on Java");

//prompt player for name

userName = JOptionPane.showInputDialog("Please enter your name");

//Main Loops

do {

menuChoice = Integer.parseInt(JOptionPane.showInputDialog(null, menuDisplay));

//Validate main menu

if(menuChoice < 1 || menuChoice > 3) {

JOptionPane.showMessageDialog(null,invalidMessage);

menuChoice = Integer.parseInt(JOptionPane.showInputDialog(null, menuDisplay));

}

if(menuChoice == 1) {

JOptionPane.showMessageDialog(null, seeRules);

menuChoice = Integer.parseInt(JOptionPane.showInputDialog(null, menuDisplay));

}

if(menuChoice == 2) {

JOptionPane.showMessageDialog(null, "Play game."); // cant make this to work

// Random rand = new Random();

// int value = 0;

//

// File fr = new File(file_path);

// Scanner inputFile = new Scanner(fr);

// String line;

//

//

// while (inputFile.hasNext()) {

// line = inputFile.nextLine();

//

//

//prompt user multiple choice question

JOptionPane.showMessageDialog(null, line);

//accept user answer

//

String answer = JOptionPane.showInputDialog(null, line);

// Scanner keyboardInput = new Scanner(System.in);

// for(int i=0; i < line.length(); i++);

// //prompt user for question

// System.out.println(line);

// //accept user answer

// String answer = keyboardInput.nextLine();

}

//Close file reader

inputFile.close();

menuChoice = Integer.parseInt(JOptionPane.showInputDialog(null, menuDisplay));

}

}

while (menuChoice != 3); {

JOptionPane.showMessageDialog(null, "Bye " + userName);

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

Define capital intensity ratio, and explain its significance.

Answered: 1 week ago

Question

Describe Balor method and give the chemical reaction.

Answered: 1 week ago

Question

How to prepare washing soda from common salt?

Answered: 1 week ago

Question

Explain strong and weak atoms with examples.

Answered: 1 week ago

Question

Explain the alkaline nature of aqueous solution of making soda.

Answered: 1 week ago