Upload
job-mccarthy
View
216
Download
0
Embed Size (px)
Citation preview
SE1011Week 8, Class 3 Today
Designing Code
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 1
Muddiest Pointhaving multiple classes and the exact use of each one. Plus that, how can I figure which classes to create?
designing and using classes
How to debug a program that requires user input. debuggingP.S. I didn't mean for my jokes to undermine your feedback tool <3Should we use main() only as a "starter" to the "object" of the main program? static and mainMore on what can or can't be passed to a method parametersWhy did we have to use a method for main? static and mainwhy we couldnt use main for the actual game static and main
2Discussed at start. Discussed during this class. [Instructor answer to the question]
Muddiest PointHow do you know when to do this before you've completed writing the duplicate code?
designing classes
should we be doing more work in other classes vs in the driver. static and main
why make another class, when you can keep the variables in the main class?
static and main; designing classes
Nothing today I think I have a good understanding of everything right now.Still not clear what "static" *means* and what the alternative is. staticshould we not use main from now on? static and main
3Discussed at start. Discussed during this class. [Instructor answer to the question]
Old Muddy PointsDoes || work the same way as && as a short circuit operator? So if(true || <something that can't be evaluated>) will it go on or will it crash? short-circuit ||
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 4
Discussed at start. Discussed during this class. [Instructor answer to the question]
What is a static method?
a method which can be called without an instance of the class, for example:
line = JOptionPane.showInputDialog("...");
unlike normal methods:Scanner in = new Scanner(System.in);
line = in.nextLine(); a method without a this reference
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 5
Version 1.0 (Start of last class)class8_2_Elevens_start
6
main(…)
Die ref
playerDie1
85638
85638
Die
numSides
int
in main(…)
playerRoll1 = playerDie1.roll();playerTotal = playerRoll1 + playerRoll2;//HERE
6
int
playerRoll1
2
int
playerRoll2
7
int
playerTotal
9
Version 1.1 (Middle of class)
7
main(…)
Die ref
playerDie1
85638
reRollOneDie
Die ref
playerDie
85638int
playerRoll1
2
int
playerRoll2
7
int
playerTotal
9
85700
Lab7
in reRollOneDie(…)
int playerRoll = playerDie.roll();if(numDie == 1) { playerRoll1 = playerRoll;} else { playerRoll2 = playerRoll;}playerTotal = playerRoll1 + playerRoll2;// HERE
85638
Die
numSides
int
6
int
numDie
1
Lab7 ref
this
85700
int
playerRoll
2
in main(…)
reRollOneDie(playerDie1, 1);
Version 1.2 (End of class)class8_2_Elevens
8
main(…)
Die ref
playerDie1
85638
in theGame(…)
reRollOneDie(playerDie1, 1);
reRollOneDie
Die ref
playerDie
85638int
playerRoll1
2
int
playerRoll2
7
int
playerTotal
9
85700
Lab7
in reRollOneDie(…)
int playerRoll = playerDie.roll();if(numDie == 1) { playerRoll1 = playerRoll;} else { playerRoll2 = playerRoll;}playerTotal = playerRoll1 + playerRoll2;// HERE
85638
Die
numSides
int
6
int
numDie
1
Lab7 ref
this
85700
int
playerRoll
2
Lab7 ref
this
85700
playGame(…)
Lab7 ref
theGame
85700
Version 2.0 (This class)class8_2_Elevens
9
main(…)
in theGame(…)
human.reRollOneDie(1);
reRollOneDie
Die ref
playerDie
85638int
playerRoll1
2
int
playerRoll2
7
85710
Playerin Player's reRollOneDie(…)…int playerRoll = dieToReroll.roll();if(numDie == 1) { playerRoll1 = playerRoll;} else { playerRoll2 = playerRoll;}// HERE
85638
Die
numSides
int
6
int
numDie
1
Player ref
this
85710
int
playerRoll
2
Player ref
human
85710
Die ref
playerDie1
85638
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 10
Acknowledgement
This course is based on the text
Introduction to Programming with Java by Dean & Dean, 2nd Edition
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 11