Question: Chapter 8: 2 Dimensional Arrays 1. Hand-write code to declare a two dimensional array of 3 columns and 4 rows. The Array will hold doubles.

Chapter 8: 2 Dimensional Arrays

1. Hand-write code to declare a two dimensional array of 3 columns and 4 rows. The Array will hold doubles. What is the array initialized to by default?

2. Define the following arrays using an initializer list:

a.

1 2 3

2 3 4

5 6 7

b.

1 2

4 5 6

3. Write code to print the arrays below

4. Given the two dimensional array below:

public class Class1 {

public static void main (String [] args) {

int[][] list = { {9, 8}, {6, 5}, {3, 2}, {7, 7} };

a. What is the value of list.length _______________

b. What is the value of list[0].length _______________

You will be asked to write and/or interpret these common array algorithms

1) Finding the highest value in a 2 dim array

2) Finding the lowest value in a 2 dim array

3) Adding the elements of a 2 dim array

4) Adding the elements of a column of a 2 dim array

5) Adding the elements of a row of a 2 dim array

They are all found in the class notes and labs completed in class.

How does the loop change the array?

int [][] matrix = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };

for (int row=0; row < matrix.length; row++) {

for (int col = 0; col< matrix[0].length; col++) {

if (row == col) matrix[row][col] = matrix[row][col] * 10;

}

}

Chapter 9: Defining Classes and Objects:

1) Constructors: Same name as the class, no return type, run when the object is created

2) Constructors may be overloaded

3) Accessors: return the value of the instance variables

4) Mutators; Change the value of the instance variables

5) Instance variables (or data fields): belong to the object. Private to enforce encapsulation. Can be used in every method of the class

6) Encapsulation: Variables private, getters and setters

7) Static variables: Shared by all objects of the class. One copy

8) Array of Objects: Employee [] theEmployees = new Employee [10];

9) Scope of variables: Where it can be used: block in which it was defined. Local and parameter variables=> method, instance variable=> entire class

10)this the current object needed if the name of parameter variable is the same as the instance variable

UML Diagrams:

Course

-courseName: String

-students: Student []

-numberOfStudents: int

+Course(courseName : String)

+getCourseName() : String

+addStudent (student : Student) : void

+addStudent (studentName: String): void

+dropStudent(studentId: int ) : void

+getStudents() : Student []

+getNumberOfStudents() : int

a. How many constructors does Course have?

b. How many methods that are void?

c. How many methods that return a value?

d. What is the parameter to the method dropStudent?

Write the Widget class.

a. A widget has a name and price.

b. The default for name should be widget

c. Write a constructor (not the no-args), all getters and setters.

d. Add a toString method.

e. Create an object of type Widget.

Consider the Person class below:

public class Person {

private String name;

private int age; public

Person ()

{

}

public void setAge(int age)

{

this.age = age;

}

public void setName(String name)

{

name = name;

}

public int getAge()

{

return age;

}

public String getName()

{

return name;

}

}

Create an object of type Person with name, John, and age 25.

Create a one dimensional Array of Person objects, people, which can hold 100 Person objects:

Write the sumAge method. It calculates the total age of all the Person objects in the people array.

public static int sumAge(Person [] people) {

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!