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

  What is the longest you might need to watch in order to draw

Will you be able to conclude at some point that the TM is in an infinite loop? If so, what is the longest you might need to watch in order to draw conclusion?

  Find at least two instances of the n-queens problem

Find at least two instances of the n-Queens problem that have no solutions.

  How using the sequence structure only

As you know, three fundamental control structure are sequence, selection and repetition. Can you write down C program using the sequence structure only.

  What is the difference between data analytics vs data mining

There is much discussion regarding Data Analytics and Data Mining. Sometimes these terms are used synonymously but there is a difference.

  Develop a web-based student registration system

Imagine you are a software engineer working on a fixed budget and you are tasked to develop a Web-based student registration system. This Web-based system.

  Compute and out put turnaround time and wating time

The program should compute and out put turnaround time and wating time of every job as well as the average waiting time and average turnaround time.

  Describing why the team performed so well or so poorly

Discuss the team dynamics for a highly effective or ineffective team of which you were a member. Can you explain why the team performed so well or so poorly?

  Write pl/sql anonymous block that will process records

Write PL/SQL anonymous block that will process records stored in the "emp" table (table that is created as part of the starter database which was created during

  What goes into a disaster recovery plan

Create a five-seven- PowerPoint Presentation on what goes into a disaster recovery plan. Include all the units as outlined in the textbook.

  Write a function to create a movie where one item is moving

Write a function to create a movie where one item is moving from the top to the bottom and another item is moving from the bottom to the top.

  Assignment cores on computer systemssingle-processor

assignment cores on computer systemssingle-processor computers were able to handle and process smaller sets of data.

  Describe a recovery that would not be feasible to test

Elaborate on the steps and processes you would have to do to try to insure that your recovery plan would work in the event of a disaster

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