Computers and Technology

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.
Gaddis_516907_Java 4/10/07 2:10 PM Page 14
Chapter 2 Lab Java Fundamentals 15
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 = 4pr3
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 p 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.

Program:

import java. util. Scanner;

/**
This program demonstrates how numeric types and operators behave in Java
*/

public class NumericTypes
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner(System. in);

//identifier declarations
final int NUMBER = 2 ; // number of scores
final int SCORE1 = 100; // first test score
final int SCORE2 = 95; // second test score
final int BOILING_IN_F = 212; // freezing temperature
int fToC; // temperature in celsius
int average; // arithmetic average
String output; // line of output to print out
String firstName;
String lastName;
char letter;

//TASK #2 declare variables used here
//TASK #3 declare variables used here
//TASK #4 declare variables used here

// Find an arithmetic average
average = (SCORE1 + SCORE2) / NUMBER;
output = SCORE1 + " and " + SCORE2 + " have an average of "
+ average;
System. out. println(output);

// Convert Fahrenheit temperatures to Celsius
fToC = (BOILING_IN_F - 32) * (5/9);
output = BOILING_IN_F + " in Fahrenheit is " + fToC
+ " in Celsius.";
System. out. println(output);
System. out. println(); // to leave a blank line

// ADD LINES FOR TASK #2 HERE

// prompt the user for first name
System. out. print(" What is your first name?");
// read the user's first name
firstName = keyboard. nextLine();

// prompt the user for last name
System. out. print(" What is your last name?");
// read the user's last name
lastName = keyboard. nextLine();

// print out the user's full name
System. out. println(""+ firstName + " " + lastName+"");

System. out. println(); // to leave a blank line

// ADD LINES FOR TASK #3 HERE

// get the first character from the user's first name
// print out the user's first initial
// convert the user's full name to all capital letters
// print out the user's full name in all capital letters

System. out. println(); // to leave a blank line

// ADD LINES FOR TASK #4 HERE
// prompt the user for a diameter of a sphere
// read the diameter
// calculate the radius
// calculate the volume
// print out the volume
}
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 15:00, yeet74
I'm taking a class on how to make a movie, and it offers some apps that would be in the process. the thing is, i don't have any of those ha. if you have any tips on some apps i could use, that would be awesome. i don't have an iphone, so don't suggest any apps like imovie. i know that this is a weird question, but it would be super for me. : )
Answers: 2
image
Computers and Technology, 22.06.2019 19:40, rakanmadi87
Solve the following javafx application: write a javafx application that analyzes a word. the user would type the word in a text field, and the application provides three buttons for the following: - one button, when clicked, displays the length of the word.- another button, when clicked, displays the number of vowels in the word.- another button, when clicked, displays the number of uppercase letters in the word(use the gridpane or hbox and vbox to organize the gui controls).
Answers: 1
image
Computers and Technology, 22.06.2019 20:40, broang23
Write a program that begins by reading in a series of positive integers on a single line of input and then computes and prints the product of those integers. integers are accepted and multiplied until the user enters an integer less than 1. this final number is not part of the product. then, the program prints the product. if the first entered number is negative or 0, the program must print “bad input.” and terminate immediately. next, the program determines and prints the prime factorization of the product, listing the factors in increasing order. if a prime number is not a factor of the product, then it
Answers: 2
image
Computers and Technology, 22.06.2019 22:00, zay179
What is a distinguishing feature of today’s graphic application software?) graphic applications are used today on a variety of devices, including touch-screen kiosks and mobile phones.
Answers: 3
Do you know the correct answer?
Task #3 Working with Strings
1. Use the charAt method to get the first character in firstName...

Questions in other subjects: