Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Enter a collection of statements (similar to above) that prompt the user to ente

ID: 3793561 • Letter: E

Question

Enter a collection of statements (similar to above) that prompt the user to enter the year they graduate, stores that value in the String variable line, then an integer equivalent in userYear and compares it to testYear. If there is a match, print "Me too!" and increment matchCount by 1. Otherwise, just print'"I graduate in " + testYear You must use the correct operator for checking numeric equality. A list of Java operators can be found at Run your program to test this comparison. Enter a collection of statements (similar to above) that prompt the user to enter their favorite movie, stores that value in userMovie. and compares it to testMovie. If there is a match, print "Me too! " and increment matchCount by 1. Otherwise, just print '"My favorite movie is " + testMovie.' Remember to use the correct method for checking String equality. Run your program to test this comparison.

Explanation / Answer

//Online URL testing : http://ideone.com/eVqcym

import java.util.*;

class TestComparison
{
public static void main(String args[])
{
String line, userMovie, testMovie;
testMovie = "Titanic";
int matchCount=0,userYear=0,testYear=2014;
Scanner in = new Scanner(System.in);
System.out.println("Enter graduation year :");
line = in.nextLine();
try{
   userYear=Integer.parseInt(line);
}catch (Exception e){
   userYear=0;
}
if (userYear == testYear){
   System.out.println("Me too!");
   matchCount++;
}
  
System.out.println("Enter your favourite movie :");
userMovie = in.nextLine();
if (userMovie.equals(testMovie)){
   System.out.println("Me too!");
   matchCount++;
}else{
   System.out.println("My favourite movie is "+testMovie);
}
  
System.out.println("Total matchcount="+matchCount);
  
  
}
}

Output :