Create a method int Turtle.java to draw a “road” pattern horizontally across the
ID: 3864074 • Letter: C
Question
Create a method int Turtle.java to draw a “road” pattern horizontally across the world. The method should take in two
parameters, int height that designates the top edge of the road, and int width that determines the distance between the edges of the
road. The dashed lines in the center of the road should be of a length = to ½ of the distance parameter. Center lines should be
done with a while loop.
The method should deal with errors. If the width is taller than the world, simply print an error and return. If the road drawn at a
given y would attempt to draw off of the bottom of the world, the width of the road should be adjusted to fit in the world at the
given starting y position.
Please help me!
Thanks in advance! :-)
#java programming
31. Create a method int Turtlejava to draw a "road'' pattern horizontally across the world. The method should take in two parameters. int height that designates the top edge of the road. and int width that determines the distance between the edges of the road. The dashed lines in the center of the road should be of a length F to of the distance parameter. Center lines should be done with a while loop The method should deal with errors. If the width is taller than the world, simply print an error and return. If the road drawn at a given y would attempt to draw off of the bottom ofthe world, the width of the road should be adjusted to fit in the world at the given starting y position.Explanation / Answer
package Turtle;
import java.util.Scanner;
public class Turtle {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
// TODO Auto-generated method stub
System.out.println("Enter the height");
int height=sc.nextInt();
System.out.println("Enter the width");
int width = sc.nextInt();
turtle(height,width);
}
public static int turtle (int height, int width)
{
float central_lines = (float) (1/2)height;
while ( central_lines > 0)
{
System.out.println("-");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.