Solved ICS 141 – 2 Lab 7: Objects Containing Objects in Java

$30.00

Original Work ?

Download Details:

  • Name: Lab6SelectionAndRepetition-3anbbh.zip
  • Type: zip
  • Size: 509.87 KB

Category: Tags: , , , You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (1 vote)

Part 1: Switch Statement
1. Complete the rest of the Calculator code based on class discussion on the Switch statement
and the starter code provided.
Part 2: If, else-if
1. Complete the rest of the Calculator code based on class discussion on the If, else-if
statement and the starter code provided.
Part 4: Creating objects that contains another object
1. Discuss with your group members and come up with a list of Objects that contain other
objects. List 5 objects that fit into this category. Discuss what it knows and can do.
2. Add a package to the SelectionAndRepetition project; name it ‘ObjectsWithinObjects’.
3. Choose one of the objects from your list and come up with an implementation:
1. Base on the discussion; select one of your objects.
i Add a class to the ‘ObjectsWithinObjects’ package for the selected object.
ii Add 3 instance variables to represent what the object knows.
iii Getters and Setters
iv 3 methods for what the object can do.
v Add a toString() to print the details.
2. Implement another class which MUST contain the previous class from #1.
i Add 2 instance variables to represent what the object knows.
1 One of the instance variables MUST be the data type of the class in
the previous step #1.
ii Add two methods for what the object can do based on the contained class
from #1.
3. Add the toString() to print the details.
4. Create a Driver class and test your code.
1. Instantiate 2 objects: One for the class created in step #1 and the second
from the class created in step 2. Call all the methods for both classes.
Part 3: For loops
1. Add another package to the ‘SelectionAndRepetion’ project, name the package ‘forloops’ and
create a class call ‘ForLoops’ inside the package.
2. Create a DriverForLoops class inside the ‘forloops’ package and add each for loop below and
respond to the question inside of your code using comments.
3. Write the following loop inside the main() method of your class
for (int i=1; i<4; i++){
System.out.print(i + “\t”);
}
System.out.println();
System.out.println(“All done”);
What is printed on the screen after running your program? Change
the loop such that numbers 1 to 10 are printed.
4. Add another for loop to your program as follows:
for (int i=1; i<4; i++){
System.out.print(i + “\t”);
}
for (int i=1; i<4; i++){
System.out.print(i + “\t”);
}
System.out.println();
System.out.println(“All done”);
What is printed on the screen when you run your program?
Change the code such that the output of each loop is printed on a
separate line.
5. Change your program so that the two for loops are nested as follows:
for (int i=1; i<4; i++){ for
(int j=1; j<4; j++){
System.out.print(j + “\t”);
}
System.out.println();
}
System.out.println();
System.out.println(“All done”);
What is printed on the screen you run your program?
Change the program such that there are 10 rows in the output and
each row includes the numbers 1 to 8.
Part 5: Uploading your code
1. Although you are working as part of a group, everyone must contribute to the discussion.
Additionally based on these discussions, each person will write and submit their own code
(partial code by the end of class). You are free to make creative changes to your code in
addition to what you discussed with your team members. Show some uniqueness based on
what you’ve learned so far. Export and .zip the project and name it YourNAMELab7 and
upload it to D2L Lab7 drop box.