Hi I am having major trouble with my homework If someone cou

Hi, I am having major trouble with my homework. If someone could help me with it, I would be greatly appreciative. This needs to be written in Java. Please no buffered readers and please do not use Java’s built in data structures or data functionality (Like sorting and searching), however stuff like java.util.scanner and wild cards like java.io.* and java.util.* are fine, but please remember I am very much a beginner at this and would much rather understand the material instead of doing it the easier way using built-in data structures. It would also be nice if you could do it in the way that is suggested because I understand that way pretty well, however it\'s not critical. Thanks in advance.

Objective:

Write a program which emulates the final game of a famous price related game show. The program must read from a file (prizeList.txt) and populate an array of 50 prizes. Each item has an associate name and price, which is in the file and also in the order named. The name and price are separated by a tab. The program must then randomly pick 5 items out of that array for the showcase showdown, in which repeated items are allowed. Then, the program must prompt the user with the names (individual prices hidden) of the prizes that have been randomly selected and ask them to enter the total cost closest without going over. Since there is not another contestant in this version of the game, the program must also check to see if the price guessed is within $2,000 of the actual retail price or else they lose as well. The game will continue until the user chooses to quit.

Suggested Methodology

You can solve this in any number of ways, and here\'s a way you may take to approach this problem.

3 Classes

Prize: This is a simple class which holds a single item from the list provided. As such it has two instance variables prize and name, and also all the accessors, mutators, and constructors associated with it.

Showcase: A more complex class which holds the arrays for the entire prize list and the randomly prize array that is the showcase. Each array uses the type Prize. This class must populate the entire prize array upon its construction from the file. Also the file contains each prize name and cost separated by a tab. A method for populating the showcase by randomly selecting items from the prize list is strongly recommended.

ShowcaseGame: This is the entire front end of the game. All of the users input and the prompts should go in this class which contains nothing more than a main method.

Example Dialog:

Welcome to the showcase show down!

Your prizes are:

milk

bread

car

car

car

You must guess the total cost of all without going over

Enter your guess

60000

You guessed 60000.0 the actual price is 60012.0

Your guess was under! You win!

Would you like to play again? Enter \'no\' to quit

yes

Welcome to the showcase show down!

Your prizes are:

moose

boat

bread

bread

bread

You must guess the total cost of all without going over

Enter your guess

40000

You guessed 40000.0 the actual price is 51021.0

I\'m sorry but that guess was bad. You lose for being bad.

Would you like to play again? Enter \'no\' to quit

yes

Welcome to the showcase show down!

Your prizes are:

milk

moose

cheese

cheese

boat

You must guess the total cost of all without going over

Enter your guess

200000

You guessed 200000.0 the actual price is 51015.0

I\'m sorry but that was over... You get nothing

Would you like to play again? Enter \'no\' to quit

no

Goodbye

Here is the contents of the text file \"prizeList.txt\"

Solution

CODE:

package temp;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Random;
import java.util.Scanner;

// Prize Class to hold prize amount and prize name.
class Prize{
  
   int prizeAmount;
   String name;
  
   // Accessors and Modifiers.
   public int getPrizeAmount() {
       return prizeAmount;
   }
   public void setPrizeAmount(int prizeAmount) {
       this.prizeAmount = prizeAmount;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
  
   // Constructor.
   public Prize(int prizeAmount, String name) {
       this.prizeAmount = prizeAmount;
       this.name = name;
   }  
}

// Showcase class
class Showcase{
  
   // Array of Prize class
   // Input file has 51 entries, so creating an array of size 52.
   Prize[] arr = new Prize[52];
  
   // Read from file.
   void readFile() throws FileNotFoundException{
      
       // Please specify the path to the file here.
       File file = new File(\"H:\\\\eclipse_workspace\\\\temp\\\\src\\\\temp\\\\prizeList.txt\");
      
       // readFile using Scanner.
       Scanner sc = new Scanner(file);
       int j = 0;
      
       // Read Till the end of File
       while(sc.hasNextLine()){
          
           // read a line
           String s = sc.nextLine();
           int data = 0;
           String name = \"\";
          
           // Split the line with white spaces.
           String[] ss = s.split(\"\\\\s\");
          
           // Try to split the data and feed it into Price object.
           for (int i=0;i<ss.length;i++){
               try{
                   data = Integer.parseInt(ss[i]);
               }
               catch(NumberFormatException e){
                   name += ss[i];
               }
           }
           Prize temp = new Prize(data, name);
           arr[j] = temp;
           j++;          
       }
       sc.close();
   }
  
   // Get the object based on the index.
   public Prize getArr(int index) {
       return arr[index];
   }
  
}

// Showcase class
public class ShowcaseGame {

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

       // Scanner class to read the user input.
       Scanner sn = new Scanner(System.in);
      
       // Create an object of Showcase class.
       Showcase sc = new Showcase();
       sc.readFile();
      
       System.out.println(\"Welcome to the showcase show down!\");
       System.out.println(\"Your prizes are:\");
      
       // TO generate randomNumber.
       Random rn = new Random();
       int totalPrizeAmount = 0;      
      
       // Generate randomNumber and display the results.
       for(int i=0;i<5;i++){
           int randomNumber = rn.nextInt(52);
           Prize temp = sc.getArr(randomNumber);
           int data = temp.prizeAmount;
           System.out.println(temp.name);
           totalPrizeAmount += data;          
       }
  
       System.out.println(\"You must guess the total cost of all without going over\");
       System.out.println(\"Enter your guess\");
       int guess = sn.nextInt();
       System.out.println(\"You guessed \" + guess + \" the actual price is \" + totalPrizeAmount);
      
       if(guess < totalPrizeAmount){
           System.out.println(\"Your guess was under! You win!\");
       }
       else{
           System.out.println(\"I\'m sorry but that guess was bad. You lose for being bad.\");
       }
          
       sn.close();
   }
}

OUTPUT:

Welcome to the showcase show down!
Your prizes are:
Cereal
Bread
PairofScooters
PinballMachine
Banjo
You must guess the total cost of all without going over
Enter your guess
546
You guessed 546 the actual price is 3631
Your guess was under! You win!

Hi, I am having major trouble with my homework. If someone could help me with it, I would be greatly appreciative. This needs to be written in Java. Please no b
Hi, I am having major trouble with my homework. If someone could help me with it, I would be greatly appreciative. This needs to be written in Java. Please no b
Hi, I am having major trouble with my homework. If someone could help me with it, I would be greatly appreciative. This needs to be written in Java. Please no b
Hi, I am having major trouble with my homework. If someone could help me with it, I would be greatly appreciative. This needs to be written in Java. Please no b
Hi, I am having major trouble with my homework. If someone could help me with it, I would be greatly appreciative. This needs to be written in Java. Please no b

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site