Question

In: Computer Science

Write this program using an IDE. Comment and style the code according to the CS 200...

Write this program using an IDE. Comment and style the code according to the CS 200 Style Guide. Submit the source code files (.java) below. Make sure your source files are encoded in UTF-8. Some strange compiler errors are due to the text encoding not being correct.

Monster collector is a game of chance, where the user tries to collect monsters by guessing the correct numbers between 1 and 5. If the user doesn't guess the incorrect number, you catch the monster, otherwise, it gets away!

Example output:

Welcome to Monster Collector, collect 2 monsters to win!
A wild pikamoo appears! Guess a number between 1 and 5
5
You almost had it, but the monster escaped.
A wild bulbaroar appears! Guess a number between 1 and 5
1
Congratulations, you caught bulbaroar!
There are no more monsters to encounter!
You caught 1 monsters of 2
Keep training to be the very best!
Welcome to Monster Collector, collect 2 monsters to win!
A wild pikamoo appears! Guess a number between 1 and 5
3
Congratulations, you caught pikamoo!
A wild bulbaroar appears! Guess a number between 1 and 5
1
Congratulations, you caught bulbaroar!
There are no more monsters to encounter!
You caught 2 monsters of 2
You're the monster collector master!

A more detailed explanation of the requirements for each method will be in the method header comments - please follow these closely. Suggested order of completion: getMonster(), catchMonster(), printResult() then main().

Config.java contains an array of monsters, and the seed for your random number generator.

Solutions

Expert Solution

Implementation in JAVA;

// import scanner class
import java.util.Scanner;

//class config.java
public class Config {

//   main method
   public static void main(String[] args) {
      
  
       System.out.println();

//       String monster array
       String monster[]= {"wild bulbaroa","Werewolf Mask","wild pikamoo","Giant Squid","Chupacabra."};
      
//       generating random numbers in range of 1 to 5
//       num is number of cases
       int num = (int) (Math.random() * (5 - 1 + 1) + 1);
     
       System.out.println("Welcome to Monster collector , collect "+num+" monsters to win !");
      
       System.out.println();
      
//       call get monster method
//       it return the results by the help of catchmonster() method
       int result=get_monster(monster,num);
      
       System.out.println();
      
//       print result
       print_result(num,result);
      
      
      
      
   }
  
//   get monster method
//   it return the results by the help of catchmonster() method
   public static int get_monster(String monster[],int num) {
      
      
       int result=0;
          
//       will run no. of cases
           while(num>0) {
              
//               generate random number for monster
               int mon= (int) (Math.random() * (5 - 1 + 1) + 1);
              
               String monst = monster[mon-1];
              
               System.out.println("A "+monst+" appers! Guess a number between 1 and 5 ");
              
//               call catchmonster method if catch result will increase by 1
           if(catchMonster(monster,mon)) {
              
               result++ ;
              
           }
          
           System.out.println();
          
           num--;
              
           }
          
           System.out.println("There are no more monsters to encounter!");
          
       return result;  
          
    }

//   boolean catchMonster method will return true if the user entered guess
//   and the argumrnted num are equal i.e user guess correctly
//   else return false
   public static boolean catchMonster(String monster[], int num) {
  
       Scanner s= new Scanner(System.in);
      
       int guess=s.nextInt();
      
       if(guess==num) {
          
           System.out.println("Congratulations, you caught "+monster[num-1]+"!");
           return true;
       }
      
       else {
          
           System.out.println("You almost had it, but the monster escaped.");
           return false;
       }
   }
  
//   print the result of game
   public static void print_result(int num, int result) {
      
       if(num==result) {
           System.out.println("You caught "+result+" monsters of "+num);
           System.out.println("You're the monster collector master!");
          
       }
      
       else {
           System.out.println("You caught "+result+" monsters of "+num);
           System.out.println("Keep training to be the very best!");
          
       }
      
   }
  
  
  
}

// NOTE: As per mentioned in question monsters are set by using random number generated by random generator with in given range. we only check the guess (correct / incorrect).

SAMPLE OUTPUT:

1.

2.

3.

// PLEASE THUMBS-UP AND RATE POSITIVELY
If you have any doubt regarding this question please ask me in commnets
// THANK YOU:-)


Related Solutions

Write code using the Arduino IDE that compiles with no errors. 2-bit adder: The code must...
Write code using the Arduino IDE that compiles with no errors. 2-bit adder: The code must read two digital input signals and turn on two LEDS as needed to show the sum of the inputs. e.g. 0 + 1 = 01.
Write a Program using MPLAB IDE and XC8 compiler to do the followings: 1. When the...
Write a Program using MPLAB IDE and XC8 compiler to do the followings: 1. When the Program Starts it should send your Name and ID# to the Serial Port 2. Display the result on Tera Term. 3. Read PORTB buttons in an infinite loop (Main Loop which is the Read Buttons Loop), your program should not block when reading the Buttons except in De-bouncing.. But you need to de-bounce each button when pressed 3.1 If the user presses PORTB, RB0...
write code in java and comment. thanks. the program is about interface . Implement the basics...
write code in java and comment. thanks. the program is about interface . Implement the basics of Fitness and types of Fitness: Aerobic. Implement specific Fitness types such as Swimming, Cycling, Fitness Task: public interface Fitness (10pts) This will be used as a starting point for deriving any specific Fitness type. Every fitness exercise type has one or more muscle group it affects. Therefor a Fitness has the following abstarct method (Note that all methods in an interface are abstract...
Control DC Using PIC18f46k20 and MPLAB IDE v8.8, write a program that can 1. Start and...
Control DC Using PIC18f46k20 and MPLAB IDE v8.8, write a program that can 1. Start and Stop the motor 2.Vary The motor Speed 3.Change the direction of the motor rotation 4.Display motor speed in OLED screen using c of MPLAB IDE v8.8 please test the code before posting
Using ECLIPSE IDE Write a Java Program to play your version of the Texas Pick 3...
Using ECLIPSE IDE Write a Java Program to play your version of the Texas Pick 3 Lottery. You will need to include the provided code given below in your program. Task:The program will prompt for a number between 0 and 999. Your program will display the number of attempts it took for the entered number to match a randomly generated number. In the main() method, declare an int named myPick3choice. Create a prompt for myPick3choice as "Enter your Pick 3...
Write code in C language in the Arduino IDE ADC data using Serial plotter Serial plot...
Write code in C language in the Arduino IDE ADC data using Serial plotter Serial plot : raw data, delay data (int) Purpose: Delay Block (**Using Class**) Input : u(t) Output : o(t)=u(t-h) sample time=0.02 Delay (h) = 0.4
Q20. Using C++ style string to write a program that reads a sentence as input and...
Q20. Using C++ style string to write a program that reads a sentence as input and converts each word of the sentence following the rule below: For every word in the sentence, the first letter is relocated the end of the word. Then append the string “KPU” to the word. More requirements: All letters in the output should be uppercase. More assumptions: The input sentence contains no non-alphabetic letters Sample Run: Please enter the original sentence: i LOVE to program...
Q20. Using C++ style string to write a program that reads a sentence as input and...
Q20. Using C++ style string to write a program that reads a sentence as input and converts each word of the sentence following the rule below: For every word in the sentence, the first letter is relocated the end of the word. Then append the string “KPU” to the word. More requirements: All letters in the output should be uppercase. More assumptions: The input sentence contains no non-alphabetic letters Sample Run: Please enter the original sentence: i LOVE to program...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code...
write a program for the microcontroller-msp430fr6989 using code composer studio not assembly language. write a code that transmits a single character and lights the red LED upon receiving that character. The board will "talk" to itself. The green LED should turn on whenever a message is sent and the LCD will display the message being received.
(Full Program)Write code that shows how deadlocks work. Then write code that shows a fix using...
(Full Program)Write code that shows how deadlocks work. Then write code that shows a fix using semaphores. (Full program)Write code showing the elevator algorithm. c++ Language
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT