Need help with my JAVA homework ASAP Thx Write a Java applic
Need help with my JAVA homework. ASAP. Thx
Write a Java application that plays a word game with the user. The program asks the user to enter the following: Your name One number between 1 and 10 Your favorite sport Your hometown Your favorite movie Your favorite animal Once the user enters these items, the program will display one of two stories depending on what number they entered. If the number they entered is less than 5 it will print the following by replacing the inputted variables into the correct locations: THIS IS THE BEST STORY EVER My name is . And I\'m from . My favorite sport is . I have a pet who I take to watch my favorite movie . The End! If the number they entered is 5 or greater, it will print the following: THIS IS THE BEST STORY EVER My name is and I am a . I live in and love to watch while trying to play . It does not work out so well though. The End! Here is a sample run. Words in orange are user input from the keyboard. Enter your name: Bob Enter a number from 1 to 10: 7 Enter your favorite sport: hockey Enter your hometown: Halifax Enter your favorite movie: Star Wars Enter your favorite animal: snake THIS IS THE BEST STORY EVER My name is Bob and I am a snake. I live in Halifax and love to watch Star Wars while trying to play hockey. It does not work out so well though. The End! Provide a printout of properly formatted source code (your entire Java program). Provide 2 example output/test cases (to show both stories).Solution
import java.util.Scanner;
class GetInputFromUser
{
public static void main(String args[])
{
int a;
String s1,s2,s3,s4,s5;
Scanner in = new Scanner(System.in);
System.out.println(\"your name\");
s1 = in.nextLine();
System.out.println(\"number between 1 and 10\");
a = in.nextInt();
System.out.println(\"your favourite sport\");
s2 = in.nextLine();
System.out.println(\"your hometown\");
s3 = in.nextLine();
System.out.println(\"your favourite movie\");
s4 = in.nextLine();
System.out.println(\"your favourite animal\");
s5 = in.nextLine();
if (a<5)
{
System.out.println(\" this is the best story ever\");
System.out.println(\"my name is \"+s1);
System.out.println(\"and i am from \"+s3);
System.out.println(\"my favourite sport is\" \"+s2);
System.out.println(\"i have a pet animal \"+s5);
System.out.println(\"who i talk to watch my\"+s4);
System.out.println(\"the end\");
}
if(a>5 and a<10)
{
System.out.println(\" this is the best story ever\");
System.out.println(\"my name is \"+s1);
System.out.println(\"iam a\"+s5);
System.out.println(\"i live in \"+s3);
System.out.println(\"and love to watch \"+s4);
System.out.println(\"while tring to play \"+s2);
System.out.println(\"it does not work out so well though. \");
System.out.println(\"The end\");
}
}
}

