Question

In: Computer Science

For this assignment, you will apply what you learned in analyzing a simple Java™ program by...

For this assignment, you will apply what you learned in analyzing a simple Java™ program by writing your own Java™ program. The Java™ program you write should do the following:

  • Display a prompt on the console asking the user to type in his or her first name
  • Construct the greeting string "Hello, nameEntered!"
  • Display the constructed greeting on the console

Complete this assignment by doing the following:

  1. Download and unzip the linked zip file.
  2. Add comments to the code by typing your name and the date in the multi-line comment header.
  3. Replace the following lines with Java™ code as directed in the file:
    • LINE 1
    • LINE 2
    • LINE 3
    • LINE 4
  4. Comment each line of code you add to explain what you intend the code to do.
  5. Test and modify your Java™ program until it runs without errors and produces the results as described above.

Here is the code and please add comments

import java.util.Scanner;

public class PRG420Week1_CodingAssignment {
  
public static void main(String[] args) {
// Create a usable instance of an input device
LINE 1. INSTANTIATE AN INSTANCE OF SCANNER AND ASSIGN IT TO A VARIABLE OF TYPE SCANNER.

// Prompt user for input
LINE 2. USE THE PRINT() METHOD TO PROMPT THE USER FOR HIS OR HER FIRST NAME.

// Capture first word and assign it to A VARIABLE
LINE 3. USE THE NEXT() METHOD OF YOUR SCANNER INSTANCE TO ASSIGN A VALUE TO A STRING VARIABLE.

// Construct the greeting
LINE 4. USE THE PRINTLN() METHOD TO CONSTRUCT A CORRECTLY PUNCTUATED GREETING.

}
  
}

Solutions

Expert Solution

Java code

============================================================================================

package sat;

import java.util.Scanner;

public class PRG420Week1_CodingAssignment {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       String st;
       // Create a usable instance of an input device
       Scanner sc = new Scanner(System.in);

       // Prompt user for input
       System.out.print("Enter first name: ");

       // Capture first word and assign it to A VARIABLE
       st=sc.next();

       // Construct the greeting
       System.out.println("Hello,"+st+"!");
   }

}

============================================================================================

Output


Related Solutions

For this assignment, you will apply what you learned in analyzing a simple Java™ program by...
For this assignment, you will apply what you learned in analyzing a simple Java™ program by writing your own Java™ program that creates and accesses an array of integers. The Java™ program you write should do the following: Create an array to hold 10 integers Ask the user for an integer. Note: This code has already been written for you. Populate the array. Note: The first element should be the integer input by the user. The second through tenth elements...
For this assignment, you will apply what you learned in analyzing Java™ code so far in...
For this assignment, you will apply what you learned in analyzing Java™ code so far in this course by writing your own Java™ program. The Java™ program you write should do the following: Accept user input that represents the number of sides in a polygon. Note: The code to do this is already written for you. If input value is not between 3 and 5, display an informative error message If input value is between 3 and 5, use a...
For this assignment, you will apply what you learned in analyzing Java™ code so far in...
For this assignment, you will apply what you learned in analyzing Java™ code so far in this course by writing your own Java™ program. The Java™ program you write should do the following: Accept user input that represents the number of sides in a polygon. Note: The code to do this is already written for you. If input value is not between 3 and 5, display an informative error message If input value is between 3 and 5, use a...
For this assignment, you will be analyzing the Java™ code in the linked Week 3 Analyze...
For this assignment, you will be analyzing the Java™ code in the linked Week 3 Analyze Assignment Zip File, and predicting the results. You will also examine both the code and the output for inconsistencies and clarity. This Java™ code includes examples of for, while, and do-while loops. Carefully read through the code line by line, then answer the following questions in a Microsoft® Word document: What is the output of the program as it is written? What improvement(s) could...
For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java...
For this assignment, you will modify existing code to create a single Java™ program named BicycleDemo.java that incorporates the following: An abstract Bicycle class that contains private data relevant to all types of bicycles (cadence, speed, and gear) in addition to one new static variable: bicycleCount. The private data must be made visible via public getter and setter methods; the static variable must be set/manipulated in the Bicycle constructor and made visible via a public getter method. Two concrete classes...
Assignment Content Resource: ****************************CODE PASTED BELOW******************************* For this assignment, you will develop Java™ code that relies...
Assignment Content Resource: ****************************CODE PASTED BELOW******************************* For this assignment, you will develop Java™ code that relies on localization to format currencies and dates. In NetBeans, copy the linked code to a file named "Startercode.java". Read through the code carefully and replace all occurrences of "___?___" with Java™ code. Note: Refer to "Working with Dates and Times" in Ch. 5, "Dates, Strings, and Localization," in OCP: Oracle® Certified Professional Java® SE 8 Programmer II Study Guide for help. Run and debug...
Overview In this assignment you will apply what you have learned about standard deviation and normal...
Overview In this assignment you will apply what you have learned about standard deviation and normal curves to solve a number of problems, including finding the area under selected sections of a normal curve using z-scores, then solve a problem using normal distributions. Part 1: The weights of all one hundred (100) 9th graders at a school are measured, and it is found that the mean of all the measurements is 100 lbs., with a standard deviation of 15 lbs.  ...
In this assignment, you will be practicing the Java OOP skills we've learned this week in...
In this assignment, you will be practicing the Java OOP skills we've learned this week in implementing a customized mutable Array class. Please read the following requirements carefully and then implement your own customized Array class: === 1) Basic (100' pts total) === Your Array class must provide the following features: --1.1) (20' pts) Two constructors. One takes the input of the initialized capacity (int) and create the underlying array with that capacity; the other takes no input and creates...
In this assignment, you will be practicing the Java OOP skills we've learned this week in...
In this assignment, you will be practicing the Java OOP skills we've learned this week in implementing a customized mutable Array class. Please read the following requirements carefully and then implement your own customized Array class: === 1) Basic (100' pts total) === Your Array class must provide the following features: --1.1) (20' pts) Two constructors. One takes the input of the initialized capacity (int) and create the underlying array with that capacity; the other takes no input and creates...
Programmed In Java In this assignment you will create a simple game. You will put all...
Programmed In Java In this assignment you will create a simple game. You will put all of your code in a class called “Game”. You may put all of your code in the main method. An example of the “game” running is provided below. Y ou will start by welcoming the user. 1. You should print "Welcome! Your starting coordinates are (0, 0).” 2. On the next line, you will tell the user the acceptable list of commands. This should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT