Question: Horizontal Ruler Problem Description: a recursive solution to printing an English Ruler with adjustable lengths and number of tick marks. It produced output vertically, like

Horizontal Ruler
Problem Description:
a recursive solution to printing an English Ruler with adjustable lengths
and number of tick marks. It produced output vertically, like this:
see image
Ruler of length 3 with major tick length 3
For this program, you are to print out rulers horizontally, like this:
see image
Notes:
You must start with the code we went over in class: Ruler.java
Your solution must be recursive
Your output must include your name.
Your program should run the three test cases that are already in Ruler.java
Ruler.java:
public class Ruler {
public static void drawRuler(int nInches, int majorLength){
drawLine(majorLength,0); // draw inch 0 line and label
for (int j =1; j = nInches; j++){
drawInterval(majorLength -1); // draw interior ticks for inch
drawLine(majorLength, j); // draw inch j line and label
}
}
private static void drawInterval(int centralLength){
if (centralLength >=1){// otherwise, do nothing
drawInterval(centralLength -1); // recursively draw top interval
drawLine(centralLength); // draw center tick line (without label)
drawInterval(centralLength -1); // recursively draw bottom interval
}
}
private static void drawLine(int tickLength, int tickLabel){
for (int j =0; j tickLength; j++)
System.out.print("-");
if (tickLabel >=0)
System.out.print(""+ tickLabel);
System.out.print("
");
}
private static void drawLine(int tickLength){
drawLine(tickLength,-1);
}
public static void main(String[] args){
System.out.print("
Ruler of length 2 with major tick length 4
");
drawRuler(2,4);
System.out.print("
Ruler of length 1 with major tick length 5
");
drawRuler(1,5);
System.out.print("
Ruler of length 3 with major tick length 3
");
drawRuler(3,3);
}
}
 Horizontal Ruler Problem Description: a recursive solution to printing an English

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!