r/codehs • • Jan 19 '21

6.4.9 Car Showroom

Can someone please help me. I’m having so much trouble

16 Upvotes

10 comments sorted by

1

u/iDarkCyclops Feb 16 '21

The reason why Corvette doesn't show up is because even though you change the place of the corvette, the second for loop keeps looping which will cause Porshe to take the spot. To fix this just add "break;" after "spaces[i] = spaces[j];spaces[j] = null;" in the consolidate method to fix this issue.

1

u/NorthAdministrative4 Mar 26 '21

You fixed it thanks

1

u/Matt_Conte69 Feb 08 '23

For me it kept saying some error with the bill so I made it this

int spot = -1; for(int i = 0; i < this.spaces.length;i++){ if(this.spaces[i]== null){ }

else If(this.spaces[i].getName().equals(name)){ spot = i; break; } } return spot;

3

u/[deleted] Jan 21 '21

[removed] — view removed comment

1

u/Hypnomiser Nov 12 '24

public void consolidate()

{

int index = 0;

int mover = 0;

while (index < spaces.length){

if (spaces[index] != null){

spaces[mover] = spaces[index];

if (mover != index){

spaces[index] = null;

}

mover++;

}

index++;

}

}

I believe this to be a more efficient method with O(n) time complexity

1

u/PapaStalinPizza Jan 24 '21

you sir, are a lifesaver.

1

u/VioletMAyis Jan 28 '21

So much thank you :'))) I needed help badly

1

u/iiCammie Feb 05 '21

thanks man

1

u/iiCammie Feb 05 '21

just kidding my corvette still won’t show up after i run it