commit cc44eff9f0f220cac4f921586ecd8b98ad9fd855
parent 38f7060fdb3bbc0a5e5c29135db8bff26b0d7818
Author: William Lindholm <william_lindholm@outlook.com>
Date: Thu, 4 May 2023 23:26:33 +0200
Modified toString to genereate human readable description, and added getters and setters for all class variables. getMass parses value to double.
Diffstat:
1 file changed, 58 insertions(+), 8 deletions(-)
diff --git a/app/src/main/java/com/example/project_assignment/Meteorite.java b/app/src/main/java/com/example/project_assignment/Meteorite.java
@@ -25,14 +25,12 @@ public class Meteorite implements Parcelable {
@Override
public String toString() {
- return "Meteorite{" +
- "name='" + name + '\'' +
- ", id='" + id + '\'' +
- ", mass='" + mass + '\'' +
- ", date='" + date + '\'' +
- ", latitude='" + latitude + '\'' +
- ", longitude='" + longitude + '\'' +
- '}';
+ return "The meteorite " + name +
+ "has a mass of " + mass + "kg " +
+ "and touched the surface of the earth at " +
+ date + "\n\n" +
+ "It landed at lat: " + latitude +
+ " long: " + longitude;
}
protected Meteorite(Parcel in) {
name = in.readString();
@@ -71,4 +69,56 @@ public class Meteorite implements Parcelable {
parcel.writeString(latitude);
parcel.writeString(longitude);
}
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public double getMass() {
+ if (mass == null) {
+ return 0;
+ }
+ double mass_double = Double.parseDouble(mass);
+ return mass_double;
+ }
+
+ public void setMass(String mass) {
+ this.mass = mass;
+ }
+
+ public String getDate() {
+ return date;
+ }
+
+ public void setDate(String date) {
+ this.date = date;
+ }
+
+ public String getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(String latitude) {
+ this.latitude = latitude;
+ }
+
+ public String getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(String longitude) {
+ this.longitude = longitude;
+ }
}