I need someone to complete the attached lab assignment for my class please! Thank you!COP 2210
Dr. Debra Davis
In lab today, you will again be employing pair programming.
As a reminder, pair programming has been found to help improve learning of both
partners, as long as both partners are contributing to the process. That means that
you want to work together, without having one person doing all the work or just
spitting out the answers. Figuring things out together, as well as teaching each other
what you know, will help you in the learning process.
For today’s lab, you will choose one person to partner with to complete the lab
assignment. For this assignment, you need to switch roles after completion of one
exercise. For example, if there are 6 exercises, then partner 1 will be the driver for
exercises 1, 3, and 5, and partner 2 will be the driver for exercises 2, 4, and 6.
Step 1: Find someone to partner with. If you cannot find someone (if there is an odd
number of students in class), let the Lab Instructor know and she will help you form
a group of 3 (in which case there will be one driver and two navigators for each
exercise).
Step 2: Decide who will be the driver first and who will be the navigator. Remember
that you will be switching roles for each exercise.
Step 3: At the top of each program or exercise that your write, be sure to include the
comment below and fill in the pertinent information. Each exercise should be saved
in a differed file (you may need to rename some of your classes and files).
// Lab Assignment # XX
// Exercise # XX
// Driver: [Driver’s Name]
// Navigator: [Navigator’s Name]
// Date: [Day of the Week], [date completed]
Step 3: Get started and have fun!
Step 4: Once you are done, be sure to zip your java program files together, along with
your output and your lab assignment sheet. You will need to upload your lab
assignment into Moodle.
Before Starting your lab, your Lab Instructor will briefly review Worked Example 2.1
Question Set 1
1.1. Object-oriented languages like Java are designed to make it easy for programmers to
implement software versions of real-world objects. In learning Java, an important skill to
master is the ability to represent an object in code. Objects that we model are described
using Java classes, so we have chosen to begin this lab by modeling a very simple,
everyday object: a door.
Write the code to create a class that models a door object. Don’t worry about the internal
details just yet. Just give the class a name and an empty body for the moment. We will
add more to the class shortly.
TA CHECK ___________
Done? Now Switch roles with your partner.
1.2. When modeling an object as a class, we also need to describe the properties or attributes an
object possesses. An everyday object that we wish to model in software always has one or more
properties that describe it. For instance a door object might have a name like “Front” or “Side”
to distinguish it from other doors. Another property that could describe a door is its state:
“open” or “closed”. Properties of objects are described in code by using nouns like “state” or
“name” to create instance variables that hold values.
Add instance variables to your Door class body for the name of the door and its state.
Experience has shown that we almost always want to limit the visibility of instance variables to
code inside the same class, so make the access modifiers of state and name private. And
because the state and name properties have values like “open” or “front”, let the instance
variables you create be of type String.
TA CHECK ___________
Done? Now Switch roles with your partner.
1.3. Objects also have operations which can be invoked on the object and which may change the
object in some way. For instance, the operations for a door object could be “open” and “close”.
An operation on an object corresponds to a Java method and is described in code by using a verb
like “open” or “close”. Invoking a method may change the value of an instance variable. For
example, invoking close() would change the value of the state variable from “open” to
“closed”.
Declare methods for open and close. Because we usually want to allow free access to
the methods a class contains, make the access modifier for each method public.
TA CHECK ___________
Done? Now Switch roles with your partner.
2
1.4. Now that we have a Door class, we would like to be able to create some Door objects. Java
constructors are components of a class whose purpose is to create objects of the given class and
to initialize the instance variables of the object. Java provides a default constructor for every
class and the Door class is no exception. Unfortunately, the default constructor that Java
provides initializes the state and name variables to null. This is unacceptable.
Add a constructor for the Door class that passes two parameters: the name of the door
and its initial state. Because we want to use the constructor outside of the class, make the
access modifier for the constructor public.
TA CHECK ___________
Done? Now Switch roles with your partner.
1.5. It is often convenient to have accessor methods that operate on a single instance variable.
Here is an accessor method for the name variable:
public String getName()
{
return name;
}
The word String in front of getName() indicates that the method returns a String when it is
invoked. The body is simple and just returns the value of name.
Add this method to your class and write a similar accessor method for the instance variable
state.
TA CHECK ___________
Done? Now Switch roles with your partner.
1.6. Many instance variables in a class will have corresponding mutator methods that allow you
to change the value of the variable. Here is a mutator method for the name variable:
public void setName(String newName)
{
name = newName;
}
The word void in front of setName() indicates that the method does not return a value when it is
invoked. The body is simple and copies the value of the parameter newName to instance variable
name.
Add this method to the class and write a similar mutator method for the instance variable state.
3
TA CHECK ___________
Done? Now Switch roles with your partner.
1.7. Compile and run the code below:
/**
A class to test the Door class.
*/
public class DoorTester
{
/**
Tests the methods of the Door class
@param args not used
*/
public static void main(String[] args)
{
Door frontDoor = new Door(“Front”, “open”);
System.out.println(“The front door is ” + frontDoor.getState());
System.out.println(“Expected: open”);
Door backDoor = new Door(“Back”, “closed”);
System.out.println(“The back door is ” + backDoor.getState());
System.out.println(“Expected: closed”);
// Use the mutator to change the state variable
backDoor.setState(“open”);
System.out.println(“The back door is ” + backDoor.getState());
System.out.println(“Expected: open”);
// Add code to test the setName mutator here
}
}
Create a third Door object called “sideDoor” the name property “Side” and an initial state of
“closed”. Verify that the object was properly created. Use the mutator to change the state of
object sideDoor to “open”. Verify that the mutator is working.
TA CHECK ___________
Done? Now Switch roles with your partner.
1.8. Consider the variable state in the class Door and the variable newState in the mutator for
state. What kind of variable is state? What kind of variable is newState? When do these
variables exist?
4
TA CHECK ___________
Done? Now Switch roles with your partner.
1.9. Consider the line below which was taken from the main method in 1.7 above.
backDoor.setState(“open”);
What is the implicit parameter that is passed by this method call? What is the explicit
parameter?
TA CHECK ___________
Done? Now Switch roles with your partner.
Difficulty Overview
Partner
1
Switch
2
Switch
1
Switch
2
Switch
1
Switch
2
Switch
1
Switch
2
Switch
1
Switch
Difficulty Exercise
Level
1
1.1
2
1.2
2
2.1
3
2.2
1
2.3
2
3.1
2
3.2
2
3.3
1
4.1
5
2
Switch
1
Switch
2
2
4.2
2
4.3
2
5
6

Purchase answer to see full
attachment




Why Choose Us

  • 100% non-plagiarized Papers
  • 24/7 /365 Service Available
  • Affordable Prices
  • Any Paper, Urgency, and Subject
  • Will complete your papers in 6 hours
  • On-time Delivery
  • Money-back and Privacy guarantees
  • Unlimited Amendments upon request
  • Satisfaction guarantee

How it Works

  • Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
  • Fill in your paper’s requirements in the "PAPER DETAILS" section.
  • Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
  • Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
  • From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.