Skip to content

Commit 4cde425

Browse files
committed
ch 03 code
1 parent 9020956 commit 4cde425

5 files changed

Lines changed: 88 additions & 0 deletions

File tree

.classpath

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="ap01"/>
4+
<classpathentry kind="src" path="ap02"/>
5+
<classpathentry kind="src" path="ch01"/>
6+
<classpathentry kind="src" path="ch02"/>
7+
<classpathentry kind="src" path="ch03"/>
8+
<classpathentry kind="src" path="ch04"/>
9+
<classpathentry kind="src" path="ch05"/>
10+
<classpathentry kind="src" path="ch06"/>
11+
<classpathentry kind="src" path="ch07"/>
12+
<classpathentry kind="src" path="ch08"/>
13+
<classpathentry kind="src" path="ch09"/>
14+
<classpathentry kind="src" path="ch10"/>
15+
<classpathentry kind="src" path="ch11"/>
16+
<classpathentry kind="src" path="ch12"/>
17+
<classpathentry kind="src" path="ch13"/>
18+
<classpathentry kind="src" path="ch14"/>
19+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
20+
<classpathentry kind="output" path="bin"/>
21+
</classpath>

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010

1111
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
1212
hs_err_pid*
13+
/bin/

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>ThinkJavaCode</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

ch03/ConvertSeconds.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* Converts number of seconds to hour, minutes, seconds.
5+
*/
6+
public class ConvertSeconds {
7+
public static void main(String[] args) {
8+
9+
int enteredSeconds;
10+
int numHours;
11+
int numMinutes;
12+
int numSeconds;
13+
14+
Scanner scannerIn = new Scanner(System.in);
15+
16+
System.out.print("How many seconds? ");
17+
enteredSeconds = scannerIn.nextInt();
18+
19+
numHours = enteredSeconds / 3600;
20+
numMinutes = (enteredSeconds % 3600) / 60;
21+
numSeconds = enteredSeconds % 60;
22+
23+
System.out.printf("%d seconds is %d hour(s), %d minutes, and %d seconds",
24+
enteredSeconds, numHours, numMinutes, numSeconds);
25+
scannerIn.close();
26+
}
27+
28+
}

ch03/Degrees.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Converts a temperature from Celsius to Fahrenheit
3+
*/
4+
5+
import java.util.Scanner;
6+
7+
public class Degrees {
8+
public static void main(String[] args) {
9+
double tempCelsius = 0.0;
10+
11+
Scanner scannerIn = new Scanner(System.in);
12+
13+
System.out.print("What is the temperature in Celsius? ");
14+
tempCelsius = scannerIn.nextDouble();
15+
16+
System.out.printf("%.1f Celsius is %.1f Fahrenheit.", tempCelsius,
17+
tempCelsius * 9.0 / 5.0 + 32 );
18+
scannerIn.close();
19+
}
20+
21+
}

0 commit comments

Comments
 (0)