Download presentation
Presentation is loading. Please wait.
Published byJob McCarthy Modified over 9 years ago
1
SE1011 Week 8, Class 3 Today Designing Code SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 1
2
Muddiest Point having 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.debugging P.S. I didn't mean for my jokes to undermine your feedback tool <3 Should we use main() only as a "starter" to the "object" of the main program?static and main More on what can or can't be passed to a methodparameters Why did we have to use a method for main?static and main why we couldnt use main for the actual gamestatic and main 2 Discussed at start. Discussed during this class. [Instructor answer to the question]
3
Muddiest Point How 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.static should we not use main from now on?static and main 3 Discussed at start. Discussed during this class. [Instructor answer to the question]
4
Old Muddy Points Does || work the same way as && as a short circuit operator? So if(true || ) 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]
5
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
6
Version 1.0 (Start of last class) class8_2_Elevens_start 6 main(…) Die ref playerDie1 85638 Die numSides int in main(…) playerRoll1 = playerDie1.roll(); playerTotal = playerRoll1 + playerRoll2; //HERE 6 int playerRoll1 2 int playerRoll2 7 int playerTotal 9
7
Version 1.1 (Middle of class) 7 main(…) Die ref playerDie1 85638 reRollOneDie Die ref playerDie 85638 int 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 numDie 1 Lab7 ref this 85700 int playerRoll 2 in main(…) reRollOneDie(playerDie1, 1);
8
Version 1.2 (End of class) class8_2_Elevens 8 main(…) Die ref playerDie1 85638 in theGame(…) reRollOneDie(playerDie1, 1); reRollOneDie Die ref playerDie 85638 int 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 numDie 1 Lab7 ref this 85700 int playerRoll 2 Lab7 ref this 85700 playGame(…) Lab7 ref theGame 85700
9
Version 2.0 (This class) class8_2_Elevens 9 main(…) in theGame(…) human.reRollOneDie(1); reRollOneDie Die ref playerDie 85638 int playerRoll1 2 int playerRoll2 7 85710 Player in Player's reRollOneDie(…) … int playerRoll = dieToReroll.roll(); if(numDie == 1) { playerRoll1 = playerRoll; } else { playerRoll2 = playerRoll; } // HERE 85638 Die numSides int 6 numDie 1 Player ref this 85710 int playerRoll 2 Player ref human 85710 Die ref playerDie1 85638
10
SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 10
11
Acknowledgement This course is based on the text Introduction to Programming with Java by Dean & Dean, 2 nd Edition SE-1011 Slide design: Dr. Mark L. Hornick Instructor: Dr. Yoder 11
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.