Patrick B. answered 02/24/19
Math and computer tutor/teacher
import java.io.*;
class StarAsteriskArrow
{
private int arrow_base_height;
private int arrow_base_width;
private int arrow_head_width;
StarAsteriskArrow ( int baseHeight, int baseWidth, int headWidth)
{
arrow_base_height = baseHeight;
arrow_base_width = baseWidth;
arrow_head_width = headWidth;
System.out.println(" Constructor : inputs are arrow base height = " + arrow_base_height +
" : \n arrow base width = " + arrow_base_width +
" : \n arrow head width = " + arrow_head_width);
}
public int PromptForInteger(String promptMsg) throws IOException
{
Console console = System.console();
String inbuff;
System.out.print(promptMsg);
inbuff = console.readLine();
int iReturn = Integer.parseInt(inbuff);
return(iReturn);
}
public static void main( String args[])
{
int baseHeight=0;
int baseWidth=0;
int headWidth=0;
StarAsteriskArrow dummyInput = new StarAsteriskArrow(0,0,0);
try
{
while (baseHeight <=0)
{
baseHeight = dummyInput.PromptForInteger(" Please input the arrow base height :>");
}
while (baseWidth<=0)
{
baseWidth = dummyInput.PromptForInteger(" Please input the arrow base width :> ");
}
while (headWidth < baseWidth)
{
headWidth = dummyInput.PromptForInteger(" Please input the arrow head width :> ");
}
}
catch( IOException ex) { System.out.println(" INPUT EXCEPTION ERROR "); }
StarAsteriskArrow myArrow = new StarAsteriskArrow( baseHeight, baseWidth, headWidth);
myArrow.Draw();
} //main
public void Draw()
{
int padWidth = (arrow_head_width - arrow_base_width)/2;
int iLoop=0;
int jLoop=0;
//draws the base
for (jLoop=0; jLoop<arrow_base_height; jLoop++)
{
for (iLoop=0; iLoop<padWidth; iLoop++)
{
System.out.print(" ");
}
for (iLoop=0; iLoop<arrow_base_width; iLoop++)
{
System.out.print("*");
}
System.out.println("");
}
//draws the head
for (jLoop=0; jLoop<arrow_head_width; jLoop++)
{
for (iLoop=0; iLoop<jLoop; iLoop++)
{
System.out.print(" ");
}
for (iLoop=0; iLoop<arrow_head_width-2*jLoop; iLoop++)
{
System.out.print("*");
}
System.out.println("");
}
} //Draw
} //class
Patrick B.
It's there. In the method INPUT you will see the prompt for the arrow head width continues until a value LARGER than the arrow base width is input02/26/19
Steve E.
Thank you for responding. The code I have is mostly working, with a couple changes to the code I posted here. But I still am having problems with the end of the problem. Apparently, need to do something with this step: (4) Modify the given program to only accept an arrow head width that is larger than the arrow base width. Use a loop to continue prompting the user for an arrow head width until the value is larger than the arrow base width. (1 pt) And maybe use this "while" statement? while (arrowHeadWidth <= arrowBaseWidth) { // Prompt user for a valid arrow head value } I've been playing with it, but no luck yet. I hope your still available for help. Thanks again. My revised code follows. System.out.println("Enter arrow base height:"); arrowBaseHeight = scnr.nextInt(); System.out.println("Enter arrow base width:"); arrowBaseWidth = scnr.nextInt(); System.out.println("Enter arrow head width:"); arrowHeadWidth = scnr.nextInt(); System.out.println(); // I added this for spacing for (int i = 0; i < arrowBaseHeight; i++) { // I remove the = after the < for (int j = 0; j < arrowBaseWidth; j++) { System.out.print("*"); } System.out.println(); } for (int i = 0; i < arrowHeadWidth; i++) { for (int j = arrowHeadWidth; j>i; j--) { System.out.print("*"); } System.out.println();02/25/19