Do I need to create new classes?
I hope this is ok to ask and all makes sense.
I have learnt the basics of building an app in Java and it all works great. (The app is a darts score keeper game for 501. ie the you input 2 player names and then input their scores after each turn and the app calculates the current score remaining and offers suggestions for finishes as you have to finish on a double in this game) All the code is currently in one java file and I have been advised to put it into classes such as a player class and a score class....
My problem is I don't really have a clue where to start with this. I am half way through a computer science degree and what we learnt in java for classes I can't seem to think how it would work for this scenario. We learnt the basics of you create a class and then all new instances of that class will have the same characteristics in this case with the open university it was a Frog class and so when you used Frog kermit = new Frog(); it would create a new instance of a Frog and this would then know a list of commands as listed in the class java file.
Obviously this isn't really relevant for the app I have. I'm not 'creating a new player' as there are always 2 players and the players are always in the app as player1 and player2. I only use the players actual name when someone wins and a toast pops up to say winner is "Danny".
I would love a tutorial on how best to make classes in this scenario. I have also done the google and udemy android studio courses and none of these even mention classes! Is it even necessary to make classes for all the different objects?
Many thanks and sorry it's a little long winded for such a simple question :)
java
add a comment |
I hope this is ok to ask and all makes sense.
I have learnt the basics of building an app in Java and it all works great. (The app is a darts score keeper game for 501. ie the you input 2 player names and then input their scores after each turn and the app calculates the current score remaining and offers suggestions for finishes as you have to finish on a double in this game) All the code is currently in one java file and I have been advised to put it into classes such as a player class and a score class....
My problem is I don't really have a clue where to start with this. I am half way through a computer science degree and what we learnt in java for classes I can't seem to think how it would work for this scenario. We learnt the basics of you create a class and then all new instances of that class will have the same characteristics in this case with the open university it was a Frog class and so when you used Frog kermit = new Frog(); it would create a new instance of a Frog and this would then know a list of commands as listed in the class java file.
Obviously this isn't really relevant for the app I have. I'm not 'creating a new player' as there are always 2 players and the players are always in the app as player1 and player2. I only use the players actual name when someone wins and a toast pops up to say winner is "Danny".
I would love a tutorial on how best to make classes in this scenario. I have also done the google and udemy android studio courses and none of these even mention classes! Is it even necessary to make classes for all the different objects?
Many thanks and sorry it's a little long winded for such a simple question :)
java
The first step is to identify actors, or abstractions. Just by reading the description of your app, I see that it has two players, where each player has a name, and a score. That is already a good candidate for a class Player, with a field name and a field score, and two instances of that class. Then it seems you have something like a Game. A Game involves two players, and needs to keep track of who is the next or current player.
– JB Nizet
Nov 24 '18 at 22:45
add a comment |
I hope this is ok to ask and all makes sense.
I have learnt the basics of building an app in Java and it all works great. (The app is a darts score keeper game for 501. ie the you input 2 player names and then input their scores after each turn and the app calculates the current score remaining and offers suggestions for finishes as you have to finish on a double in this game) All the code is currently in one java file and I have been advised to put it into classes such as a player class and a score class....
My problem is I don't really have a clue where to start with this. I am half way through a computer science degree and what we learnt in java for classes I can't seem to think how it would work for this scenario. We learnt the basics of you create a class and then all new instances of that class will have the same characteristics in this case with the open university it was a Frog class and so when you used Frog kermit = new Frog(); it would create a new instance of a Frog and this would then know a list of commands as listed in the class java file.
Obviously this isn't really relevant for the app I have. I'm not 'creating a new player' as there are always 2 players and the players are always in the app as player1 and player2. I only use the players actual name when someone wins and a toast pops up to say winner is "Danny".
I would love a tutorial on how best to make classes in this scenario. I have also done the google and udemy android studio courses and none of these even mention classes! Is it even necessary to make classes for all the different objects?
Many thanks and sorry it's a little long winded for such a simple question :)
java
I hope this is ok to ask and all makes sense.
I have learnt the basics of building an app in Java and it all works great. (The app is a darts score keeper game for 501. ie the you input 2 player names and then input their scores after each turn and the app calculates the current score remaining and offers suggestions for finishes as you have to finish on a double in this game) All the code is currently in one java file and I have been advised to put it into classes such as a player class and a score class....
My problem is I don't really have a clue where to start with this. I am half way through a computer science degree and what we learnt in java for classes I can't seem to think how it would work for this scenario. We learnt the basics of you create a class and then all new instances of that class will have the same characteristics in this case with the open university it was a Frog class and so when you used Frog kermit = new Frog(); it would create a new instance of a Frog and this would then know a list of commands as listed in the class java file.
Obviously this isn't really relevant for the app I have. I'm not 'creating a new player' as there are always 2 players and the players are always in the app as player1 and player2. I only use the players actual name when someone wins and a toast pops up to say winner is "Danny".
I would love a tutorial on how best to make classes in this scenario. I have also done the google and udemy android studio courses and none of these even mention classes! Is it even necessary to make classes for all the different objects?
Many thanks and sorry it's a little long winded for such a simple question :)
java
java
asked Nov 24 '18 at 22:37
Danny JebbDanny Jebb
135
135
The first step is to identify actors, or abstractions. Just by reading the description of your app, I see that it has two players, where each player has a name, and a score. That is already a good candidate for a class Player, with a field name and a field score, and two instances of that class. Then it seems you have something like a Game. A Game involves two players, and needs to keep track of who is the next or current player.
– JB Nizet
Nov 24 '18 at 22:45
add a comment |
The first step is to identify actors, or abstractions. Just by reading the description of your app, I see that it has two players, where each player has a name, and a score. That is already a good candidate for a class Player, with a field name and a field score, and two instances of that class. Then it seems you have something like a Game. A Game involves two players, and needs to keep track of who is the next or current player.
– JB Nizet
Nov 24 '18 at 22:45
The first step is to identify actors, or abstractions. Just by reading the description of your app, I see that it has two players, where each player has a name, and a score. That is already a good candidate for a class Player, with a field name and a field score, and two instances of that class. Then it seems you have something like a Game. A Game involves two players, and needs to keep track of who is the next or current player.
– JB Nizet
Nov 24 '18 at 22:45
The first step is to identify actors, or abstractions. Just by reading the description of your app, I see that it has two players, where each player has a name, and a score. That is already a good candidate for a class Player, with a field name and a field score, and two instances of that class. Then it seems you have something like a Game. A Game involves two players, and needs to keep track of who is the next or current player.
– JB Nizet
Nov 24 '18 at 22:45
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462959%2fdo-i-need-to-create-new-classes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462959%2fdo-i-need-to-create-new-classes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The first step is to identify actors, or abstractions. Just by reading the description of your app, I see that it has two players, where each player has a name, and a score. That is already a good candidate for a class Player, with a field name and a field score, and two instances of that class. Then it seems you have something like a Game. A Game involves two players, and needs to keep track of who is the next or current player.
– JB Nizet
Nov 24 '18 at 22:45