In: Computer Science
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:
displayRabbitWearsHat(); //prints rabbit wearing hat
/* *********************************************************************************** displayRabbitWearsHat() - Displays the ASCII image of a rabbit wearing a hat ************************************************************************************ */ public static void displayRabbitWearsHat() {
displayRabbitEars(); displayRabbitFace(); displayHatBottom(); //etc.
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.
//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
}
}