For this assigment, I need to create a java program on the command line. As part
ID: 3719882 • Letter: F
Question
For this assigment, I need to create a java program on the command line. As part of the arguments, the user will input the location of a file containing words and their definitions, separated by semi-colons. The program will be executed by using the javac command.
The words.txt file will have the following structure:
Java: A Programming Language
Recursive Functions: A recursive function (DEF) is a function which either calls itself or is in a potential cycle of function calls. As the definition specifies, there are two types of recursive functions.
Private: A private member is only accessible within the same class as it is declareda
Public: A public member is accessible to all classes (unless it resides in a module that does not export the package it is declared in).
The user will start your program and will be prompted to start a new game. A game consists of 5 questions asked. Your program must randomize the order in which the words will show up. Along with a question, the program will display another 4 randomly chosen answer choices, displayed like this:
What is the definition of Java:
a)A recursive function (DEF) is a function which either calls itself or is in a potential cycle of function calls. As the definition specifies, there are two types of recursive functions.
b)A Programming Language
c)A public member is accessible to all classes (unless it resides in a module that does not export the package it is declared in).
d)A private member is only accessible within the same class as it is declared
Answer: b
Your program must keep track of the correct and incorrect responses, and give feedback to the user after selecting a choice. If an incorrect answer was selected, you must show the correct response. After 5 questions have been asked, you will display their score along with the correct answers for each question.
Any help / ideas of how to complete this would be appreciated! Thank you!
Explanation / Answer
i have written PseudoCode and algorithm below:
define two arrayList :words and definitions
while(files is not empty)
{
read a line
split the line in to an array by colon to get word and definition
add the word into words arraylist
add definition in definitions arraylist
}
while(true)
{
for(int questionNumber=0;questionNumber<5;questionNumber++)
{
Random rand = new Random();
int correctIndex = rand.nextInt(words.size() + 1 - 0) + 0;
print what is definition of words.getIndex(correctIndex)
for(int option=0;option<4;option++)
{
boolean answerPrinted=false;
int randomDefinition=rand.nextInt(definitions.size() + 1 - 0) + 0;
if(correctIndex <randomDefinition)
{
print definition.getIndex(correctIndex)
answerPrinted=true
}
print definition.getIndex(randomDefinition)
if(answerPrinted==false)
{
print definition.getIndex(correctIndex)
}
get The user input
if(input=definition.getIndex(correctIndex))
{
corectResponses++
}
else
{
incorrectResponses++
print definition.getIndex(correctIndex) is the right answer
}
displayScore depending upon their Responses;
ask if the want to repeat or end the program
if(end)
{
break from infinte while loop
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.