Question: Ruler: Overview As a team, you are to write three programs that solve problems which can be solved recursively: Horizontal Ruler, based on the Ruler


Ruler:

Overview As a team, you are to write three programs that solve problems which can be solved recursively: Horizontal Ruler, based on the Ruler program Eight-Queens Problem, based on the Problem Solver approach Prefix Expression Evaluation, a completely new problem 1. Horizontal Ruler 1.1. Problem Description In class, we went over a recursive solution to printing an English Ruler with adjustable lengths and number of tick marks. It produced output vertically, like this: Ruler of length 3 with major tick length 3 --- 3 For this program, you are to print out rulers horizontally, like this: Ruler of length 3 with major tick length 3 1 2 1.2. Notes 0 You must start with the code we went over in class: Ruler.java Your solution must be recursive. Turn in only your source file: HorizontalRuler.java. Make sure your class is not in a package (that is, it is in the default package). Your output must include the names of all team members. Your program should run the three test cases that are already in Ruler, that is: Ruler of length 2 with major tick length 4 Ruler of length 1 with major tick length 5 Ruler of length 3 with major tick length 3 Don't overthink this! This problem is not that different from the original. Hint: Because of the way printing works, you will need to print the top line first (just the tops of the longest tick lines), then the second line (with top two longest tick lines), etc. Finally, you can print the numbers. 1.3. Required Main Class Horizontal Ruler 1.4. Required Input Not applicable 1.5. Required Output Your output should look like the following: Horizontal Ruler - Team Member 1, Team Member 2, Team Member 3, ... Ruler of length 2 with major tick length 4 Ruler of length 1 with major tick length 5 1 Ruler of length 3 with major tick length 3 0 2 Ruler.java X 2 public class Ruler { public static void drawRuler(int ninches, int majorLength) { drawLine(majorLength, o); // draw inch @ line and Label for (int j = 1; j = 1) { // otherwise, do nothing 13 drawinterval(centralLength - 1); // recursively draw top interval 14 drawLine(centralLength); // draw center tick line (without label) 15 drawInterval(centralLength - 1); // recursively draw bottom interval 16 17 18 190 private static void drawLine(int tickLength, int tickLabel) { 20 for (int j = 0; j = 0) 23 System.out.print(" " + tickLabel); 24 System.out.print(" "); 25 26 27 private static void drawline(int tickLength) { 28 drawLine(tickLength, -1); 29 } 30 310 public static void main(String[] args) { 32 System.out.print(" Ruler of length 2 with major tick length 4 "); 33 drawRuler(2, 4); 34 System.out.print(" Ruler of length 1 with major tick Length 5 "); 35 drawRuler(1, 5); 36 System.out.print(" Ruler of length 3 with major tick length 3 "); 37 drawRuler(3, 3); 38 } 39) 40 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
