Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions

Question

Why is lubrication often a major concern in metalforming?

Answered: 1 week ago

Question

Did you pick a topic that you know all about?

Answered: 1 week ago