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

image text in transcribed

image text in transcribed

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 autolD(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 1. Make Account, Contact, and Box implement the Identifiable interface. 2. Implement the id0 method as described below for the Account, Contact, and Box classes. 3. Implement an override of the dressedID( method for the Contact class as described below. 4. Implement an overrice of the static autolD0 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 id0 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.id0 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 0 .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 "Post 335 Pre" Calls to Identifier.autolD(i) returns 1000+i, where i is an integer. Box.autolD(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 returns "Pre91Post" However, the Contact class override of dressedID() does the following: myContact. dressedID ("Pre", "Post") returns "Post 335Pre" Calls to Identifier.autolD(i) returns 1000+i, where i is an integer. Box.autolD(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 autolD(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. 37.5.1: Creating and Using an Interface 0/4

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

International Baccalaureate Computer Science HL And SL Option A Databases Part I Basic Concepts

Authors: H Sarah Shakibi PhD

1st Edition

1542457084, 978-1542457088

More Books

Students also viewed these Databases questions