Skip to content

Commit

Permalink
added boiling and freezing point exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmusgrove committed Jun 1, 2014
1 parent 99acb15 commit d3621dd
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 0 deletions.
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.");
}
}

}
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());
}

}

0 comments on commit d3621dd

Please sign in to comment.