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

Task 2 1. Add an import statement above the class declaration to make the Scanne

ID: 3673230 • Letter: T

Question

Task 2

1. Add an import statement above the class declaration to make the Scanner class available to your program.

2. In the main method, create a Scanner object and connect it to the System.in object.

3. Prompt the user to enter his/her first name.

4. Read the name from the keyboard using the nextLine method, and store it into a variable called firstName (you will need to declare any variables you use).

5. Prompt the user to enter his/her last name.

6. Read the name from the keyboard and store it in a variable called lastName.

7. Concatenate the firstName and lastName with a space between them and store the result in a variable called fullName.

8. Print out the fullName.

9. Compile, debug, and run, using your name as test data.

10. Since we are adding on to the same program, each time we run the program we will get the output from the previous tasks before the output of the current task.

Task 3 working with strings

1. Use the charAt method to get the first character in firstName and store it in a variable called firstInitial (you will need to declare any variables that you use).

2. Print out the user’s first initial.

3. Use the toUpperCase method to change the fullName to all capitals and store it back into the fullName variable

4. Add a line that prints out the value of fullName and how many characters (including the space) are in the string stored in fullName (use the method length to obtain that information).

5. Compile, debug, and run. The new output added on after the output from the previous tasks should have your initials and your full name in all capital letters.

Task 4 Using Predefined Math Functions

1. Add a line that prompts the user to enter the diameter of a sphere.

2. Read in and store the number into a variable called diameter (you will need to declare any variables that you use).

3. The diameter is twice as long as the radius, so calculate and store the radius in an appropriately named variable.

4. The formula for the volume of a sphere is V=(4/3)pir^3

Convert the formula to Java and add a line which calculates and stores the value of volume in an appropriately named variable. Use Math.PI for        and Math.pow to cube the radius.

5. Print your results to the screen with an appropriate message.

6. Compile, debug, and run using the following test data and record the results.

Diameter

Volume (hand calculated)

Volume (resulting output)

2

25.4

875,000

Diameter

Volume (hand calculated)

Volume (resulting output)

2

25.4

875,000

Explanation / Answer

Multiple Questions : Answering 1st ( Task 2) :

import java.util.*;
import java.lang.*;
import java.io.*;

class fullName
{
   public static void main (String[] args) throws java.lang.Exception
   {
      Scanner keyboard = new Scanner(System.in);
      System.out.println("Enter your first name");
      String firstName = keyboard.nextLine();
      System.out.println("Enter your last name");
      String lastName = keyboard.nextLine();
      String fullName = firstName + lastName;
      System.out.println("Full Name : "+fullName);
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote