Question: Hello everyone, I just started my object oriented programming class and am having some difficulty understanding this assignment. Make a copy of the file template.java
Hello everyone, I just started my object oriented programming class and am having some difficulty understanding this assignment.
Make a copy of the file template.java and call it HelloMe.java'
Use Notepad or another editor to make the following changes:
Insert the line "import java.util.Scanner;" at the top of the file.
Change the short description to "This program asks for the user's name and age, and says hello to the user."
Change the longer description to "Standard input and output is used. * This program will be further modified during this assignment."
Change "public class template" to "public class HelloMe." Note that you must use the same name here as the file name, with the same capitalization.
Change both @since lines to today's date.
Change "Short one line description of the method" to "main method is entry point for all java programs."
Insert the following between the line "public static void main(String[] args) {" and the following "}":
String name;
int age;
Scanner scanIn = new Scanner(System.in);
System.out.println("What is your name? ");
name = scanIn.nextLine();
System.out.println("Hello " + name);
System.out.println("How old are you? ");
age = scanIn.nextInt();
System.out.println("Next year you will be "
+ Integer.toString(age+1) + " years old!");
scanIn.close();
Save the file, compile, and run.
Answer the questions.
The result is as follows for both Windows and Mac users.
Part 2: Programming Practice
In the steps above, you learned how to create a simple Java program that reads strings and numbers from the command line.
View the famous poem "How Do I Love Thee? Let Me Count the Ways," by Elizabeth Barrett Browning at http://www.poetryfoundation.org/poem/172998.
In the spirit of this famous poem, modify the program above as follows.
Instead of asking the user's age, instead ask "How much love do you need?" There are "3 use case" scenarios to consider:
i.Use Case 1: User enters 0 or a negative number
Print out the message "Everybody needs some love!"
ii.Use Case 2: User enters a number bigger than 10
Print out the message "You cannot handle that much love!"
iii.Use Case 3: User enters a number between 1 and 9
Use a loop to count from 1 to the number entered, and print each "I love you" number "way" or "ways" according to English grammar, on a separate line.
Example: If 2 is entered, then print:
I love you 1 way
I love you 2 ways
After thoroughly testing the program, submit the Java file (.java) to the instructor.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
