Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. In the Boxcar class definition on the next page, fill in top portions of each

ID: 3807240 • Letter: 1

Question

1. In the Boxcar class definition on the next page, fill in top portions of each of the three the method declarations (the underlined areas). Then implement the addCargo method according to the description in (a). Make sure to include the return type, name, and a parameter list between parentheses for each method definition. (a) Name: addCargo Return type: boolean Parameter list: weight (type double) Definition: Adds weight to weight only if weightLimit will not be exceeded. Returns true if the weight is successfully added, and false otherwise. (b) Name: weighCargo Return type: double Parameter list: none Definition: Returns the cargo weight only (after subtracting the base weight of 30). (c) Name: unloadCargo Return type: double Parameter list: none Definition: Resets weight to 30 and returns the weight of the cargo.

Explanation / Answer

Ans 1:

a) public boolean addCargo(double _weight) {

if((_weight+=weight )<=_weightlimit){

_weight+=weight;

return True;

}

else

return false;

}

b) public double weighCargo(){

return _weight-30;

}

c)   

Public double unloadCargo(){

double cargoWeight=this.weighcargo()

_weight=30;

return cargoWeight;

}

d) Car1.addcargo(70);

e) Boxcar car2=new boxcar(150);

f) Car2.addcargo(car1.unloadcargo());

Ans 2.

a)console.print(fun.f(int x,int z,int y));

b) console.print(f.g(int x,f.h(int y,int z)));

c) console.print(f.g(f.h(int z, int z),f.g(int x,int y)));

Ans 3:

a)

public foo(int[] values){

_values-values;

}

b)

int [] a=new inta a[10];

int x=0;

int y =0;

c)

d)2 3 6 6 6 7

e) y or mystery return the length of new array created.it tells how many times this loops has iterated.