Yeah so theres a strike on at school and i didnt have a drive there the last few classes and weve gotta do this thing as like a work pack, think anyone can do it for me?>
itd be greatly appreciated
its jave, we use blueJ if that means anything.
itd be greatly appreciated
its jave, we use blueJ if that means anything.
CP 12
WORKSHEET #7
Name: ______________________________________________
1. Write a declaration for an array variable people that could be used to refer to an array of person objects.
2. Write a declaration for an array variable vacant that could be used to refer to an array of boolean values.
3. Correct the following array declarations: [ ] int counts; boolean[5000] occupied;
4. Given the following variable declarations: double[ ] readings;
String[ ] urls;
TicketMachine[ ] machines;
a. Write the assignment statement that makes the readings variable refer to an array able to hold 60 double values.
b. Write the assignment statement that makes the urls variable refer to an array able to hold 90 String objects.
c. Write the assignment statement that makes the machines variable refer to an array able to hold 5 TicketMachine objects.
5. How many String objects are created by the following declaration?
String [ ] labels = new String [20];
6. Correct the following array declaration: double[ ] prices = new double(50);
7. Correct the errors in the following:
/**
* Print all the values in the marks array that are greater than the mean.
* parameter - marks: an array of mark values
*parameter - mean: the mean (average) mark.
*/
public void printGreater(double marks, double mean)
{
for(index = 0; index <= marks.length; index++) {
if (marks[index] > mean) {
System.out.println(marks[index]);
}
}
}
8. Rewrite the following method so it uses a for loop instead of a while:
public void listNotes()
{
int index = 0;
while (index < notes.size()) {
System.out.println(notes.get(index));
index++;
}
}
WORKSHEET #7
Name: ______________________________________________
1. Write a declaration for an array variable people that could be used to refer to an array of person objects.
2. Write a declaration for an array variable vacant that could be used to refer to an array of boolean values.
3. Correct the following array declarations: [ ] int counts; boolean[5000] occupied;
4. Given the following variable declarations: double[ ] readings;
String[ ] urls;
TicketMachine[ ] machines;
a. Write the assignment statement that makes the readings variable refer to an array able to hold 60 double values.
b. Write the assignment statement that makes the urls variable refer to an array able to hold 90 String objects.
c. Write the assignment statement that makes the machines variable refer to an array able to hold 5 TicketMachine objects.
5. How many String objects are created by the following declaration?
String [ ] labels = new String [20];
6. Correct the following array declaration: double[ ] prices = new double(50);
7. Correct the errors in the following:
/**
* Print all the values in the marks array that are greater than the mean.
* parameter - marks: an array of mark values
*parameter - mean: the mean (average) mark.
*/
public void printGreater(double marks, double mean)
{
for(index = 0; index <= marks.length; index++) {
if (marks[index] > mean) {
System.out.println(marks[index]);
}
}
}
8. Rewrite the following method so it uses a for loop instead of a while:
public void listNotes()
{
int index = 0;
while (index < notes.size()) {
System.out.println(notes.get(index));
index++;
}
}





Comment