From 899b1a33c79fab6909e863d1c308a42c8299033e Mon Sep 17 00:00:00 2001 From: propenster <51266654+propenster@users.noreply.github.com> Date: Mon, 10 Jun 2019 19:11:05 +0100 Subject: [PATCH] Update Goodbye.java Added instance variables to the class. Added setter and getter methods for perfect encapsulation. Added comments for documentation --- ch01/Goodbye.java | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/ch01/Goodbye.java b/ch01/Goodbye.java index 2963e2e..bdf4887 100644 --- a/ch01/Goodbye.java +++ b/ch01/Goodbye.java @@ -2,13 +2,48 @@ * Example program that demonstrates print vs println. */ public class Goodbye { + //Instance variables + private String name, status; + //Static class-wide counter variable. + private static int id = 0; + + public Goodbye(String n, String s){ + this.name = n; + this.status = s; + id += 1; + } + /** + * Setter and Getter methods for Encapsulation + */ + public void setName(String name){ + this.name = name; } + public String getName(){ + return this.name;} + public void setStatus(String status){ + this.status = status;} + public String getStatus(){ + return this.status;} + //Handler method for output + public void getGoodbyeInfo(){ + System.out.println("Name: "+getName()); + System.out.println("Current Status: "+getStatus()); + System.out.println("ID: "+this.id); + + + +} /** * Prints a greeting. */ public static void main(String[] args) { System.out.print("Goodbye, "); // note the space System.out.println("cruel world"); + System.out.println("I'm being no longer with you"); +//Instantiate a new object of class Goodbye + + Goodbye obj1 = new Goodbye("HP-LAT-1946IPV0", "Running"); + obj1.getGoodbyeInfo(); } }