Question: /* * CPS150_Lab10.java */ import java.io.*; import java.util.*; /** * CPS 150, Fall 2018 semester * * Section N1 * * Lab Project 13: Comparing
/* * CPS150_Lab10.java */ import java.io.*; import java.util.*; /** * CPS 150, Fall 2018 semester * * Section N1 * * Lab Project 13: Comparing Java Strings * * @author *** Replace with your name *** */ public class CPS150_Lab13 { static final Scanner KBD = new Scanner(System.in); static final PrintStream OUT = System.out; // TO DO: Implement each of the following 4 methods, // using the String compareTo method: /* * lessThan(String, String) -> boolean * * method is passed two Strings * method returns true if the first String is less than the second String * otherwise, the method returns false */ /* * lessThanOrEquals(String, String) -> boolean * * method is passed two Strings * method returns true if the first String is less than or equal to the second String * otherwise, the method returns false */ /* * greaterThan(String, String) -> boolean * * method is passed two Strings * method returns true if the first String is greater than the second String * otherwise, the method returns false */ /* * greaterThanOrEquals(String, String) -> boolean * * method is passed two Strings * method returns true if the first String is greater than or equal to the second String * otherwise, the method returns false */ public static void main(String[] args) throws FileNotFoundException { OUT.print("Enter the input file name: "); // prompt the user for an input file name String fileName = KBD.nextLine(); Scanner fileIn = new Scanner( new File( fileName ) ); String str1 = fileIn.nextLine(); // read three strings from the file String str2 = fileIn.nextLine(); String str3 = fileIn.nextLine(); // compare the strings lexicographically String middle = str1; // Assume str1 is the middle string // TO DO: Complete the following code: // 1. using (calling) the methods implemented above // 2. nested branches that DO NOT use the boolean oprerators !, && or || // TO DO: Check to see if str1 is <= str2 and str3 >= str2 // If so, set the middle String to str2 // TO DO: Check to see if str3 is <= str2 and str1 >= str2 // If so, set the middle String to str2 // TO DO: Check to see if str1 is <= str3 and str2 >= str3 // If so, set the middle String to str3 // TO DO: Check to see if str2 is <= str3 and str1 >= str3 // If so, set the middle String to str3 System.out.println("The middle string is " + middle); // output the middle-valued string } } Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
