Question

In: Computer Science

Program Specifications: You will be writing a Java program called ASCIIRabbit.java that will print the following...

Program Specifications:

You will be writing a Java program called ASCIIRabbit.java that will print the following ASCII objects. There should be two blank lines between each shape and your output must match identically.

 Rabbit In A Hat
--------------------

 (^\ /^)
  \ V /
  (o o)
 ( (@) )
---------
 |     |
 |     |
 |     |
 _______


 Rabbit Under A Hat
--------------------
 _______
 |     |
 |     |
 |     |
---------
  /\"/\
 () * ()
("")_("")


Rabbit Wears A Hat
------------------
 _______
 |     |
 |     |
 |     |
---------
  (o o)
 ( (@) )
  /\"/\
 () * ()
("")_("") 

Style requirements:

  1. Main comments - Be sure to include a comment in the main method as your begin each shape stating what shape you're about to print...like this:
    displayRabbitWearsHat();   //prints rabbit wearing hat
    
  2. Method comments - Be sure to include a comment above each method that describes the purpose of that method like this
    /* ***********************************************************************************
        displayRabbitWearsHat() - Displays the ASCII image of a rabbit wearing a hat
    ************************************************************************************ */
    public static void displayRabbitWearsHat() {
    
  3. Methods to be used - For this exercise, you will be defining several methods to assist you in drawing the objects and minimizes code redundancy (similar to the egg program we did in lecture). For this exercise, we are going to give you the methods you should use for a proper decomposition.
    • A method called displayRabbitEars: public static void displayRabbitEars() - Draws the portion of the rabbit that includes the ears only.
    • A method called displayRabbitFace: public static void displayRabbitFace() - Similar to above, but this method should display the face of the rabbit.
    • A method called displayRabbitBody: public static void displayRabbitBody() - Similar to above, but this method should display the body of the rabbit.
    • A method called displayHatTop: public static void displayHatTop() - This draws the first line of the hat.
    • A method called displayHatBottom: public static void displayHatBottom() - This draws the last line of the hat.
    • A method called displayHatBody: public static void displayHatBody() - This draws the middle of the hat.
    • A method called displayRabbitInHat: public static void displayRabbitInHat() - So now you can probably see where we are headed. We can draw any of the required rabbits by piecing together the different methods.
              displayRabbitEars();
              displayRabbitFace();
              displayHatBottom();
              //etc.
      
    • Methods for displayRabbitUnderHat() and displayRabbitWearsHat() - Continue using the above logic to develop the remaining rabbit methods. Then tie it all together with a main method that will display the ASCII graphics in the proper order.

Once you think you have your program decomposition properly created, test your program to see if your output matches the sample run from above. When it looks correct and you have it properly documented, submit it for grading.

Solutions

Expert Solution

//Below is the required program in JAVA.

//Kindly note that characters have been escaped wherever required(like \" instead of ").

/*I can see that there is a problem in copying (problem with the text editor provided here) since spaces have been copied as some character,for resolution simply replace that character with " " in text editor.*/

import java.io.*;

// (^\ /^)
// \ V /
// (o o)
// ( (@) )
// /\"/\
// () * ()
// ("")_("")

class RabbitDisplay{
  
// Draws the portion of the rabbit that includes the ears only.
public static void displayRabbitEars(){
System.out.println(" (^\\ /^)");
System.out.println(" \\ V /");
}
  
// this method should display the face of the rabbit.
public static void displayRabbitFace(){
System.out.println(" (o o)");
System.out.println(" ( (@) )");
}
  
// this method should display the body of the rabbit.
public static void displayRabbitBody(){
System.out.println(" /\\\"/\\");
System.out.println(" () * ()");
System.out.println("(\"\")_(\"\")");
}
  
// this method should display the first line of the hat.
public static void displayHatTop(){
System.out.println(" _______");
}
  
// this method should display the body of the hat.
public static void displayHatBody(){
System.out.println(" | |");
System.out.println(" | |");
System.out.println(" | |");
}
  
// this method should display the last line of the hat.
public static void displayHatBottom(){
System.out.println("---------");
}
  
/* ***********************************************************************************
displayRabbitWearsHat() - Displays the ASCII image of a rabbit in a hat
************************************************************************************ */
public static void displayRabbitInHat(){
System.out.println(" Rabbit In A Hat");
System.out.println("--------------------");
displayRabbitEars();
displayRabbitFace();
displayHatBottom();
displayHatBody();
displayHatTop();
System.out.println("\n\n");
}
  
/* ***********************************************************************************
displayRabbitWearsHat() - Displays the ASCII image of a rabbit under a hat
************************************************************************************ */
public static void displayRabbitUnderHat(){
System.out.println(" Rabbit Under A Hat");
System.out.println("--------------------");
displayHatTop();
displayHatBody();
displayHatBottom();
displayRabbitBody();
System.out.println("\n\n");
}
  
/* ***********************************************************************************
displayRabbitWearsHat() - Displays the ASCII image of a rabbit wearing a hat
************************************************************************************ */
public static void displayRabbitWearsHat(){
System.out.println(" Rabbit Wears A Hat");
System.out.println("--------------------");
displayHatTop();
displayHatBody();
displayHatBottom();
displayRabbitFace();
displayRabbitBody();
System.out.println("\n\n");
}
  
//MAIN METHOD
   public static void main (String[] args) {
displayRabbitInHat(); //prints rabbit in a hat
displayRabbitUnderHat(); //prints rabbit under a hat
displayRabbitWearsHat(); //prints rabbit wearing hat
   }
}


Related Solutions

Specifications: Write a Java program called LifeRaft.java that will do all of the following: Display a...
Specifications: Write a Java program called LifeRaft.java that will do all of the following: Display a title Ask the user to enter the following values: The type of plane(Boeing 747 or Airbus A300) The number of passengers on board the Plane The number of crew aboard the plane The maximum number of people that can be carried by one liferaft assuming all the liferafts on the plane are the same size The actual number of liferafts that are available on...
Write a program in Java and run it in BlueJ according to the following specifications: The...
Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade on each line) and determines their type (excellent or ok). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "all" - prints all student records (first name, last name, grade, type). "excellent" - prints students with grade > 89. "ok"...
Program Specifications The built-in Java Math methods make some calculations much easier. Write a program called...
Program Specifications The built-in Java Math methods make some calculations much easier. Write a program called "DoTheMath" that accepts as input three floating-point numbers x, y, and z (define them as double) and outputs several calculations: x to the power of y x to the power of (y to the power of z) The absolute value of x The square root of (x*y to the power of z). Sample Run: Enter the values for x, y, z: -3.7 -3 5...
Problem specifications: You are tasked with developing a complete temperature conversion program in Java. Your program...
Problem specifications: You are tasked with developing a complete temperature conversion program in Java. Your program should: -prompt the user with the following menu: -1-Convert Fahrenheit to Celcius -2-Convert Celcius to Fahrenheit -3-Quit Program The menu must be coded in its own method. -If user select option 1 then call a method that prompts the user to enter a value in degrees Fahrenheit and return it back to main. -call a method that converts from Fahrenheit to Celcius -call a...
***USING JAVA Scenario: You will be writing a program that will allow a user to find...
***USING JAVA Scenario: You will be writing a program that will allow a user to find and replace misspelled words anywhere in the phrase, for as many words as the user wishes. Once done (see example runs below), the program will print the final phrase and will show the Word Count, Character Count, the Longest Word and the Shortest Word. Requirements: Do not use Arrays for this assignment. Do not use any String class methods (.phrase(), replace methods, regex methods)...
Using Java, The program you will be writing displays a weekly payroll report. A loop in...
Using Java, The program you will be writing displays a weekly payroll report. A loop in the program should ask the user for the employee’s number, employee’s last name, number of hours worked, hourly pay rate, state tax, and federal tax rate. After the data is entered and the user hits the enter key, the program will calculate gross and net pay then displays employee’s payroll information as follows and asks for the next employees’ information. if the user works...
write this program in java... don't forget to put comments. You are writing code for a...
write this program in java... don't forget to put comments. You are writing code for a calendar app, and need to determine the end time of a meeting. Write a method that takes a String for a time in H:MM or HH:MM format (the program must accept times that look like 9:21, 10:52, and 09:35) and prints the time 25 minutes later. For example, if the user enters 9:21 the method should output 9:46 and if the user enters 10:52...
Writing a Modular Program in Java In this lab, you add the input and output statements...
Writing a Modular Program in Java In this lab, you add the input and output statements to a partially completed Java program. When completed, the user should be able to enter a year, a month, and a day to determine if the date is valid. Valid years are those that are greater than 0, valid months include the values 1 through 12, and valid days include the values 1 through 31. Instructions Notice that variables have been declared for you....
Write a complete Java program to print out the name bob
Write a complete Java program to print out the name bob
I need it in java. Write a program that will print if n numbers that the...
I need it in java. Write a program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT