« first day (2282 days earlier)      last day (2883 days later) » 

00:48
Is anyone on?
01:04
@Qwerp-Derp I'm always on.
Is it possible to have an arraylist consisting of two classes?
@Qwerp-Derp Sure
Why?
Just curious
@Qwerp-Derp You can always give Object to the generic
And waive off type checking in compile time.
 
1 hour later…
02:18
@MadaraUchiha Couldn't you just use ? instead of Object for generics?
 
3 hours later…
05:34
Playing Space Engineers
My computer that's supposed to be quiet is being noisy.
Now streaming_client.exe has crashed. I suppose that means it's time for something completely different.
06:01
hii
user6857832
06:50
@MadaraUchiha I know that but idk how do I calculate the score?
08:15
@Hemlata Can you break down the bowling problem into models?
user6857832
@ItachiUchiha Um, yea.
So, what according to you are the model involved in the game?
user6857832
But I don't need to I think, cuz I jus have to calculate spare and strike.
This will make it easy
user6857832
Um, ok.
user6857832
08:18
Then should I model 'em in spare, strike and fields?
Nope, think about it this way. What things are involved in a game of bowling?
user6857832
Fields? FirstShot? SecondShot?
What are fields?
FirstShot and SecondShot belong to a ... ?
user6857832
Sorry, I meant frames.
user6857832
Frame
08:21
Yes, great!
So frame can be a class containing firstShot and secondShot, right?
user6857832
Yes
anything else that you would put inside a frame?
user6857832
Sum maybe?
user6857832
Of firstShot and secondShot?
user6857832
And spare and strike?
08:24
Yes, exactly.
Spare and Strike are details that should be inside a frame
user6857832
Plus an arrayList.
user6857832
Yea.
Why an arrayList?
user6857832
Um, to store values of frame 1 to frame 10.
But, we are talking about a single frame right now
user6857832
08:25
Um, ok.
@Hemlata score may be a better name?
user6857832
Yeah.
So Frame would look something like this...
user6857832
public class Frames {

private int firstShot;
private int secondShot;
private int score;
private int strike;
private int spare;
}
user6857832
Like this?
08:27
Do strike and spare need to be int fields?
user6857832
Um, no.
user6857832
A string?
user6857832
No, boolean.
user6857832
So we can know if it's a strike or spare, right?
user6857832
public class Frames {

private int firstShot;
private int secondShot;
private int score;
private boolean strike;
private boolean spare;
}
08:28
yes :)
user6857832
:D
Superb, great progress!
Now, what can be the next model?
Hint: Something that will contain the frame.
user6857832
Um, frames?
user6857832
Like all 10 frames?
Nope, what class should contain the List<Frame> frames?
user6857832
08:30
Pins?
How can pin contain frames?
user6857832
Um, idk.
A game of Bowling
user6857832
bowling?
user6857832
Yea
08:31
We can call the class as Bowling
user6857832
Yep
What fields can you think of for this class?
user6857832
List<Frame>?
That one is obvious. What else?
user6857832
PlayerName?
08:34
Lets first create the Bowling considering it can be played by just one person
user6857832
Ok.
We will refactor it later to make it a multiplayer game
user6857832
yea.
user6857832
class Bowling {

private List<Frames> frames = new ArrayList<>();
private String playerName;
}
user6857832
A scanner variable to let the user enter her name?
08:35
What about total score?
user6857832
Yea.
and how will you know which frame is the player in??
user6857832
Like I will make a counter variable and increase it every time it enters a frame, So that way I can keep track of which frame the user is in?
If the user wants to know which frame is he playing, how can he know?
user6857832
How would ya know which frame is the player in?
08:38
who is "ya" here?
user6857832
Um, by HashMap?
user6857832
I mean "you". Lol
user6857832
That's how ya pronounce it.
I am not the one writing the program or using it. You tell me :P
Ya = nonstandard informal spelling of "you"
08:40
@JonahSloan o/
Did you get any sleep?
@ItachiUchiha Yeah
user6857832
Like HashMap<playerName, Frame> map = new HashMap<>()?
Good for you
@Hemlata How will that help?
user6857832
@JonahSloan Yea, but that's how ya pronounce it. Don't ya?
user6857832
@ItachiUchiha Um, idk lol.
user6857832
08:42
It should be somethin' else
@Hemlata Think.. Let you brain neurons do some work for you :)
@Hemlata I pronounce "you" the same as I pronounce the letter 'u'.
user6857832
@JonahSloan Well, maybe different accents.
user6857832
@ItachiUchiha HashMap<playerName, List<Frame>> map = new HashMap<>()?
user6857832
Am I right? lol
08:46
@Hemlata It would have been correct if I had asked you to turn the game into a multiplayer game. But, we are trying to resolve something else, aren't we?
user6857832
@ItachiUchiha Yea.
We just want to keep a check on the frameNo
user6857832
Yea.
Just create a field without a setter.
In this way the user can't set the frameNo, but can access the value.
user6857832
class Bowling {

private List<Frames> frames = new ArrayList<>();
private String playerName;
private int totalScore;
private int frameNo;

public int getFrameNo() {
return frameNo;
}
user6857832
08:48
}
user6857832
@ItachiUchiha But why do we don't want user to see the frameNo?
The user can't see set the value
user6857832
Oh yea lol
frame no is controlled by the game and the user shouldn't be allowed to jump from one frame to another at his own will
user6857832
Yeah.
user6857832
08:52
Now I should add how the user enter the input like her name?
Yes, and that should be a part of?
user6857832
Bowling
Shouldn't there be a function to roll the ball?
@Hemlata No
user6857832
@JonahSloan That's in another class with firstShot and secondShot
user6857832
08:54
@ItachiUchiha Um, why?
user6857832
We have playerName in bowling class.
Have you ever played a game of Bowling?
user6857832
@ItachiUchiha No lol
Ah, ok!
user6857832
Why?
user6857832
08:56
Lol
The name is either entered by someone at the registration counter or you enter it at a machine near the bowling alley.
user6857832
Um, yea.
user6857832
So I should make another class for it?
So, the game itself isn't responsible for entering the name.
user6857832
Yea.
08:57
Yes, just call it a Main(or Game) class with a main()
user6857832
Ok.
user6857832
I named it Main.
user6857832
Or should I name it BowlingGame?
user6857832
Does that sounds good?
Whatever suits you ;)
user6857832
08:59
Um, ok lol.
user6857832
public class BowlingGame {

public static void main(String[] args) {
Bowling bowling = new Bowling();

Scanner input = new Scanner(System.in);
System.out.println("Enter your name here: ");
bowling.playerName = input.nextLine();
System.out.println("Welcome to the Bowling game " + bowling.playerName);

}
}
You should document your code
user6857832
@JonahSloan What does that mean?
user6857832
Um, idk.
> bowling.playerName = input.nextLine();
Instead of this, use a setter
09:04
@Hemlata Add some informative comments telling what each thing is supposed to do.
user6857832
public static void main(String[] args) {
Bowling bowling = new Bowling();
bowling.setPlayerName("Hem");

System.out.println("Welcome to the Bowling game " + bowling.getPlayerName());

}
user6857832
@JonahSloan Um, yea.
@Hemlata Better
user6857832
:D
I should document my own code...
user6857832
09:07
Lol
user6857832
Now what should I do next?
user6857832
@ItachiUchiha
You need to roll the ball. Create a method in bowling called roll(). This will roll the ball and return the no of pins that fell down.
user6857832
Um, ok.
user6857832
Should I add setter and getter in frame class as well?
09:13
for which field?
user6857832
For spare and strike.
user6857832
So then I can add those in roll method.
You tell me..
which fields according to you need setter/getters
user6857832
I think I should.
posted on January 21, 2017 by CommitStrip

user6857832
09:14
Oh, wait firstShot and secondShot lol.
user6857832
Right?
user6857832
Like I need the user to enter the no of pins she knocked down in firstShot, So shouldn't I use setters/getters?
user6857832
So then I can use it in roll method.
user6857832
Or Am I sayin' wrong?
user6857832
09:17
That's what is supposed to go inside roll method, right?
user6857832
:)
@Feeds true story, it went like that when I deployed my first application ever, only much worse...
user6857832
public void roll() {

frame.setFirstShot(4);
frame.setSecondShot(2);
System.out.println("The number of pins knocked down on the firstShot is: "+frame.getFirstShot());
System.out.println("The number of pins knocked down on the secondShot is: "+frame.getSecondShot());

}
user6857832
@ItachiUchiha
09:25
sout should not go inside the roll method
Instead of 4 and 2, use Math.random()
user6857832
sout?
For the first shot use a random number between 0 and 10. For the second shot a random no between 0 and (10 - firstshot)
@Hemlata System.out.println
user6857832
Um, ok.
user6857832
Why between 0 and (10 - firstshot) ?
user6857832
Random rnd = new Random();
int firstRandomNo = rnd.nextInt(11);
user6857832
09:31
frame.setFirstShot(firstRandomNo);
user6857832
But I didn't get for secondShot.
@Hemlata If I drop 4 pins in first round, what is the max no of pins I can drop in second round?
user6857832
Shouldn't be secondshot should also in between 0-10?
user6857832
@ItachiUchiha 6.
@Hemlata I think you have answered your own question?
user6857832
09:33
Oh, it works that way lol.
user6857832
What about sout?
user6857832
public void roll() {

int firstRandomNo = rnd.nextInt(11);
frame.setFirstShot(firstRandomNo);
int secondRandomNo = rnd.nextInt(11 - firstRandomNo);
frame.setSecondShot(secondRandomNo);
System.out.println("The number of pins knocked down on the firstShot is: " + frame.getFirstShot());
System.out.println("The number of pins knocked down on the secondShot is: " + frame.getSecondShot());

}
user6857832
@ItachiUchiha
user6857832
Now I should call roll() ten times, right?
user6857832
public void callRoll() {
for (int i = 1; i <= 10; i++) {
roll();
}
}
09:45
No, its not over yet
If the firstRandom is 10, then its a Strike
user6857832
public void roll() {

int firstRandomNo = rnd.nextInt(11);
frame.setFirstShot(firstRandomNo);
int secondRandomNo = rnd.nextInt(11 - firstRandomNo);
frame.setSecondShot(secondRandomNo);
int firstShotScore = frame.getFirstShot();
int secondShotScore = frame.getSecondShot();
int totalScore = firstShotScore + secondShotScore;
if (firstShotScore == 10) {
frame.strike();
}
if (totalScore == 10) {
frame.spare();
}
// System.out.println("The number of pins knocked down on the firstShot
// is: " + frame.getFirstShot());
user6857832
In frame class:
public void strike() {
strike = true;
}

public void spare() {
spare = true;
}
user6857832
Like this?
Everything is OK except

> int totalScore = firstShotScore + secondShotScore;
If its a spare/strike, you wait for the next frame to calculate the score of current frame
user6857832
Well It'll be a spare only if total score is 10, right?
user6857832
09:49
Yea, but to know if it's a spare shouldn't we do it like int totalScore = firstShotScore + secondShotScore?
Let us consider an example where a user score

`6 /` (6 pins in first and 4 pins in second)

Then in the next round if the user is able to score 4 pins in the first round of the frame then the score for first frame would be 10 + 4 = 14
user6857832
By first round you mean like total score of a frame 2?
user6857832
Or jus firstshot score is 4?
user6857832
@ItachiUchiha Um, yea. I got it.
@Hemlata first shot is 4
user6857832
09:52
Yea.
user6857832
But to know if it's a spare we need to write the code for it, right?
similar for strike we add the total score of frame 2 into frame 1 i.e.

score for frame 1 = 10 + score for frame 2
@ItachiUchiha score for first roll of frame 2
user6857832
So what the totalScore I wrote is not the score, it's jus so we can know it's a spare and wait for the next frame to calculate the score.
@Hemlata firstShotScore != 10 && firstShotScore + secondShotScore == 10
@Unihedron better. Thanks :)
user6857832
09:57
@Unihedron What's that?
A better way to put first round
round is actually causing confusion. So we can say that we have 2 rolls in a frame
@ItachiUchiha well done for realizing
10 points to house griffindor
user6857832
yeah.
In a strike, the bonus is the next two rolls, and in a spare, the bonus is the one next roll.
user6857832
Yeah.
10:01
@Hemlata You should already know this, a rules page was posted here before while you had read it, I'm just restating it for @ItachiUchiha.
user6857832
@Unihedron Lol I know that.
user6857832
@ItachiUchiha
user6857832
If a guy smoke then it's a turn off for me lol
user6857832
10:06
So I won't gonna watch it haha
@Hemlata Its just a placeholder image. Listen to the song.
user6857832
@ItachiUchiha Um, ok.
@Hemlata If a variable is not shared across multiple methods, its always better to move it inside the method. Looks at Random rnd = new Random();
user6857832
Um, ok.
user6857832
What about sout?
user6857832
10:09
@ItachiUchiha Lol it says "This video is not available" Lol
@Hemlata May be its not for kids :P
user6857832
Lol
user6857832
I'm not a kid haha
@ItachiUchiha true
user6857832
10:13
Ah I can't post it lol
user6857832
Yea, it's so cool song lol.
user6857832
I have watched the first movie of it and now I'll watch this as well when it will be out lol.
user6857832
It'll release on Valentine's day.
user6857832
Anyway let's get back to coding haha
user6857832
10:19
// System.out.println("The number of pins knocked down on the firstShot is: " + frame.getFirstShot());
// System.out.println("The number of pins knocked down on the secondShot is: " + frame.getSecondShot());
user6857832
Should I remove this line from my code?
user6857832
@ItachiUchiha
user6857832
Um, ok.
user6857832
How was the song? Did ya listen it?
10:28
@Hemlata I have heard it in the past
Right now listening to something else
user6857832
Cool lol
user6857832
Yeah
else if (firstShotScore + secondShotScore == 10)
Random rnd = new Random(); should move inside roll()
user6857832
Yeah, did.
There is a logical problem with the code
user6857832
What's that?
We are calling roll and in a single roll, we are calculating everything that we need for a frame.
user6857832
Yeah
There is a level of segregation missing.
user6857832
10:33
But we need to calculate it like 10 times
Each frame should have 2 rolls
user6857832
Yeah
user6857832
But roll() should be call like 10 times.
user6857832
Right?
nope, the no of times roll needs to be called depends on the output of the current roll
For example, in the first roll of frame1, if its a strike, we do not need to call second roll for frame1
user6857832
10:35
Well but whatever be the output of it, It'll still be call like 10 times.
user6857832
Oh yea.
The no of frames is fixed but not the no of rolls in each frame
user6857832
Yep
cat
8 upvotes to go
user6857832
10:40
public void roll() {
Random rnd = new Random();
int firstRandomNo = rnd.nextInt(11);
frame.setFirstShot(firstRandomNo);
if (firstRandomNo == 10) {
frame.strike();
} else {
frame.setSecondShot(secondRandomNo);
int secondShotScore = frame.getSecondShot();
if (firstShotScore + secondShotScore == 10) {
frame.spare();
}
}

}
user6857832
Like this?
@Hemlata :S
@ItachiUchiha silver badge
Rename firstShot and secondShot to firstRoll and secondRoll respectively
10:43
@ColdFire which one?
and 9 upvotes to go for 200 upvotes on an answer
@Unihedron android
Rename roll() to frame()
user6857832
Um, ok.
you know what I want
java badge
nvm I have it
hmm i only want android one
user6857832
10:46
@ItachiUchiha Wasn't it right way of doing it?
@ItachiUchiha nice
@Hemlata It is. We just missed some useful information on the way
i dont even have 200 answer in android tag to qualify for gold currently
user6857832
@ItachiUchiha What's that?
10:47
@ItachiUchiha you have one on javafx, which is even more rare :)
@Unihedron :)
@Hemlata The segregation part. Bowling -> Contains 10 frames -> Each frame can have a min of 1 roll.
we're both overqualified in answers posted but not enough score lol
user6857832
@ItachiUchiha Yea
10:50
@Hemlata This line should throw a compilation error. Don't you use an IDE?
user6857832
I changed in the my code but not here lol
update it then
user6857832
Did.
idk if you're still taking code quality reviews, but hem isn't a conventional package name, usually you want to use your identifier
like if you own a domain lolcats.com then your package would be com.lolcats.~projectname~
if you don't, you can use account information like com.github.hemhershey.bowling or com.gmail.~yourgmail~.bowling
user6857832
Yeah.
10:55
Currently, the frames list is empty. You can either create 10 instances of Frame and put them inside frames list when Bowling class is instantiated OR you can populate the list each time frame() is executed and the ball is rolled for them.
also, here if (firstRollScore == 10) { you're using a magic constant, you should move it out so you don't accidentally change it while coding also it makes it easier to read
private static final int STRIKE_VALUE = 10;
// before Frames frame = new Frames();

// ...
if (firstRollScore == STRIKE_VALUE) {
This just gets better with time - youtube.com/watch?v=_NNOaYNqLo8
@Unihedron int
@ItachiUchiha ayy elmao
@Unihedron ayy lmao? :P
user6857832
Yeah
user6857832
10:59
@Unihedron Yea, I'll change it.
also another side advice is to use the yoda expression STRIKE_VALUE == firstRollScore instead but that doesn't really matter right now

« first day (2282 days earlier)      last day (2883 days later) »