Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introducing Access Control In this lab you will start using Introducing Access Control in the Address class. Deliverable A zipped NetBeans project with 2 classes

Introducing Access Control

In this lab you will start using Introducing Access Control in the Address class.

Deliverable

A zipped NetBeans project with 2 classes

  • app
  • ZipCode
  • Address

Classes

image text in transcribed

Suggestion:

  • Use Netbeans to copy your last lab (Lab 04) to a new project called Lab05.
  • Close Lab04.
  • Work on the new Lab05 project then.

The Address Class

  • Uses encapsulation
  1. Attributes
    • private int number
    • private String name
    • private String type
    • private ZipCode zip
    • private String state
  1. Constructors
    • one constructor with no input parameters
      • since it doesn't receive any input values, you need to use the default values below:
        • number - 0
        • name - "N/A"
        • type - "Unknown"
        • zip - use the default constructor of ZipCode
        • state - " " (two spaces)
    • one constructor with all (five) parameters
      • one input parameter for each attribute
  2. Methods
    • public String toString()
      • returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as one String.
      • toString() is a special method, you will learn more about it in the next lessons
        • it needs to be public
        • it needs to have @override notation (on the line above the method itself). Netbeans will suggest you do it.
    • Get and Set methods
      • public int getNumber()
      • public void setNumber(int number)
      • public String getName()
      • public void setName(String name)
        • this method will receive an input parameter name and will correct if necessary to make its first letter upper case and the remaining part of the word lower case (correcting MAIN to Main, for instance)
        • it will work for at least 2 words (correcting north atherton to North Atherton, for instance)
        • the attribute name will be updated with the corrected value
      • public String getType()
        • this method will return a corrected value depending on the value of the attribute type.
        • it will return "Dr." if the attribute type is "Drive"
        • it will return "Ave." if the attribute type is "Avenue"
        • it will return "St." if the attribute type is "Street"
        • it will return the value of the attribute type for any other cases
      • public void setType(String type)
      • public ZipCode getZip()
      • public void setZip(ZipCode zip)
      • public String getState()
      • public void setState(String state)

The ZipCode Class (updated to include encapsulation)

  • Uses encapsulation
  1. Attributes
    • private String fiveDigit
    • private String plus4
  2. Constructors
    • one constructor with no input parameters
      • since it doesn't receive any input values, you need to use the default values below:
        • private fiveDigit - "00000"
        • private plus4 - "0000"
    • one constructor with one parameter
      • one input parameter for fiveDigit
      • use the default value from the no-parameter constructor to initialize plus4
    • one constructor with all (two) parameters
      • one input parameter for each attribute
  3. Methods (updated to include Get and Set methods)
    • public String toString()
      • returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as one String.
      • toString() is a special method, you will learn more about it in the next lessons
        • it needs to be public
        • it needs to have @override notation (on the line above the method itself). Netbeans will suggest you do it.
      • the toString method will have a similar functionality as App had in the first lab.
        • it returns all the data from each object as a String
          • if the second attribute, plus4, is blank, display only the first attribute fivedigit, for instance, 16801
          • if the second attribute, plus4, is not blank, display only the first attribute fivedigit followed by a "-" and then the plus4 attribute, for instance, 16802-1503
    • Get and Set methods for each of the two attributes
    • display()
      • this method gets the "toString()" value (whatever is returned by toString() ) and uses "System.out.println" to display it.
      • you need to decide what is the type of this method
    • display(int p)
      • this method receives an input parameter, an int number p
      • based on p's value
        • if p's value is 1
          • uses "System.out.println" to display the zipcode's prefix, i.e., its 3 first digits.
          • if the fiveDigit is "10022", displays "100"
        • if p's value is2
          • uses "System.out.println" to display the zipcode's area, i.e., its fourth and fifth digits.
          • if the fiveDigit is "10022", displays "22"
        • for any other value of p, it should not display anything

The App class

  1. create an Address object called ad1 using the no-parameter constructor
  2. create an Address object called ad2 using the all-parameter constructor with the value
    • number 100
    • name RODEO (note the all Upper Case "RODEO" to test the setName method)
    • type Drive
    • zip 90210
    • state CA
  3. create an Address object called ad3 using the all-parameter constructor with the values
    • number 210
    • name west college (note the lower case "w" and "c" to test the setName method)
    • type Avenue
    • zip 16801-2141
    • state PA
  4. display all the data from each object using System.out.println and the method toString()

Output

The output should be similar to

Address{number=0, name=N/A, type=Unknown, zip=00000, state= } Address{number=100, name=Rodeo, type=Dr., zip=90210, state=CA} Address{number=210, name=West College, type=Ave., zip=16801-2141, state=PA}
App ZipCode Address - Creates an Address object ad1 using the no-parameter constructor. - Creates an Address object ad2 using the all-parameter constructor. - Creates an Address object ad3 using the all-parameter constructor. Using the method toString(), display the data from each of the 3 objects Attributes private String five Digit; private String plus4; Attributes private int number; private String name; private String type; private Zip Code zip; private String state; Constructors No-parameter One-parameter Two-parameter Constructors No-parameter All-parameter Methods String toString() Get/Set methods void display(). void display(int p) Methods String toString() Get/Set methods

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

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago