Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Java) Privacy Leak. Code: package privacyLeak; public class Phone { private Str

ID: 3700165 • Letter: #

Question

(Java) Privacy Leak.

Code:

package privacyLeak;

public class Phone {

private String number;

private int totalCalls;

public Phone(String number) {

this.number = number;

totalCalls = 0;

}

public String getNumber() {

return number;  

}

public int getTotalCalls() {

return totalCalls;

}

public void placeCall() {

totalCalls++;

}

}

package privacyLeak;

public class Customer {

private String name;

private Phone phone;

private String address;

public Customer(String name, String phoneNumber, String address) {

this.name = name;

phone = new Phone(phoneNumber);

this.address = address;

}

public String toString(){

return name + ", " + address;

}

public void placeCall() {

phone.placeCall();

}

public Phone getPhone() { // Does it generate a privacy leak?

return phone;

}

public String getName() { // Does it generate a privacy leak?

return name;

}

}

package privacyLeak;

public class Driver {

public static void main(String[] args) {

Customer mary = new Customer("Mary", "301-555-4444", "College Park");

System.out.println(mary);

/* Only Mary should be able to place a call */

mary.placeCall();

Phone marysPhone = mary.getPhone();

System.out.println("Total Calls: " + marysPhone.getTotalCalls());

/*

* We are placing a call using Mary's phone (only Mary should be able

* to do it)

*/

marysPhone.placeCall();

System.out.println("Total Calls: " + marysPhone.getTotalCalls());

}

}

Explain why there is a privacy leak, that is explain why marysPhone can use placeCall() method and tell us how to fix it.

Explanation / Answer

The code is executing perfectly.

The getPhone() method inside the Customer class will return the Phone class reference.

By using the reference of the Phone class we are getting the total no of calls mede from the phone using the method getTotalCalls() .By using this method we are getting total no of calles made from that phone.

______________Thank You