This JAVA program is broken down into two phases for your convenience only. Plea
ID: 3855830 • Letter: T
Question
This JAVA program is broken down into two phases for your convenience only. Please turn in only your final product. Phase 2:In this phase you will allow the user to specify three things: the height of each stage the width of each stage how many stages in the rocket [A "stage" in your rocket is one rectangle. The example rocket above has a stage-height of 6, a stage-width of 5, and the number of stages is 2.] Your main method in phase 2 must look like this: public static void main(String[] args) { <6 statements to prompt for and read the stage-height, stage-width, and number of stages.> drawRocket(); } You must still use the drawHorizontalLine(), draw2VerticalLines(), and drawOneRow() methods Notice that if you run the program and choose a different width for your stages, the cone won't really fit correctly anymore. I won't make you fix this, but you can fix it for 5 points of extra credit if you like. However, I will not help you with the extra credit. In order to get the extra credit, the number of rows of your cone must be equal to the width of the stages divided by 2 (plus 1 for odd widths). If the stage width is an even number, your cone must have two stars in the top row instead of one. If you do this perfectly and use good decomposition in the process you'll get 5 extra credit points.
Explanation / Answer
import java.io.*;
import java.util.*;
//class DrawRocket is used to draw rocket with cone or filled and others.
class DrawRocket
{
public void drawOddCone(int width)
{
for(int j=1;j<=width;j+=2)
{
for(int i=1;i<=(width-j)/2;i++)
{
System.out.print(" ");
}
System.out.print("*");
if(j>1)
{
for(int h=1; h<=j-2; h++)
{
System.out.print(" ");
}
System.out.print("*");
}
System.out.print(" ");
}
}
public void drawOddBoxFilled(int height,int width)
{
for(int k= 1; k <=height;k++)
{
for(int m=1;m<=width;m++)
{
System.out.print("*");
}
System.out.print(" ");
}
}
public void drawOddBoxOpen(int height,int width)
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if ((j == 0) || (j == width - 1))
{
System.out.print("*");
}
else if ((i == 0) || (i == height - 1))
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.print(" ");
}
}
//functions for sample#2
public void drawConeEven(int width)
{
for(int j=1;j<=width/2;j++)
{
for(int i=1;i<=(width/2)-j;i++)
{
System.out.print(" ");
}
System.out.print("*");
if(j>=1)
{
for(int h=1; h<=2*j-2; h++)
{
System.out.print(" ");
}
System.out.print("*");
}
System.out.print(" ");
}
}
public void drawEvenBoxFilled(int height, int width)
{
for(int k= 1; k <=height;k++)
{
for(int m=1;m<=width;m++)
{
System.out.print("*");
}
System.out.print(" ");
}
}
public void drawEvenBoxOpen(int height, int width)
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
if ((j == 0) || (j == width - 1))
{
System.out.print("*");
}
else if ((i == 0) || (i == height - 1))
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.print(" ");
}
}
}
//main class Rocket which takes height, width, stages of a rocket and calls methods in above class.
class Rocket
{
public static void main(String args[])
{
DrawRocket d=new DrawRocket();
char again;
int rocketHeight;
int rocketWidth;
int rocketStage;
char rocketType;
Scanner s=new Scanner(System.in);
do
{
System.out.print("Please enter a number for the height of the rocket: ");
rocketHeight = s.nextInt();
System.out.print("Please enter a number for the width of the rocket: ");
rocketWidth = s.nextInt();
System.out.print("Please enter a number for the stages of the rocket: ");
rocketStage = s.nextInt();
System.out.print("Would you like the rocket to be filled or open?(F/O): ");
rocketType = s.next().charAt(0);
if((rocketHeight>3 && rocketHeight<15) && (rocketWidth>3 && rocketWidth<15)) //minimum rocketHeight, rocketWidth is 4 and maximum rocketHeight,rocketWidth is 14
{
// displays rocket with odd height and odd width and filled.
if((rocketHeight %2 != 0) && (rocketWidth %2 != 0) && (rocketType == 'F'|| rocketType == 'f'))
{
d.drawOddCone(rocketWidth);
for (int l =1;l<=rocketStage; l++)
{
d.drawOddBoxFilled(rocketHeight,rocketWidth);
}
d.drawOddCone(rocketWidth);
}
// displays rocket with odd height and odd width and open.
if((rocketHeight %2 != 0) && (rocketWidth %2 != 0) && (rocketType == 'O'|| rocketType == 'o'))
{
d.drawOddCone(rocketWidth);
for (int l =1;l<=rocketStage; l++)
{
d.drawOddBoxOpen(rocketHeight,rocketWidth);
}
d.drawOddCone(rocketWidth);
}
//displays rocket with even height and even width and filled.
if((rocketHeight %2 == 0) && (rocketWidth %2 == 0) && (rocketType == 'F'|| rocketType == 'f'))
{
d.drawConeEven(rocketWidth);
for (int q =1;q<=rocketStage;q++)
{
d.drawEvenBoxFilled(rocketHeight,rocketWidth);
}
d.drawConeEven(rocketWidth);
}
//displays rocket with even height and even width and open.
if((rocketHeight %2 == 0) && (rocketWidth %2 == 0) && (rocketType == 'O'|| rocketType == 'o'))
{
d.drawConeEven(rocketWidth);
for (int q =1;q<=rocketStage;q++)
{
d.drawEvenBoxOpen(rocketHeight,rocketWidth);
}
d.drawConeEven(rocketWidth);
}
// displays rocket with even height and odd width and filled.
if((rocketHeight %2 == 0) && (rocketWidth %2 != 0) && (rocketType == 'F'|| rocketType == 'f'))
{
d.drawOddCone(rocketWidth);
for (int l =1;l<=rocketStage; l++)
{
d.drawEvenBoxFilled(rocketHeight,rocketWidth);
}
d.drawOddCone(rocketWidth);
}
// displays rocket with even height and odd width and open.
if((rocketHeight %2 == 0) && (rocketWidth %2 != 0) && (rocketType == 'O'|| rocketType == 'o'))
{
d.drawOddCone(rocketWidth);
for (int l =1;l<=rocketStage; l++)
{
d.drawEvenBoxFilled(rocketHeight,rocketWidth);
}
d.drawOddCone(rocketWidth);
}
// displays rocket with odd height and odd width and filled.
if((rocketHeight %2 != 0) && (rocketWidth %2 == 0) && (rocketType == 'F'|| rocketType == 'f'))
{
d.drawConeEven(rocketWidth);
for (int l =1;l<=rocketStage; l++)
{
d.drawOddBoxFilled(rocketHeight,rocketWidth);
}
d.drawConeEven(rocketWidth);
}
// displays rocket with odd height and odd width and open.
if((rocketHeight %2 != 0) && (rocketWidth %2 == 0) && (rocketType == 'O'|| rocketType == 'o'))
{
d.drawConeEven(rocketWidth);
for (int l =1;l<=rocketStage; l++)
{
d.drawOddBoxFilled(rocketHeight,rocketWidth);
}
d.drawConeEven(rocketWidth);
}
}
else
{
System.out.print("Invalid Input. Please try again or quit: ");
}
System.out.print("Would you like to do this again?(y/n): ");
again = s.next().charAt(0);
}while(again == 'Y' || again =='y');
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.