stuff
This commit is contained in:
parent
5073cfb137
commit
c884acd6e2
47
src/main/java/tech/nevets/STNumericTypes.java
Normal file
47
src/main/java/tech/nevets/STNumericTypes.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package tech.nevets;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class STNumericTypes {
|
||||||
|
static final int NUMBER = 2;
|
||||||
|
static final int SCORE1 = 100;
|
||||||
|
static final int SCORE2 = 95;
|
||||||
|
static final int BOILING_IN_F = 212;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int fToC;
|
||||||
|
double average;
|
||||||
|
String output;
|
||||||
|
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
average = (double) (SCORE1 + SCORE2) / NUMBER;
|
||||||
|
output = SCORE1 + " and " + SCORE2 + " have an average of " + average;
|
||||||
|
System.out.println(output);
|
||||||
|
|
||||||
|
fToC = Math.round((5 / 9F) * (BOILING_IN_F - 32));
|
||||||
|
output = BOILING_IN_F + " in Fahrenheit is " + fToC + " in Celsius.";
|
||||||
|
System.out.println(output);
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
System.out.print("Enter First Name: ");
|
||||||
|
String firstName = sc.nextLine();
|
||||||
|
System.out.print("Enter Last Name: ");
|
||||||
|
String lastName = sc.nextLine();
|
||||||
|
System.out.println(firstName + " " + lastName);
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
char firstInitial = firstName.charAt(0);
|
||||||
|
System.out.println(firstInitial);
|
||||||
|
String nameUpper = firstName.toUpperCase();
|
||||||
|
System.out.println(nameUpper);
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
System.out.println("Enter Sphere Diameter: ");
|
||||||
|
int sphereDiameter = sc.nextInt();
|
||||||
|
float sphereRadius = sphereDiameter / 2.0F;
|
||||||
|
float sphereVolume = (float) ((4 / 3F) * Math.PI * (sphereRadius * sphereRadius * sphereRadius));
|
||||||
|
System.out.println(sphereVolume);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
41
src/main/java/tech/nevets/STNumericTypesAlgorithm.txt
Normal file
41
src/main/java/tech/nevets/STNumericTypesAlgorithm.txt
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
// This program will demonstrate the function of numeric operators
|
||||||
|
|
||||||
|
// Class declarator
|
||||||
|
// Main method head
|
||||||
|
|
||||||
|
Create Scanner Object
|
||||||
|
|
||||||
|
Create constant ints for NUMBER = 2, SCORE1 = 100, SCORE2 = 95, and BOILING_IN_F = 212
|
||||||
|
Create int named fToC
|
||||||
|
Create double named average
|
||||||
|
Create String named output
|
||||||
|
|
||||||
|
Set average to SCORE1 plus SCORE2, all divided by NUMBER
|
||||||
|
Set output to SCORE1 appending " and " appending average appending " have an average of " appending average
|
||||||
|
Print output to the console
|
||||||
|
|
||||||
|
// This converts Fahrenheit to Celsius
|
||||||
|
Set fToC to 5 divided by 9 all times (BOILING_IN_F minus 32)
|
||||||
|
Set output to BOILING_IN_F appending " in Fahrenheit is " appending fToC appending " in Celsius."
|
||||||
|
Print output to the console
|
||||||
|
Print a newline to the console
|
||||||
|
|
||||||
|
// Reads user's first and last name, then appends them
|
||||||
|
Print "Enter First Name: " to console
|
||||||
|
Use previously created scanner object to read the String, setting it to variable firstName
|
||||||
|
Print "Enter Last Name: " to console
|
||||||
|
Use scanner object to read the String, setting it to variable lastName
|
||||||
|
Print firstName appending lastName to the console
|
||||||
|
Print newline to the console
|
||||||
|
|
||||||
|
Use the String method charAt passing in 0 to get the first char in the first name, setting that to a new char variable named firstInitial
|
||||||
|
Print firstInitial to the console
|
||||||
|
Use the String method toUpperCase, setting that to a new String variable named nameUpper
|
||||||
|
Print nameUpper to the console
|
||||||
|
Print newline to the console
|
||||||
|
|
||||||
|
Print "Enter Sphere Diameter: " to console
|
||||||
|
Use scanner object to get the entered int, setting it to a new variable named sphereDiameter
|
||||||
|
Create new float named sphereRadius, setting it to shpereDiameter divided by 2.0F
|
||||||
|
Create a new float named sphereVolume, setting it to (4 / 3F) * Math.PI * (sphereRadius * sphereRadius * sphereRadius)
|
||||||
|
Print sphereVolume to the console
|
@ -1,5 +1,9 @@
|
|||||||
package tech.nevets;
|
package tech.nevets;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Steven Tracey
|
||||||
|
*/
|
||||||
|
|
||||||
public class STWelcome {
|
public class STWelcome {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Welcome to Java Programming.");
|
System.out.println("Welcome to Java Programming.");
|
||||||
@ -7,8 +11,8 @@ public class STWelcome {
|
|||||||
System.out.println("will be awesome!");
|
System.out.println("will be awesome!");
|
||||||
System.out.println("I promise not to cheat in this class");
|
System.out.println("I promise not to cheat in this class");
|
||||||
System.out.println("If caught, I will be withdrawn with an F grade");
|
System.out.println("If caught, I will be withdrawn with an F grade");
|
||||||
System.out.println("Como estas hoy");
|
System.out.println("Como estas hoy"); // Lang: Spanish
|
||||||
System.out.println("J'espere que tu aimes ce cours");
|
System.out.println("J'espere que tu aimes ce cours"); // Lang: French
|
||||||
System.out.println("Byona gironata");
|
System.out.println("Byona gironata"); // Lang: Italian
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
src/main/java/tech/nevets/Test.java
Normal file
12
src/main/java/tech/nevets/Test.java
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package tech.nevets;
|
||||||
|
|
||||||
|
public class Test {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int i = 5;
|
||||||
|
System.out.println("i is 5, next int is prefixed");
|
||||||
|
System.out.println(++i);
|
||||||
|
i = 5;
|
||||||
|
System.out.println("i is 5, next int is postfixed");
|
||||||
|
System.out.println(i++);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user