Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please finish this by using java.If u run StudentBody.java the output should be the same as the picture showing b Write an interface called Lock

Please finish this by using java.If u run StudentBody.java the output should be the same as the picture showing b

Write an interface called Lock which has 2 methods which are called lock and unlock. The methods have no parameters and return nothing.

A class X which implements the Lock interface behaves normally if it is unlocked. If locked, the toString method returns X is locked.. Either all of Xs objects are locked, or all unlocked. Initially, the class is unlocked. Calling the lock method with one object of type X, locks all the objects of type X. Similarly for unlock.

Your output must be exactly as shown below:

image text in transcribed

//******************************************************************** // Address.java Author: Lewis/Loftus // // Represents a street address. //********************************************************************

public class Address { private String streetAddress, city, state; private long zipCode;

public Address (String street, String town, String st, long zip) { streetAddress = street; city = town; state = st; zipCode = zip; } public String toString() { String result;

result = streetAddress + " "; result += city + ", " + state + " " + zipCode;

return result; } }

//******************************************************************** // Student.java Author: Lewis/Loftus // // Represents a college student. //********************************************************************

public class Student { private int grade; private String firstName, lastName; private Address homeAddress, schoolAddress;

public Student (String first, String last, Address home, Address school,int grade1) { firstName = first; lastName = last; homeAddress = home; schoolAddress = school; grade = grade1; }

public String toString() { String result;

result = firstName + " " + lastName + " "; result += "Grade: "+grade; result += "Home Address: " + homeAddress + " "; result += "School Address: " + schoolAddress;

return result; } }

//******************************************************************** // StudentBody.java Author: Lewis/Loftus // // Demonstrates the use of an aggregate class, and an interface. //********************************************************************

public class StudentBody { public static void main(String[] args) { Address school = new Address("800 Lancaster Ave.", "Villanova", "PA", 19085); Address jHome = new Address("21 Jump Street", "Blacksburg", "VA", 24551); Student john = new Student("John", "Smith", jHome, school,0); Student adam = new Student("Adam", "Smith", jHome, school, 80);

Address mHome = new Address("123 Main Street", "Euclid", "OH", 44132); Student marsha = new Student("Marsha", "Jones", mHome, school,0);

System.out.println(john); System.out.println(); System.out.println(adam); System.out.println(); System.out.println(marsha); school.lock(); System.out.println(); System.out.println(john); System.out.println(); System.out.println(adam); System.out.println(); System.out.println(marsha); john.lock(); System.out.println(); System.out.println(john); System.out.println(); System.out.println(adam); System.out.println(); System.out.println(marsha); adam.unlock(); System.out.println(); System.out.println(john); System.out.println(); System.out.println(adam); System.out.println(); System.out.println(marsha); } }

Velcome to DrJava Vorki run StudentBody John Smith Grade: 0 Hone Address: 1 Juap Street Blacksburg, VA 24551 Sehool Address 800 Lancaster Avre Villanova, PA 19085 Adam Smith Grade: 00 Hone Address: l Jump Street Blachsburg, VA 24551 School Address: 800 Lancaster Ave Villanova, PA 19005 Mar sha Jones Grade: 0 Hone Address: 123 Main Street Euclid, OH 4413 School Address: 800 Lancaster Ave Villanova, PA 19085 John Smith Grade: o Address is locked School Address: Address is locked Adan Smith Grade: 00 Hone AddresS Addr ess is Loel:edd Sehool Address Address is locked Marsha Jones Grade: 0 Home Address Address is locked School Address: Address is locked Seudent is locked Student is Locked Scudent is 1ocked John Smith Grade: 0 Home Address Address is locked School Address: Address is locked Adam Smitlh Grade: 00 Address is locked School Address: Address is locked Marsha Jones Grade: 0 Home Address Address is locl:ed School ?ddress

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_2

Step: 3

blur-text-image_3

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

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

5. Describe the relationship between history and identity.

Answered: 1 week ago