Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

37.5 Creating and Using an Interface In this lab, you will write an interface, called Identifiable, which defines three methods: Integer id(): the only abstract

37.5 Creating and Using an Interface In this lab, you will write an interface, called Identifiable, which defines three methods: Integer id(): the only abstract method which returns an Integer object as implemented by the class String dressedID(String pre, String post): a default method, whose default implement surrounds the value from id() by a pair of strings, pre and post static Integer autoID(int i): a static method that returns an Integer object by adding i to a static int variable defined by Identifiable The lab has a Main method, which is read only You will perform the following tasks Make Account, Contact, and Box implement the Identifiable interface. Implement the id() method as described below for the Account, Contact, and Box classes. Implement an override of the dressedID() method for the Contact class as described below. Implement an overrice of the static autoID() method for the Box class as described below. It has definitions for three classes: Account, Contact, and Box. For each, you are to write an implementation of id() to implement the Identifiable interface. For the Account class, the implementation of id() should sum the characters of the account name variable add that to the whole value of the account balance divide the sum by 10000 to get the remainder add the remainder to 10000 to get a number between 10000 and 19999 inclusive return this number For the Contact class, the implementation of id() should sum the characters of the contact name variable return the sum plus the contact age For the Box class, the implementation of id() should return the integer part of the sum of the length, height, and width variables. For example, if the name of the Account class object myAccount is "Joe" and the balance is 500.00, then the myAccount.id() returns 10786 If the name of the Contact class object myContact is "Sue" and the age is 34, then myContact.id() returns 335 If the length, height, and width variables of the Box class object myBox are 30.1, 30.5, and 30.6, then myBox().id() returns 91 For the preceding examples, the default dressedID("Pre", "Post") returns myAccount.dressedID("Pre", "Post") returns "Pre10783Post" and ```myContact.dressedID("Pre", "Post") returns "Pre335Post" and myBox.dressedID("Pre", "Post") returns "Pre91Post" However, the Contact class override of dressedID() does the following: myContact.dressedID("Pre", "Post") returns "Post335Pre" Calls to Identifier.autoID(i) returns 1000+i, where i is an integer. Box.autoID(i),returns consecutive values starting from 2000. Implementing the id() method in each of the three classes will allow you to pass Test #1: and Test #3:. To pass Test #2:, you must override the implementation of dressedID() in the Contact class implementation. The Contact class implementation of dressedID(String pre, String post) works like the default version, but reverses the positions of the pre and post strings in the returned value. To pass Test#4:, you must override the autoID(int i) method in the Box class implementation so that it simply auto increments a static integer variable of the Box class that is initialized to 2000.

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

Students also viewed these Databases questions

Question

1. Choose as precise or as concrete a word as possible.

Answered: 1 week ago