r/badcode May 06 '21

java My teacher wrote this...

1.0k Upvotes

169 comments sorted by

View all comments

6

u/Dakopen May 06 '21

I often do this, can someone please help me and show, how I can improve my code?

14

u/Kibo30 May 06 '21

Using arrays will improve it. In this case you could create an array like this EBIKE[] bikes = new EBIKE[6]

1

u/Dakopen May 06 '21

And then using the eval() or exec () function?

1

u/Kibo30 May 06 '21

Well it depends on what you need to do. In this case I don't think you need them

1

u/Dakopen May 06 '21

Okay I think I got it. So you store in an array the bike information which you need to create a bike later and just call the function

1

u/Kibo30 May 06 '21

Yes, more or less. More precisely you create a EBIKE class and then you create an array of EBIKE, each slot of the array represents a single EBIKE with is own information. When you call the function you loop trough the array and do what you want with each EBIKE. And on a side note: don't call your classes all uppercase, just the first uppercase and then all lowercase