Skip to content

Commit

Permalink
Added Temperaure Domain with comparison and conversion functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
aakash070 committed Jul 30, 2015
1 parent 7215a2b commit 164c550
Show file tree
Hide file tree
Showing 31 changed files with 426 additions and 272 deletions.
468 changes: 248 additions & 220 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified out/production/CheckConversion/domain/length/Centimetres.class
Binary file not shown.
Binary file modified out/production/CheckConversion/domain/length/Feet.class
Binary file not shown.
Binary file modified out/production/CheckConversion/domain/length/Inch.class
Binary file not shown.
Binary file modified out/production/CheckConversion/domain/length/Length.class
Binary file not shown.
Binary file modified out/production/CheckConversion/domain/length/Metres.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/CheckConversion/domain/volume/Cup.class
Binary file not shown.
Binary file modified out/production/CheckConversion/domain/volume/Ounce.class
Binary file not shown.
Binary file modified out/production/CheckConversion/domain/volume/TableSpoon.class
Binary file not shown.
Binary file modified out/production/CheckConversion/domain/volume/TeaSpoon.class
Binary file not shown.
Binary file modified out/production/CheckConversion/domain/volume/Volume.class
Binary file not shown.
Binary file not shown.
Binary file modified out/production/CheckConversion/tests/VolumeTest.class
Binary file not shown.
16 changes: 10 additions & 6 deletions src/domain/length/Centimetres.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/
public class Centimetres extends Length{

final double conversionFactor = 1;
private static double conversionFactor = 1;

public Centimetres(double length) {
super(1*length);
super(length);
}

@Override
Expand All @@ -17,11 +17,15 @@ public boolean equals(Object o) {
}

@Override
public double getLengthValue() {
return super.getLength();
public double getConversionFactor() {
return conversionFactor;
}

public static double convert(Length l) {
return l.getLengthValue();
public static double convert(Length length) {
return length.getLength()/conversionFactor;
}

public Centimetres add(Length length) {
return new Centimetres((this.getLength()+length.getLength())/conversionFactor);
}
}
14 changes: 9 additions & 5 deletions src/domain/length/Feet.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/
public class Feet extends Length{

final double conversionFactor = 12*2.54;
private static double conversionFactor = 12*2.54;

public Feet(double length) {
super(length*12*2.54);
super(length);
}

@Override
Expand All @@ -17,11 +17,15 @@ public boolean equals(Object o) {
}

@Override
public double getLengthValue() {
return super.getLength();
public double getConversionFactor() {
return conversionFactor;
}

public static double convert(Length l) {
return l.getLengthValue()/(12*2.54);
return l.getLength()/conversionFactor;
}

public Feet add(Length length) {
return new Feet((this.getLength()+length.getLength())/conversionFactor);
}
}
15 changes: 10 additions & 5 deletions src/domain/length/Inch.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
*/
public class Inch extends Length{

private static double conversionFactor = 2.54;

public Inch(double length) {
super(length*2.54);
super(length);
}

@Override
Expand All @@ -15,12 +17,15 @@ public boolean equals(Object o) {
}

@Override
public double getLengthValue() {
return super.getLength();
public double getConversionFactor() {
return conversionFactor;
}


public static double convert(Length l) {
return l.getLengthValue()/2.54;
return l.getLength()/conversionFactor;
}

public Inch add(Length length) {
return new Inch((this.getLength()+length.getLength())/conversionFactor);
}
}
9 changes: 2 additions & 7 deletions src/domain/length/Length.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,22 @@ public abstract class Length {
private double length;

public Length(double length) {
this.length = length;
this.length = length*this.getConversionFactor();
}

public double getLength() {
return length;
}

// public abstract double convertToBase(double l);


@Override
public boolean equals(Object o) {
if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
if(!(o instanceof Length))
return false;
Length length1 = (Length) o;

return Double.compare(length1.length, length) == 0;

}

public abstract double getLengthValue();
public abstract double getConversionFactor();
}
14 changes: 9 additions & 5 deletions src/domain/length/Metres.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/
public class Metres extends Length{

final double converSionFactor = 100;
private static double conversionFactor = 100;

public Metres(double length) {
super(100*length);
super(length);
}

@Override
Expand All @@ -17,11 +17,15 @@ public boolean equals(Object o) {
}

@Override
public double getLengthValue() {
return super.getLength();
public double getConversionFactor() {
return conversionFactor;
}

public static double convert(Length l) {
return l.getLengthValue()/100;
return l.getLength()/conversionFactor;
}

public Metres add(Length length) {
return new Metres((this.getLength()+length.getLength())/conversionFactor);
}
}
20 changes: 20 additions & 0 deletions src/domain/temperature/Celsius.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package domain.temperature;

/**
* Created by aakash on 7/30/2015.
*/
public class Celsius extends Temperature{

public Celsius(double temperature) {
super(temperature);
}

@Override
public double tempBaseValue(double temperature) {
return temperature;
}

public static Celsius convert(Temperature t) {
return new Celsius(t.getTemperature());
}
}
20 changes: 20 additions & 0 deletions src/domain/temperature/Fahrenheit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package domain.temperature;

/**
* Created by aakash on 7/30/2015.
*/
public class Fahrenheit extends Temperature{

public Fahrenheit(double temperature) {
super(temperature);
}

@Override
public double tempBaseValue(double temperature) {
return (((temperature-32)*5)/9);
}

public static Fahrenheit convert(Temperature t) {
return new Fahrenheit(((t.getTemperature()*9)/5)+32);
}
}
30 changes: 30 additions & 0 deletions src/domain/temperature/Temperature.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package domain.temperature;

/**
* Created by aakash on 7/30/2015.
*/
public abstract class Temperature {

private double temperature;

public Temperature(double temperature) {
this.temperature = tempBaseValue(temperature);
}

public double getTemperature() {
return temperature;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if(!(o instanceof Temperature))
return false;

Temperature that = (Temperature) o;

return Double.compare(that.temperature, temperature) == 0;
}

public abstract double tempBaseValue(double temperature);
}
16 changes: 11 additions & 5 deletions src/domain/volume/Cup.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
*/
public class Cup extends Volume{

private static double conversionFactor = 48;

public Cup(double volume) {
super(volume*48);
super(volume);
}

@Override
public double getVolumeValue() {
return super.getVolume();
@Override
public double getConversionFactor() {
return conversionFactor;
}

public static double convert(Volume volume) {
return volume.getVolumeValue()/48;
return volume.getVolume()/conversionFactor;
}

public Cup add(Volume volume) {
return new Cup((this.getVolume()+volume.getVolume())/conversionFactor);
}
}
14 changes: 10 additions & 4 deletions src/domain/volume/Ounce.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
*/
public class Ounce extends Volume{

private static double conversionFactor = 6;

public Ounce(double volume) {
super(volume*6);
super(volume);
}

@Override
public double getVolumeValue() {
return super.getVolume();
public double getConversionFactor() {
return conversionFactor;
}

public static double convert(Volume volume) {
return volume.getVolumeValue()/6;
return volume.getVolume()/conversionFactor;
}

public Ounce add(Volume volume) {
return new Ounce((this.getVolume()+volume.getVolume())/conversionFactor);
}
}
14 changes: 10 additions & 4 deletions src/domain/volume/TableSpoon.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@
*/
public class TableSpoon extends Volume{

private static double conversionFactor = 3;

public TableSpoon(double volume) {
super(volume*3);
super(volume);
}

@Override
public double getVolumeValue() {
return super.getVolume();
public double getConversionFactor() {
return conversionFactor;
}

public static double convert(Volume volume) {
return volume.getVolumeValue()/3;
return volume.getVolume()/conversionFactor;
}

public TableSpoon add(Volume volume) {
return new TableSpoon((this.getVolume()+volume.getVolume())/conversionFactor);
}
}
11 changes: 8 additions & 3 deletions src/domain/volume/TeaSpoon.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
*/
public class TeaSpoon extends Volume{

private static double conversionFactor = 1;

public TeaSpoon(double volume) {
super(volume);
}

@Override
public double getVolumeValue() {
return super.getVolume();
public double getConversionFactor() {
return conversionFactor;
}

public static double convert(Volume volume) {
return volume.getVolumeValue();
return volume.getVolume()/conversionFactor;
}

public TeaSpoon add(Volume volume) {
return new TeaSpoon((this.getVolume()+volume.getVolume())/conversionFactor);
}
}
4 changes: 2 additions & 2 deletions src/domain/volume/Volume.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public abstract class Volume {
private double volume;

public Volume(double volume) {
this.volume = volume;
this.volume = volume*this.getConversionFactor();
}

public double getVolume() {
Expand All @@ -27,5 +27,5 @@ public boolean equals(Object o) {
return Double.compare(volume1.volume, volume) == 0;
}

public abstract double getVolumeValue();
public abstract double getConversionFactor();
}
25 changes: 25 additions & 0 deletions src/tests/TemperatureTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package tests;

import domain.temperature.Celsius;
import domain.temperature.Fahrenheit;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by aakash on 7/30/2015.
*/
public class TemperatureTest {

@Test
public void checkComparisonBetweenCelsiusAndFahrenheit(){
assertTrue(new Celsius(40).equals(new Fahrenheit(104)));
}

@Test
public void checkConversionFromFahrenheitToCelsius() {

assertEquals(40,Celsius.convert(new Fahrenheit(104)).getTemperature(),0.00001);
}

}
8 changes: 2 additions & 6 deletions src/tests/VolumeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ public void checkComparisonBetweenTbspAndCup() {

@Test
public void checkConversionFromOunceToTeaspoon() {
Ounce onz = new Ounce(2);
double tsp = TeaSpoon.convert(onz);

TeaSpoon teaSpoon = new TeaSpoon(tsp);

double tsp = TeaSpoon.convert(new Ounce(2));
assertEquals(12,tsp,0.00001);
assertTrue(teaSpoon.equals(onz));
assertTrue(new TeaSpoon(tsp).equals(new Ounce(2)));
}
}

0 comments on commit 164c550

Please sign in to comment.