Question: Arrays For the questions below: Assume this Box class: public class Box { double length; double width; double height; Box(double l, double w, double h)
Arrays
For the questions below: Assume this Box class:
public class Box
{
double length;
double width;
double height;
Box(double l, double w, double h)
{
length = l;
width = w;
height = h;
}
double volume( )
{
return length * width * height;
}
}
Write the statement to instantiate an Box obindexect, blueBox, with a length of 6, width of 4, and height of 2.
Write a statement to output the volume of the blue box.
Override constructor to class Box for a cube, which only accept 1 parameter, side.
Write a statement to instantiate a cube with a length of 3, width of 3, and height of 3.
Add a method FindArea to find area of box, which accept length and width.
What output is produced by the following code fragment?
ArrayList
names.add(Betty);
names.add(1, Chet);
names.add(1, Don);
For the questions below, assume values is an obindexect of ArrayList
9, 4, 12, 2, 6, 8, 18
What is returned by values.get[3]?
What is the value of values.size()?
9. What output should be generated after adding two statements:
values.add(2,20);
values.remove(4);
How you can find the max number from values list? Give the main code.
Array
To initialize a String array names to store the three Strings "Huey", "Duey" and "Louie", you would do
A) String names = {"Huey", "Duey", "Louie"};
B) String[ ] names = {"Huey", "Duey", "Louie"};
C) String[ ] names = new String{"Huey", "Duey", "Louie"};
D) String names[3] = {"Huey", "Duey", "Louie"};
E) String names; names[0] = "Huey"; names[1] = "Duey"; names[2] = "Louie";
Describe what problem occurs in the following code. What modifications
should be made to it to eliminate the problem?
int[] numbers = {3, 2, 3, 6, 9, 10, 12, 32, 3, 12, 6};
for (int count = 1; count <= numbers.length; count++)
System.out.println(numbers[count]);
Write an array declaration and any necessary supporting classes to represent Students names for a class of 25 students
14.Write code that prints the values stored in an array called names backwards.
For the questions below, assume values is an int array that is currently filled to capacity, with the following values:
9, 4, 12, 2, 6, 8, 18
15. Which of the following loops would adequately add 1 to each element stored in values?
A) for (index=1; index B) for (index=0; index C) for (index=0; index<=values.length; index++) values[index]++; D) for (index=0; index E) for (index=1; index
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
