Construct a streetaddress object in which the number is 650

Assignment Help Computer Engineering
Reference no: EM133369155

A class that needs your help

Question 1. This class does not employ appropriate encapsulation. In section 2-1 of ps3_partI, revise the class to prevent direct access to the internals of a StreetAddress object while allowing indirect access through appropriate methods. Your revised version should include:

- whatever steps are needed to prevent direct access to the fields

- accessor methods that can be used to obtain the value of each field

- methods that can be used to change the value of each field. These methods should ensure that num is always greater than 0, and that name is no more than 30 characters long. Any attempt to assign an invalid value should produce an IllegalArgumentException.

- a constructor that initializes the fields of a newly created StreetAddress object to the values specified by the parameters of the constructor. Any attempt to specify an invalid value should produce an IllegalArgumentException. Take advantage of the error-checking code that is already present in the methods that you defined for changing the values of the fields.

No other methods are required.

Question 2. Now imagine that you're writing client code for your revised StreetAddress class - i.e., code in a different class that uses StreetAddress objects. For each of the following tasks, write a single line of client code to accomplish the task:

a. Construct a StreetAddress object in which the number is 650 and the name is "Commonwealth Avenue" and assign it to a properly declared variable named ccds (short for "Center for Computing and Data Sciences", the new home of the CS department!).

b. Your friend points out that the correct street number for the new building is 665, not 650. Change the value of the num field in the object that you created in part (a), giving it a value of 665. You should not create a new object; you should change the internals of the existing object.

Important: As a result of your changes from part 1, clients no longer have direct access to the fields in a StreetAddress object. As a result, you will need to make a method call to change the appropriate field. 

c. Get the name component of the StreetAddress object that you created in part (a), and assign it to a properly declared variable named streetName. Here again, you will need to make an appropriate method call.

d. Now imagine that you are given a second StreetAddress object that has been created by someone else and has been assigned to the variable addr. Change the value of the num field in addr, giving it a value that is 1 more than its current value.

Reference no: EM133369155

Questions Cloud

How many months will this take : Using a financial calculator/excel calculator. Cooling Tools, Inc. is currently producing 623 of small refrigerators per month but the company's CEO plans
Examine the membership table : Examine the Membership table. Note that membership types include information about how many DVDs a member can rent at a time, and that there is also a limit
Is the project still economically viable why or why not : Is the project still economically viable why or why not? Is there any information that you think is missing? What do you think you need? Why?
Process of creating a content and social media strategy : COMM 1630 University Of Central Missouri serve as a web content manager. For whatever client you choose, you will go through the process of creating a Content
Construct a streetaddress object in which the number is 650 : Construct a StreetAddress object in which the number is 650 and the name is "Commonwealth Avenue" and assign it to a properly declared variable named ccds
What is present value of carlton cars interest tax shield : What is the present value of Carlton Cars' interest tax shield under the proposed capital structure? What is the Carlton Cars' current cost of equity?
Create a document that has the artifacts for a new project : Provider to model and create a document that has the artifacts for a new project that the company is pursuing in order to improve customer satisfaction
What is the percentage change in the price of this bond : A 12-year, 5 percent coupon bond with a face value of $1,000 pays interest semiannually. What is the percentage change in the price of this bond if the market
Write function c2f to convert temperature in degree celsius : Write a function C2F to convert Temperature in degree Celsius to degree Fahrenheit which takes input arguments double CTemp and returns CFahr

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd