Question

PSEUDOCODE AND JAVA SOURCE CODE PLEASE: Program 1 (60 pts): Find the Rabbit! For this assignment,...

PSEUDOCODE AND JAVA SOURCE CODE PLEASE:

Program 1 (60 pts): Find the Rabbit! For this assignment, you will write a program that asks the user to find a rabbit in one of 10 holes (0-9). The holes and guesses are visualized on the screen (as shown below), but as the user guesses, you should not show where the rabbit is hidden. The rabbit is assigned a random hole each time the program is run. You must write and use at least two functions for this question (maybe printing as one?). Further, you should actually use the array to solve this problem (i.e. not “hack your way” through it). Design (pseudocode) and implement (source code) this program. Extra credit (5 pts): if the user guesses the correct hole, show the rabbit with the letter ‘R’.

Sample run

Find the Rabbit!

| | | | | | | | | | |

Pick a hole (0-9): 9

| | | | | | | | | |X|

Pick a hole (0-9): 6

| | | | | | |X| | |X|

Pick a hole (0-9): 4

| | | | |X| |X| | |X|

Pick a hole (0-9): 3

| | | |R|X| |X| | |X|

You found the rabbit!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.*;
import java.util.*;
class A{
   public static void main(String[] args)
   {
       Random rand = new Random();
       int r=rand.nextInt(10);//random value between 0 to 9
       int A[]=new int[10];
       for (int i=0;i<10 ;i++ )
       {
           A[i]=0;  
       }
       A[r]=1;//rabbit's location
       System.out.println("Find the Rabbit!");
       System.out.print("|");
       for (int i=0; i<10;i++)
           {
               System.out.print(" |");
           }
       System.out.println();
       int c=10;
       while(c>0)
       {
           System.out.print("Pick a hole(0-9) :");
           int pos;
           Scanner sc= new Scanner(System.in);
           pos=sc.nextInt();
           //when user enters rabit's location
           if (A[pos]==1)
           {
                   System.out.println("You found the rabbit");
                   System.out.print("|");
                   for (int i=0; i<10;i++)
                   {
                       if (A[i]==-1)
                       {
                           System.out.print("X|");      
                       }
                       else if (A[i]==0)
                       {
                           System.out.print(" |");
                       }
                       else
                       {
                           System.out.print("R|");
                       }
                   }
                   System.out.println();
                   System.exit(0);
           }
           // in case of wrong guess
           else
           {
               A[pos]=-1; //we consider X at this position so -1 denotes X
               System.out.print("|");
              
               for (int i=0; i<10;i++)
               {
                   if (A[i]==0||A[i]==1)
                   {
                       System.out.print(" |");      
                   }
                   else if(A[i]==-1)
                   {
                       System.out.print("X|");
                   }
               }
               System.out.println();
           }
           c--;
       }
   }
}

output -

Find the Rabbit!
| | | | | | | | | | |
Pick a hole(0-9) :9
| | | | | | | | | |X|
Pick a hole(0-9) :6
| | | | | | |X| | |X|
Pick a hole(0-9) :4
| | | | |X| |X| | |X|
Pick a hole(0-9) :3
| | | |X|X| |X| | |X|
Pick a hole(0-9) :1
You found the rabbit
| |R| |X|X| |X| | |X|

Add a comment
Know the answer?
Add Answer to:
PSEUDOCODE AND JAVA SOURCE CODE PLEASE: Program 1 (60 pts): Find the Rabbit! For this assignment,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ***** PSEUDOCODE PLEASE****** ***** PSUDOCODE PLEASE****** Program 0 (Warm-up): Deoxyribonucleic acid, or DNA, is comprised of...

    ***** PSEUDOCODE PLEASE****** ***** PSUDOCODE PLEASE****** Program 0 (Warm-up): Deoxyribonucleic acid, or DNA, is comprised of four bases: (G)uanine, (C)ytosine, (A)denine and (T)hymine.  Ribonucleic acid, or RNA, is different than DNA in that it contains no Thymine; thymine is replaced with something called (U)racil.  For this assignment, you will create an array of 255 characters.  You must start by filling the array with random characters of G, C, A and T.   You must then print out the array.  Next, replace all the instances of Thymine...

  • PLEASE DO THE PSEUDOCODE FOR THE PROGRAM BELOW Program 3: Design (pseudocode) and implement (source code)...

    PLEASE DO THE PSEUDOCODE FOR THE PROGRAM BELOW Program 3: Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values in an array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method getValues() that takes an integer array and returns another single-dimensional array containing only distinct values in the original (passed) array. Document...

  • Note: Write the pseudocode separately and the source code separately in java using the loops method...

    Note: Write the pseudocode separately and the source code separately in java using the loops method according to the question. Please make sure there is no errors. Program 0 (Warm up): Gimme a cookie! In the early days of computing, you likely couldn't afford your own computer. Instead, you had to sit at a terminal - which was literally just a monochrome monitor and keyboard that was connected to a big mainframe machine (hidden somewhere in the building). When you...

  • Pseudocode and PYTHON source code, thanks! Program 1: Design (pseudocode) and implement (source code) a class...

    Pseudocode and PYTHON source code, thanks! Program 1: Design (pseudocode) and implement (source code) a class (name it QuadraticEquation) that represents a quadratic equation of the form of ax2+ bx + x = 0. The class defines the following variables and methods: Private data field a, b, and c that represent three coefficients. A constructor for the arguments for a, b, and c. Three get methods for a, b, and c. Method getDiscriminant()returns the discriminant value, which is disc =...

  • PLEASE DO THIS IN JAVA!Design (pseudocode) and implement (source code) a program (name it PhoneBill) that...

    PLEASE DO THIS IN JAVA!Design (pseudocode) and implement (source code) a program (name it PhoneBill) that calculates the bill for a cellular telephone company. The company offers two types of service: regular service and premium service. The rates vary depending on the type of service. The rates are computed as follows: Regular service: $15.00 fee covering first 50 minutes. Charges for over 50 minutes are computed at the rate of $0.50 per minute. Premium service: $25.00 fee plus: a. For...

  • Write pseudocode and the write the source code in C++, thanks! Program 0: Insulted yet? Most...

    Write pseudocode and the write the source code in C++, thanks! Program 0: Insulted yet? Most people get harassed by telemarketers, so for your warmup question, you're going to design (pseudocode) and write (source code) a program that generates (clean) insults at random. The program must have a function that takes in the name of a person and prints out an insult directed to them. Further, the program should ask if the person has had enough insults and continue until...

  • PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it...

    PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it FeetMeters) to display a conversion tables for feet and meter as show below. Document your code and properly. Feet Meter 1.0 0.305 2.0 0.610 3.0 0.915 . . . . . . 19.0 5.7.95 20.0 6.100 Meter Feet 1.0 3.279 2.0 6.558 3.0 9.837 . . . . . . 19.0 62.301 20.0 65.574 The program defines the following methods: Method feetToMeter() converts from...

  • IN PYTHON ONLY!!! Program 2: Design (Pseudocode) and implement (Source Code) a program that asks the...

    IN PYTHON ONLY!!! Program 2: Design (Pseudocode) and implement (Source Code) a program that asks the user for their height (in inches), weight (in pounds), age and gender. Use loops to validate user input and to continue running for a new user until a sentinel value is entered. Ask them to select their approximate level of exercise each week from the options below, then determine and print their allowed daily caloric intake using their BMR: Female BMR = 655+(4.35 *...

  • java pseudocode and source code help? Write a program that uses an array of high temperatures...

    java pseudocode and source code help? Write a program that uses an array of high temperatures for your hometown from last week (Sunday - Saturday). Write methods to calculate and return the lowest high temperature (minimum) and a method to calculate and return the highest high temperature (maximum) in the array. You must write YOUR ORIGINAL methods for minimum and maximum. You MAY NOT use Math class methods or other library methods. Write an additional method that accepts the array...

  • For this assignment, you will write a program that guesses a number chosen by your user....

    For this assignment, you will write a program that guesses a number chosen by your user. Your program will prompt the user to pick a number from 1 to 10. The program asks the user yes or no questions, and the guesses the user’s number. When the program starts up, it outputs a prompt asking the user to guess a number from 1 to 10. It then proceeds to ask a series of questions requiring a yes or no answer....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT