In: Computer Science
Name the project pa3
[Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit.
1: All work and no play makes Jack a dull boy.
2: All work and no play makes Jack a dull boy.
3: All work and no play makes Jack a dull boy.
4: All work and no play makes Jack a dull boy.
[Method 2] In the Main class, write a static method that accepts an array of floating point parameters. The three elements in the array can be labeled as a, b, and c from first to last. The method computes and returns the results of the quadratic equation in a separate two-element array given by the following equation: −b ± √( b^2 − 4 · a · c) / (2 · a), as long as the discriminant (b^2 − 4 · a · c) is non-negative. Otherwise, return a reference to an array object with zeros in both elements.
[Method 3] In the Main class, write a static void method that receives three Strings and prints them in reverse dictionary order, Z to A. Tips: Should the result of the following example be positive: callingString.compareTo(otherString), callingString will appear after otherString in the dictionary. There are six possible orderings of 3 items, so you should not need more than 5 nested if statements. Another option is to place the Strings into an array, use the Arrays.sort static method, and traverse the array backwards.
[Method 4] In the Main class, write a static method that receives a String parameter named option. The method then returns one of the following String literals based on the return value of option’s length() function. When option has fewer than 10 characters, return “too small”. When option has more than 10 characters, return “too big”. When option has exactly 10 characters, return “just right”.
In the main method, write the Java code to receive the needed actual parameters from the user for each method and call each method. For instance, the three numbers required for Method 2 should be read from the user. Also include the appropriate prompts instructing the user what to enter.
Requirements
1) A reference variable and instance object of class java.util.Scanner must be used to read the input from the user. 2) Identifiers must be descriptive (i.e., must self document).
3) Indention of all code blocks (compound statements, code inside braces), including single statements following selection or while statements, is required.
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. Let me know for any help with any other questions. Thank You! =========================================================================== public class Main { // Question 3 public static void repeat4(String line) { for (int count = 1; count <= 4; count++) { System.out.println(count + ": " + line); } } // Question 4 public static double[] getRoots(double a, double b, double c) { double[] roots = {0.0, 0.0}; double discriminant = b * b - 4 * a * c; if (discriminant < 0) { return roots; } discriminant = Math.sqrt(discriminant); roots[0] = (-b + discriminant) / (2 * a); roots[1] = (-b - discriminant) / (2 * a); return roots; } // Question 5 public static void reversePrint(String a, String b, String c) { if (a.compareTo(b) < 0 && a.compareTo(c) < 0) { if (b.compareTo(c) < 0) { System.out.println(c); System.out.println(b); System.out.println(a); } else { System.out.println(b); System.out.println(c); System.out.println(a); } } else if (b.compareTo(a) < 0 && b.compareTo(c) < 0) { if (a.compareTo(c) < 0) { System.out.println(c); System.out.println(a); System.out.println(b); } else { System.out.println(a); System.out.println(c); System.out.println(b); } } else { if (a.compareTo(b) < 0) { System.out.println(b); System.out.println(a); System.out.println(c); } else { System.out.println(a); System.out.println(b); System.out.println(c); } } } // 6 public static String optionString(String s) { if (s == null || s.length() < 10) return "too small"; else if (s.length() == 10) return "just right"; else return "too big"; } // 7 public static void getInput() { Scanner scanner = new Scanner(System.in); System.out.println("Method 1"); System.out.print("Enter a line to repeat: "); String line = scanner.nextLine(); repeat4(line); System.out.println("Method 2"); System.out.print("Enter value of a: "); double a = scanner.nextDouble(); System.out.print("Enter value of b: "); double b = scanner.nextDouble(); System.out.print("Enter value of c: "); double c = scanner.nextDouble(); scanner.nextLine(); double[] roots = getRoots(a, b, c); System.out.println("Root 1: " + roots[0] + ", Root 2:" + roots[1]); System.out.println("Method 3"); System.out.print("Enter first string: "); String first = scanner.nextLine(); System.out.print("Enter second string: "); String second = scanner.nextLine(); System.out.print("Enter third string: "); String third = scanner.nextLine(); reversePrint(first, second, third); System.out.println("Method 4"); System.out.print("Enter option string: "); String option = scanner.nextLine(); System.out.println(optionString(option)); } public static void main(String[] args) { getInput(); } }
===========================================================================