-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added boiling and freezing point exercises
- Loading branch information
1 parent
99acb15
commit d3621dd
Showing
2 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
151 changes: 151 additions & 0 deletions
151
src/main/java/com/levelup/java/exercises/beginner/FreezingAndBoilingPoints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package com.levelup.java.exercises.beginner; | ||
|
||
import java.util.Scanner; | ||
|
||
/** | ||
* This java example will demonstrate a solution to the Freezing and boiling exercise. | ||
* | ||
* @author Justin Musgrove | ||
* @see <a href='http://www.leveluplunch.com/java/exercises/freezing-boiling-points/'>Freezing and Boiling Points</a> | ||
*/ | ||
public class FreezingAndBoilingPoints { | ||
|
||
public class FreezeAndBoiling { | ||
|
||
private double temperature; | ||
|
||
public FreezeAndBoiling(double t) { | ||
temperature = t; | ||
} | ||
|
||
public double getTemperature() { | ||
return temperature; | ||
} | ||
|
||
/** | ||
* Method should check if the temperature is freezing | ||
* | ||
* @return true if Ethyl is freezing | ||
*/ | ||
public boolean isEthylAlchoolFreezing() { | ||
|
||
if (temperature <= -173.0) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Method should check if the temperature is boiling | ||
* | ||
* @return true if Ethyl is boiling | ||
*/ | ||
public boolean isEthylAlchoolBoiling() { | ||
|
||
if (temperature >= 172.0) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Method should check if the temperature is freezing | ||
* | ||
* @return true if Oxygen is freezing | ||
*/ | ||
public boolean isOxygenFreezing() { | ||
|
||
if (temperature <= -362.0) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Method should check if the temperature is boiling | ||
* | ||
* @return true if Oxygen is boiling | ||
*/ | ||
public boolean isOxygenBoiling() { | ||
|
||
if (temperature >= -306.0) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Method should check if the temperature is freezing | ||
* | ||
* @return true if Water is freezing | ||
*/ | ||
public boolean isWaterFreezing() { | ||
|
||
if (temperature <= 32.0) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Method should check if the temperature is boiling | ||
* | ||
* @return true if Water is boiling | ||
*/ | ||
public boolean isWaterBoiling() { | ||
|
||
if (temperature >= 212.0) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
// Create a Scanner object for keyboard input. | ||
Scanner keyboard = new Scanner(System.in); | ||
|
||
System.out.print("Enter a temperature: "); | ||
double temperature = keyboard.nextDouble(); | ||
|
||
// close keyboard | ||
keyboard.close(); | ||
|
||
FreezingAndBoilingPoints freezeAndBoilingPoints = new FreezingAndBoilingPoints(); | ||
FreezeAndBoiling freezeAndBoiling = freezeAndBoilingPoints.new FreezeAndBoiling( | ||
temperature); | ||
|
||
// Display elements will freeze. | ||
if (freezeAndBoiling.isEthylAlchoolBoiling()) { | ||
System.out.println("Ethyl alcohol will freeze."); | ||
} | ||
|
||
if (freezeAndBoiling.isOxygenFreezing()) { | ||
System.out.println("Oxygen will freeze."); | ||
} | ||
|
||
if (freezeAndBoiling.isWaterFreezing()) | ||
System.out.println("Water will freeze."); | ||
|
||
// Display if elements will boil. | ||
if (freezeAndBoiling.isEthylAlchoolBoiling()) { | ||
System.out.println("Ethyl alcohol will boil."); | ||
} | ||
|
||
if (freezeAndBoiling.isOxygenBoiling()) { | ||
System.out.println("Oxygen will boil."); | ||
} | ||
|
||
if (freezeAndBoiling.isWaterBoiling()) { | ||
System.out.println("Water will boil."); | ||
} | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
src/test/java/com/levelup/java/exercises/beginner/FreezingAndBoilingPointsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.levelup.java.exercises.beginner; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
import com.levelup.java.exercises.beginner.FreezingAndBoilingPoints.FreezeAndBoiling; | ||
|
||
/** | ||
* Unit test for {@link FreezingAndBoilingPoints} | ||
* | ||
* @author Justin Musgrove | ||
* @see <a href='http://www.leveluplunch.com/java/exercises/freezing-boiling-points/'>Freezing and Boiling Points</a> | ||
*/ | ||
public class FreezingAndBoilingPointsTest { | ||
|
||
@Test | ||
public void test_isEthylAlchoolFreezing() { | ||
|
||
FreezingAndBoilingPoints freezeAndBoilingPoints = new FreezingAndBoilingPoints(); | ||
FreezeAndBoiling freezeAndBoiling = freezeAndBoilingPoints.new FreezeAndBoiling( | ||
-174); | ||
|
||
assertTrue(freezeAndBoiling.isEthylAlchoolFreezing()); | ||
} | ||
|
||
@Test | ||
public void test_isEthylAlchoolBoiling() { | ||
|
||
FreezingAndBoilingPoints freezeAndBoilingPoints = new FreezingAndBoilingPoints(); | ||
FreezeAndBoiling freezeAndBoiling = freezeAndBoilingPoints.new FreezeAndBoiling( | ||
172); | ||
|
||
assertTrue(freezeAndBoiling.isEthylAlchoolBoiling()); | ||
} | ||
|
||
@Test | ||
public void test_isOxygenFreezing() { | ||
|
||
FreezingAndBoilingPoints freezeAndBoilingPoints = new FreezingAndBoilingPoints(); | ||
FreezeAndBoiling freezeAndBoiling = freezeAndBoilingPoints.new FreezeAndBoiling( | ||
-400); | ||
|
||
assertTrue(freezeAndBoiling.isOxygenFreezing()); | ||
} | ||
|
||
@Test | ||
public void test_isOxygenBoiling() { | ||
|
||
FreezingAndBoilingPoints freezeAndBoilingPoints = new FreezingAndBoilingPoints(); | ||
FreezeAndBoiling freezeAndBoiling = freezeAndBoilingPoints.new FreezeAndBoiling( | ||
-362); | ||
|
||
assertTrue(freezeAndBoiling.isOxygenFreezing()); | ||
} | ||
|
||
@Test | ||
public void test_isWaterFreezing() { | ||
|
||
FreezingAndBoilingPoints freezeAndBoilingPoints = new FreezingAndBoilingPoints(); | ||
FreezeAndBoiling freezeAndBoiling = freezeAndBoilingPoints.new FreezeAndBoiling( | ||
10); | ||
|
||
assertTrue(freezeAndBoiling.isWaterFreezing()); | ||
} | ||
|
||
@Test | ||
public void test_isWaterBoiling() { | ||
|
||
FreezingAndBoilingPoints freezeAndBoilingPoints = new FreezingAndBoilingPoints(); | ||
FreezeAndBoiling freezeAndBoiling = freezeAndBoilingPoints.new FreezeAndBoiling( | ||
213); | ||
|
||
assertTrue(freezeAndBoiling.isWaterBoiling()); | ||
} | ||
|
||
} |