Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Hard Drives – more laterHard Drives – more later MethodsMethods.

Similar presentations


Presentation on theme: "March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Hard Drives – more laterHard Drives – more later MethodsMethods."— Presentation transcript:

1 March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Hard Drives – more laterHard Drives – more later MethodsMethods

2 March 2005 2/18R. Smith - University of St Thomas - Minnesota Breaking up is hard to do But not breaking up is even worse.But not breaking up is even worse. How do you build a huge program?How do you build a huge program? –Answer: one piece at a time. –When a program gets too big, you break it into pieces to make it bigger. What is a ‘piece’ of a program?What is a ‘piece’ of a program? –We start with ‘methods’

3 March 2005 3/18R. Smith - University of St Thomas - Minnesota Stepping out of our program What have we been ignoring?What have we been ignoring? public class foobar { public static void main (… We’ve been copying that stuff blindly. But what does it mean?We’ve been copying that stuff blindly. But what does it mean?

4 March 2005 4/18R. Smith - University of St Thomas - Minnesota The part that runs is the method So far, that’s always been mainSo far, that’s always been main Tradition: the system always starts your program with a method called mainTradition: the system always starts your program with a method called main

5 March 2005 5/18R. Smith - University of St Thomas - Minnesota The “method header” public static – Method Modifierspublic static – Method Modifiers –Special features of the method. –It doesn’t matter right now what they actually mean void – Return Typevoid – Return Type –Says whether the method produces a result –“Void” means “nothing returned” – could be any type or object Then the method’s own nameThen the method’s own name –main – just the traditional starting point (String[] args) – Argument list(String[] args) – Argument list –Data passed to the method –For main, it’s data passed from Windows then the program starts

6 March 2005 6/18R. Smith - University of St Thomas - Minnesota Arguments in and out Argument list – a list of variable names and types, separated by commasArgument list – a list of variable names and types, separated by commas public static void printStub (double totalHours, double grossPay) { Return value – replaces void in the ones we’ve seen so farReturn value – replaces void in the ones we’ve seen so far

7 March 2005 7/18R. Smith - University of St Thomas - Minnesota Mini-Lab 11 Take the Lab 8 payrollTake the Lab 8 payroll Rename itRename it Make it use 3 or 4 methodsMake it use 3 or 4 methods –weeksPay (Scanner sc) – most of your current main –printStub (totalHours, grossPay) – the printing part –main – creates a Scanner and calls weeksPay Optional for an extra point:Optional for an extra point: –String dayOfWeek(int day) – converts digit into a day We will be using Lab 11 for some in-class work on Monday! Be sure it works!We will be using Lab 11 for some in-class work on Monday! Be sure it works!

8 March 2005 8/18R. Smith - University of St Thomas - Minnesota That’s it. Questions?Questions? Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.


Download ppt "March 2005 1/18R. Smith - University of St Thomas - Minnesota QMCS 230: Today in Class Hard Drives – more laterHard Drives – more later MethodsMethods."

Similar presentations


Ads by Google