Skip to content

Commit bab99a9

Browse files
committed
4-B-6
1 parent c7ea0c2 commit bab99a9

3 files changed

Lines changed: 130 additions & 0 deletions

File tree

ch04/Employee.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import java.util.Random;
2+
import java.util.Scanner;
3+
4+
public class Employee
5+
{
6+
public static void main(String[] args)
7+
{
8+
Scanner scanner = new Scanner(System.in);
9+
int birthYear = 1998;
10+
boolean isUnionMember = true;
11+
String firstName = "Sigh";
12+
String middleName = "Lent";
13+
String lastName = "Tee";
14+
int employeeNumber;
15+
16+
printHeader();
17+
18+
System.out.println("Please enter your 5 digit employee number: ");
19+
employeeNumber = scanner.nextInt();
20+
21+
printFullName(firstName, middleName, lastName);
22+
23+
printUnionStatus(isUnionMember);
24+
25+
printAge(birthYear);
26+
27+
printEvenOrOdd(employeeNumber);
28+
29+
printGeneratedSecretPassword(employeeNumber);
30+
}
31+
32+
public static void printHeader()
33+
{
34+
System.out.println("Welcome to the WallabyTech Employee Application");
35+
System.out.println("===============================================");
36+
}
37+
38+
public static void printFullName(String firstN, String middleN, String lastN)
39+
{
40+
System.out.print(lastN + ", ");
41+
System.out.print(firstN + " ");
42+
System.out.println(middleN);
43+
}
44+
45+
public static void printUnionStatus(boolean tOrF)
46+
{
47+
System.out.println("Your union status is: " + tOrF);
48+
}
49+
50+
public static void printAge(int yearBorn)
51+
{
52+
int currentYear = 2018;
53+
int employeeAge = currentYear - yearBorn;
54+
System.out.println("Your age is: " + employeeAge);
55+
}
56+
57+
public static void printEvenOrOdd(int evenOdd)
58+
{
59+
int evenOddMath = evenOdd % 2;
60+
System.out.print("Employee number is even/odd (1=odd, 0=even);");
61+
System.out.println(evenOddMath);
62+
}
63+
64+
public static void printGeneratedSecretPassword(int empNumber)
65+
{
66+
// pick a random number
67+
Random random = new Random();
68+
int randomNumber = random.nextInt(10) + 1;
69+
70+
int password = (empNumber + randomNumber) * 5;
71+
72+
System.out.println("Employee's random secret pw is: " + password);
73+
}
74+
}

ch04/NewCelsiusToFahrenheit.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.util.Scanner;
2+
3+
public class NewCelsiusToFahrenheit
4+
{
5+
public static void main(String[] args)
6+
{
7+
Scanner input = new Scanner(System.in);
8+
System.out.print("Enter degrees in Celsius: ");
9+
double degreesEntered = input.nextDouble();
10+
11+
printFahrenheit(degreesEntered);
12+
System.out.println();
13+
printKelvin(degreesEntered);
14+
}
15+
16+
public static void printFahrenheit(double celsius)
17+
{
18+
19+
double fahrenheit = celsius * 9 / 5 + 32;
20+
System.out.printf("Degrees in Fahrenheit: %.1f", fahrenheit);
21+
22+
}
23+
24+
public static void printKelvin(double celsius)
25+
{
26+
double kelvin = celsius + 273.15;
27+
System.out.printf("Degrees in Kelvin: %.2f", kelvin);
28+
}
29+
}

ch04/NewToungeWeight.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.Scanner;
2+
3+
public class NewToungeWeight
4+
{
5+
public static void main(String[] args)
6+
{
7+
Scanner input = new Scanner(System.in);
8+
9+
System.out.print("Enter weight of trailer: ");
10+
double trailerWeight = input.nextDouble();
11+
12+
System.out.print("Enter weight of cargo: ");
13+
double cargoWeight = input.nextDouble();
14+
15+
printRange(trailerWeight, cargoWeight);
16+
}
17+
18+
public static void printRange(double trailer, double cargo)
19+
{
20+
double totalWeight = trailer + cargo;
21+
double maxWeight = totalWeight * 0.15;
22+
double minWeight = totalWeight * 0.09;
23+
24+
System.out.printf("Maximum tongue weight: %.2f\n", maxWeight);
25+
System.out.printf("Minimum tongue weight: %.2f", minWeight);
26+
}
27+
}

0 commit comments

Comments
 (0)