a). Create a new java project file, CMSC246. In it, create a new Java class, Pro
ID: 3625267 • Letter: A
Question
a). Create a new java project file, CMSC246. In it, create a new Java class, Project5Java. Write a main method and static method called greatestOfThree that returns the greatest of three integer values. This method will have three integer parameters. Write the code to prompt the user to input three integers; call this method; and code to print out the three numbers that were sent as arguments and the returned value in the main method.b). In the Project5Java that was created in number a), add another static method called isSubstring that accepts two String objects as parameters and returns true if either one of the strings is contained in another. As in part three, write the code to prompt the user to input two Strings; call this method; and code to print out the strings that were sent as arguments and result - all in the main method.
Explanation / Answer
please rate - thanks
import java.util.*;
public class CMSC246
{public static void main(String[] args)
{int n1,n2,n3;
String a,b;
Scanner in=new Scanner(System.in);
System.out.print("Enter a number: ");
d
System.out.print("Enter another number: ");
n2=in.nextInt();
System.out.print("Enter a third number: ");
n3=in.nextInt();
System.out.println("The largest of "+n1+", "+n2+" and "+n3 +" is: "+greatestOfThree(n1,n2,n3));
in.nextLine();
System.out.print("Enter a string: ");
a=in.nextLine();
System.out.print("Enter another string: ");
b=in.nextLine();
if(isSubString(a,b))
System.out.println("one string is contained in the other");
else
System.out.println("one string is not contained in the other");
}
public static boolean isSubString(String a,String b)
{String big,little;
if(a.length()==b.length())
if(a.equals(b))
return true;
else
return false;
else
{if(a.length()<b.length())
{big=b;
little=a;
}
else
{big=a;
little=b;
}
if(big.indexOf(little)==-1)
return false;
else
return true;
}
}
public static int greatestOfThree(int n1,int n2,int n3)
{int big=n1;
if(n2>big)
big=n2;
if(n3>big)
big=n3;
return big;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.