Skip to content

Commit

Permalink
A few more changes to WeatherReport and added some test code.
Browse files Browse the repository at this point in the history
  • Loading branch information
muheem committed Feb 1, 2023
1 parent 0bb79cf commit ac73138
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.techreturners.encapsulation.bankaccount.model.DodgyBankAccount;
import com.techreturners.encapsulation.bankaccount.model.SecureBankAccount;

import com.techreturners.encapsulation.bankaccount.model.WeatherReporter;
public class Main {

private static final String MYACCOUNTNUMBER = "ABCDEFG123";
Expand Down Expand Up @@ -62,6 +62,20 @@ public static void main(String[] args) {
//mySecureBankAccount.accountBalance = 1000000;
mySecureBankAccount.displayAccountBalance();
System.out.println("😹 Well I guess that's secure!");


// WEATHER REPORT
WeatherReporter weatherReporter1 = new WeatherReporter("London", 7.33);
System.out.println(weatherReporter1.GetReport());

WeatherReporter weatherReporter2 = new WeatherReporter("Kingston", -33.2);
System.out.println(weatherReporter2.GetReport());

WeatherReporter weatherReporter3 = new WeatherReporter("California", 31);
System.out.println(weatherReporter3.GetReport());

WeatherReporter weatherReporter4 = new WeatherReporter("Cape Town", 10);
System.out.println(weatherReporter4.GetReport());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@

public class WeatherReporter {

private String location;
private double temperature; // in Celsius
private final String location;
private final double temperature; // in Celsius

static double fahrenheit(double c) {
return (1.8 * c) + 32;
}

public WeatherReporter(String location, double temperature) {
this.location = location;
this.temperature = temperature;
}


public String GetReport() {
double newTemp = 1.8 * (temperature) + 32;
return MessageFormat.format("I am in {0} and it is {1}. {2}. The temperature in Fahrenheit is {3}.", location, checkWeather(), checkTemperature(), newTemp);
return MessageFormat.format("I am in {0} and it is {1}. {2}. The temperature in Fahrenheit is {3}.", location,
checkWeather(), checkTemperature(), fahrenheit(temperature));
}

public String checkWeather() {
private String checkWeather() {
if (location.equals("London"))
return "🌦";
if (location.equals("California"))
Expand All @@ -28,7 +33,7 @@ public String checkWeather() {
return "🔆";
}

public String checkTemperature() {
private String checkTemperature() {
if (temperature > 30)
return "It's too hot 🥵!";
if (temperature < 10)
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit ac73138

Please sign in to comment.