Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

List at least 5 test cases for your final project. Include testing scenarios. Example: 1) Validate the main menu input Test variable: mainMenuChoice Test values:

List at least 5 test cases for your final project. Include testing scenarios.

Example: 1) Validate the main menu input Test variable: mainMenuChoice Test values: 1, 2, 3, 5, a

Could you please help me run 5 tests on the code provided and use the example given as well in the tests?

/*Filename:

*name: Andre Chung, Victoria Liong-A-San

*6/1/20

*Description: This program will help the user to review topics from chapter 1-2 in a question answer point system format

*

*documentation

*added 3 names and 3 scores to highscore text file

*added 2 questions

*modified method, proccess question, readinhighscore, comparehighscore

*/

package project;

import java.io.*;

import java.util.Scanner;

/* public static char displayMainMenu()

{

String mainMenuChoice;

mainMenuChoice = JOptionPane.showInputDialog(null, "main menu "

+ "1)see rules "

+ "2)play game "

+ "3)exit "

+ "Please enter the option you desire");

return mainMenuChoice;

*/

import javax.swing.JOptionPane;

public class Project {

final static int SIZE = 10;

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

//Declare a variables for input

double counter = 0.0;

String name, menuChoice;

String mainMenuChoice;

String [] line1= new String [SIZE], question = new String [SIZE], answerA= new String [SIZE], answerB = new String [SIZE],

answerC=new String [SIZE], answerD=new String [SIZE], correctAnswer=new String [SIZE], line8A= new String [SIZE];

int score=0, i=0, highscore=0, highScore= 0;

String [] highNames = new String [3];

int [] highScores = new int [3];

int [] pointValue= new int [SIZE];

//Display an introduction

JOptionPane.showMessageDialog(null, "Welcome user");

//prompt for user name

name = JOptionPane.showInputDialog(null, "Please enter your username:");

//display a hello to user

JOptionPane.showMessageDialog(null, "Hello " + name);

//display a menu main menu, see rules, play game, exit, prompt user to select an option

do {

mainMenuChoice =displayMainMenu();

if (mainMenuChoice.equals ("1"))

{

// call method display rules

displayRules();

}

else if (mainMenuChoice.equals ("2"))

{

score=processQuestion(line1, question, answerA, answerB, answerC, answerD, correctAnswer, pointValue, line8A);

// call method readInHighScore

readInHighScore(highNames, highScores);

// call method updateHighscores

updateHighscores(highNames, highScores);

// call method compareScore

compareScore(score, highScores, name, highNames);

}

else if (mainMenuChoice.equals ("3"))

{

System.exit(0);

}

else

{

JOptionPane.showMessageDialog(null, "Invalid. You must enter 1 - 3 from the menu.");

}}while (!mainMenuChoice.equals ("2"));

}

//return type: char

//parameter: none

//purpose: prompt for and display

public static String displayMainMenu() {

String mainMenuChoice;

mainMenuChoice = JOptionPane.showInputDialog(null, "main menu "

+ "1)see rules "

+ "2)play game "

+ "3)exit "

+ "Please enter the option you desire");

return mainMenuChoice;

}

//

//

//return type: void

//parameters: none

//purpose: this method is used to display the rules

public static void displayRules()

{

//display rule for the game

JOptionPane.showMessageDialog(null, "here are the rules of the game! "

+ "*you must answer each question correct to recieve points"

+ "*each question increases in points");

}

//return type: int

//parameters:

public static int processQuestion (String [] line1, String [] question, String [] answerA, String [] answerB, String [] answerC, String [] answerD, String [] correctAnswer, int [] pointValue, String [] line8A)

throws FileNotFoundException{

JOptionPane.showMessageDialog(null, "loading game");

//open file

File questionFile = new File("questions.txt");

Scanner questionRead = new Scanner(questionFile);

String menuChoice;

int score = 0;

for (int i=0; i<9; i++)

{

line1 [i]= questionRead.nextLine();

question [i] = questionRead.nextLine();

answerA [i] = questionRead.nextLine();

answerB [i] = questionRead.nextLine();

answerC [i] = questionRead.nextLine();

answerD [i] = questionRead.nextLine();

correctAnswer [i] = questionRead.nextLine();

pointValue [i] = questionRead.nextInt();

line8A [i] = questionRead.nextLine();

//change to more descriptive variables

//JOptionPane.showInputDialog(

//if input equals b, then give points idea

do

{

menuChoice = JOptionPane.showInputDialog (null, line1[i] + " " + question[i]+ " " +answerA[i]+ " " +answerB[i]

+ " " +answerC[i]+ " " + answerD[i]);

if (menuChoice.equals(correctAnswer[i]) || menuChoice.equals(correctAnswer[i].toLowerCase()))

{

score+=pointValue[i];

JOptionPane.showMessageDialog(null, "Correct ");

displayScore(score);

}

else if (!menuChoice.equals(correctAnswer[i]))

{

JOptionPane.showMessageDialog(null, "Wrong, the correct answer is, " + correctAnswer[i]);

displayScore(score);

}

}

while(!menuChoice.equals("A") && !menuChoice.equals("B")

&& !menuChoice.equals("C") && menuChoice.equals("D"));

}questionRead.close();

return score;

}

//return type: int

//parameter: none

//purpose: open highscore.txt, read in the highscore, close the file, return the highscore

public static void readInHighScore (String[] highName, int[] highScore)

throws FileNotFoundException

{

//String highName;

//int highScore;

//Declare a file for input, to open highscore.txt.

File highscoreRead = new File ("highscore.txt");

//declare the scanner, to read in, to read from the file

Scanner highscoreReadT = new Scanner (highscoreRead);

//read in the data from highscore.txt, add variable highscore

for (int i = 0 ; i <= 2; i++)

{

highName [i] = highscoreReadT.next();

highScore [i]= highscoreReadT.nextInt();

}

JOptionPane.showMessageDialog(null, "The current highest scores in the highscore board is: " + highName[0] +

" , " + highScore[0] + " "

+ highName[1] + " , " + highScore[1] + " "+ highName[2] + " , " + highScore[2] + " ");

//read then close, highscoreReadT.close();

}

//return type: void

//parameter: 2 (highScore, userScore)

//purpose: to compare and replace the highscore

public static void compareScore (int userScore, int [] highScore, String userName,String[] highName)

throws FileNotFoundException

{

//if statement

if (userScore > highScore [0])

JOptionPane.showMessageDialog(null, "you beat the highscore: " + userScore);

highName[2] = highName[1];

highScore [2]=+ highScore[1];

highName[1] = highName[0];

highScore [1]=+ highScore[0];

highName[0] = userName;

highScore [0]=+ userScore;

}

public static void updateHighscores(String [] highName, int [] highScore)

throws FileNotFoundException

{

//Declare a PrintWriter Object

PrintWriter highscoreWrite = new PrintWriter("highscore.txt");

highscoreWrite.print(highName[0] + " ");

highscoreWrite.print(highScore[0] + " ");

highscoreWrite.print(highName[1] + " ");

highscoreWrite.print(highScore[1] + " ");

highscoreWrite.print(highName[2] + " ");

highscoreWrite.print(highScore[2] + " ");

//close file

highscoreWrite.close();

}

//return type: void

//parameter: 1 (score)

//purpose: to display score after each question

public static void displayScore(int score)

{

JOptionPane.showMessageDialog(null, "your score is " + score);

}

// fourth option to display current highscore idea,

}

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_2

Step: 3

blur-text-image_3

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions