-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumericTypes.java
115 lines (80 loc) · 3.24 KB
/
NumericTypes.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//Captain-Price-TF-141
//TASK #2 Add an import statement for the Scanner class
import java.util.Scanner;
/**
This program demonstrates how numeric types and
operators behave in Java.
*/
public class NumericTypes
{
public static void main (String [] args)
{
// TASK #2 Create a Scanner object here
Scanner keyboard = new Scanner (System.in);
// (not used for alternate)
// 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; // Boiling temperature
final int fToC; // Temperature Celsius
double average; // Arithmetic average
String output; // Line of output
// TASK #2 declare variables used here
String firstName;
String lastName;
String fullName;
// TASK #3 declare variables used here
char firstInitial;
// TASK #4 declare variables used here
double diameter, radius, volume;
// Find an arithmetic average.
average = ((double)SCORE1 + SCORE2) / NUMBER;
output = SCORE1 + " and " + SCORE2 +
" have an average of " + average;
System.out.println(output);
// Convert Fahrenheit temperature 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("enter your first name ");
// Read the user's first name
firstName = keyboard.nextLine();
// Prompt the user for last name
System.out.print("enter your last name ");
// Read the user's last name
lastName = keyboard.nextLine();
// Concatenate the user's first and last names
fullName = firstName + " " + lastName;
// Print out the user's full name
System.out.println(fullName + " has " + fullName.length() + " characters");
System.out.println(); // To leave a blank line
// ADD LINES FOR TASK #3 HERE
// Get the first character from the user's first name
firstInitial = firstName.charAt(0);
// Print out the user's first initial
System.out.println("first initial: " + firstInitial);
System.out.println(); // To leave a blank line
// Convert the user's full name to uppercase
fullName = fullName.toUpperCase();
// Print out the user's full name in uppercase
System.out.println("full name in all capital: " + fullName);
System.out.println(); // To leave a blank line
// ADD LINES FOR TASK #4 HERE
// Prompt the user for a diameter of a sphere
System.out.print("enter a diameter of a sphere: ");
// Read the diameter
diameter = keyboard.nextDouble();
// Calculate the radius
radius = diameter / 2;
// Calculate the volume
volume = (4 * (Math.PI) * (Math.pow(radius, 3)) / 3);
// Print out the volume
System.out.println("the volume is: " + volume);
System.out.println(); // To leave a blank line
}
}