Question: (Java) Privacy Leak. Code: package privacyLeak; public class Phone { private String number; private int totalCalls; public Phone(String number) { this.number = number; totalCalls =

(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.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!