This year september i started at my education program and i want to become a software engineer, the first programming language i need to learn is java.
Well it is going quite OK i think, after two months we learned the basics, how to start programming, if and else , booleans, arrays, int, doubles, etcc... quite the basic stuff i think..
I got the feeling i dont get programming for some reason, i see people on the internet do magical things in java ,, i really like programming i think its one of the best school subjects i have atm.
But still, i feel kinda dumb in java learning to code..
Oke that was the background of my question :P
Soooo i have been programming alot lately especially this week since i have my first exam tommorow!,,
I am programming this program for exercise and to prep me for the exam, but i have a isseu with it, i am kinda stuck atm..
So the assignment says the fallowing, I need to make a program for sport game scores.. the best of 7.
So there are 2 teams, and the user can input the names of the teams, and what they scored all games.
The first team that wins 4 games wins the best of 7 tournement.
The assignment tells me i need to use arrays for the scores and loops to check what team wins each game, annd output it for the user (output is the simple part)
Also if one team wins 4 games before al 7 games are played the program must stop cause that team wins the tournement.
The thing i want to know, is how do i use the arrays to check the scores and tell howmuch games there are played using a loop?
I really dont know where to start.
Any comments or feedback on the code is very very welcome! :)
My first comment is when you find yourself repeating the same basic chunk of code each time then it either ought to be a loop or a method. I'm guessing methods are beyond your knowledge at the moment so in your code where you get the team's scores 7 times you should have a loop which repeats for the length of the scores array (ie 7 times). Inside this loop you ask for each teams score and do a check to see if either team has won 4 games.
The first option may seem acceptable for a few names but it would soon get tiresome if there were 20 names. Now what if you'd used option 1 for 5 names and then your boss turned around and said it now needs to be 10 names. With option 1 you have a lot of coding to do but with option 2 all you have to do is change the size of the array. Or what if your boss says he doesn't like the prompt so change it to "Please enter a name", with option 1 you have to change it for every block of code whereas in option 2 you just change it in one place.
No. You only need one loop and you ask for both teams scores in that loop, as I've previously stated. If you did it with two loops you can't fulfil the requirement of the assignment to end the game as soon as one team has won 4 games
My suggestion would be to step away from the computer, and write down how you are going to do this in pseudo code.
Your explanation in the last post was effectively
- Enter Team1 name
- Enter Team 2 name
- Enter Team1 scores for all games - loop 7 times entering in a score for each game
- Enter Team 2 scores for all games - loop 7 times entering in a score for each game
The problem is that doing it this way, means that you won't be able to meet the requirement of "stop once one team wins 4 games"
Can you think of a better way to do it?
Is a for loop the most appropriate way? Are there any other loop styles that will work also? There isn't any "correct" answer here, but you should at least consider which style of loop to use.