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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started