Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: techreturners/short-exercise-oop-encapsulation
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: muheem/short-exercise-oop-encapsulation
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Feb 1, 2023

  1. Copy the full SHA
    387641e View commit details
  2. Refactored WeatherReport.java

    muheem committed Feb 1, 2023
    Copy the full SHA
    0bb79cf View commit details
  3. Copy the full SHA
    ac73138 View commit details
Original file line number Diff line number Diff line change
@@ -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";
@@ -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
@@ -4,49 +4,40 @@

public class WeatherReporter {

public String location;
public double temperature;
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 print() {

double newTemp = (9.0 / 5.0) * temperature + 32;
return MessageFormat.format("I am in {0} and it is {1}. {2}. The temperature in Fahrenheit is {3}.", location, check1(), check2(), newTemp);

public String GetReport() {
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 check1() {
if (location == "London") {

private String checkWeather() {
if (location.equals("London"))
return "🌦";

} else if (location == "California") {

if (location.equals("California"))
return "🌅";

} else if (location == "Cape Town") {

if (location.equals("Cape Town"))
return "🌤";

}
return "🔆";
}

public String check2() {
if (temperature > 30) {

private String checkTemperature() {
if (temperature > 30)
return "It's too hot 🥵!";

} else if (temperature < 10) {

if (temperature < 10)
return "It's too cold 🥶!";

}
return "Ahhh...it's just right 😊!";
}

}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.