Programming Methodology (1). Implementing Methods main.
-
Upload
carson-denier -
Category
Documents
-
view
224 -
download
2
Transcript of Programming Methodology (1). Implementing Methods main.
![Page 1: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/1.jpg)
Programming Methodology (1)
![Page 2: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/2.jpg)
Implementing Methods
main
![Page 3: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/3.jpg)
Learning objectives
• explain the meaning of the term method;
• declare and define methods;
• call a method;
• explain the meaning of the terms actual parameters and formal parameters;
• return a result from a method;
• explain the meaning of the term polymorphism;
• declare and use overloaded methods;
• use methods to implement menu driven programs.
![Page 4: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/4.jpg)
public static void main(String[ ] args){
}
// code to accomplish task A
// code to accomplish task B
// code to accomplish task A
{
}
method A
CALL method A
CALL method A
// code to accomplish task A
![Page 5: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/5.jpg)
Using methods: a first example…
![Page 6: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/6.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
firstName = sc.next(); System.out.println("Please enter your family name");
// more code here }
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );
![Page 7: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/7.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 8: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/8.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 9: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/9.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 10: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/10.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 11: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/11.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 12: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/12.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 13: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/13.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 14: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/14.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 15: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/15.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 16: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/16.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 17: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/17.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 18: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/18.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 19: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/19.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 20: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/20.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 21: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/21.jpg)
public static void main(String[ ] args){ // variables declared here
System.out.println("Please enter your first name");
firstName = sc.next(); System.out.println("Please enter your family name");
}
System.out.println(“All information supplied is confidential");System.out.println("No personal details will be shared ");
{
}
displayMessage( )private static void
displayMessage( );
displayMessage( );// more code here
![Page 22: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/22.jpg)
Another example:
The DisplayStars program
![Page 23: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/23.jpg)
public static void main (String [ ] args){
}
for (int i = 1; i < = 5; i++){
System.out.println(*****);}
for (int i = 1; i < = 5; i++){
System.out.println(*****);}
private static void showStars( ){
}
showStars( );
![Page 24: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/24.jpg)
Let’s look at the version of DisplayStars where the user chooses the size of the square..
* * *
* * *
* * *
![Page 25: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/25.jpg)
Let’s look at the version of DisplayStars where the user chooses the size of the square..
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
![Page 26: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/26.jpg)
public static void main(String[ ] args) { int num; Scanner sc = new Scanner (System.in); System.out.println("Size of square?"); num = sc.nextInt(); for (int i = 1; i <= num ; i++) {
for (int j = 1; j<= num ; j++) {
System.out.print("*"); } System.out.println(); }
}
private static void showStars( )
{
}
showStars( );}
![Page 27: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/27.jpg)
public static void main(String[ ] args) { int num; Scanner sc = new Scanner (System.in); System.out.println("Size of square?"); num = sc.nextInt();
for (int i = 1; i <= ; i++) {
for (int j = 1; j<= ; j++) {
System.out.print("*"); } System.out.println(); }
private static void showStars( )
{
}
showStars( );}
num
num
showStars( num );
int )
numIn
numIn
numIn
num
numIn
?actual parameter
formal parameter
![Page 28: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/28.jpg)
Remember parameters are copies!
![Page 29: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/29.jpg)
public static void main(String[ ] args){ int x = 1; method1(x); System.out.print(x); }
private static void method1(int{
}
x )
x = x + 1;System.out.print(x); xIn = xIn + 1;System.out.print(xIn);
xIn )
xxIn
x 1
12
![Page 30: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/30.jpg)
Some more examples of writing methods: add
![Page 31: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/31.jpg)
public static void main (String [ ] args)
{
}
int x, y, z; x = 10; y = 20; z = x + y;
private static add ( )? int num1, num2int num1, int num2int{
}
int sum = num1 + num2; return sum; return num1 + num2;
add (x, y) ;
![Page 32: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/32.jpg)
public static void main (String [ ] args)
{
}
int x, y, z; x = 10; y = 20;
x + y;
private static add ( )int num1, int num2int{
}
return num1 + num2;
add (x, y) ;z =System.out.println( ); x + yadd (x, y)
![Page 33: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/33.jpg)
Some more examples of writing methods: isEven
![Page 34: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/34.jpg)
if( ){
}else{
}
isEven( ) int numberIn private static boolean
{
return true;
return false;
numberIn % 2 == 0
}
return (numberIn % 2 == 0 );
}
![Page 35: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/35.jpg)
Using the isEven method….
![Page 36: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/36.jpg)
public static void main (String [ ] args)
{
}
int num = 10;
if( ){
}
isEven(num) == true
System.out.println(“number is odd”);System.out.println(“number is even”);
! == false
![Page 37: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/37.jpg)
Revisiting the DisplayStars Program
* * *
* * *
* * *
![Page 38: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/38.jpg)
public static void main(String[ ] args){ int num; num = showStars(num); }
private static void showStars( int numIn){
// code goes here}
Scanner sc = new Scanner (System.in);System.out.println("Size of square?");
sc.nextInt();getSize( );
![Page 39: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/39.jpg)
private static getSize( ){
}
public static void main(String[ ] args){ int num; num = showStars(num); }private static void showStars( int numIn){ // code goes here }
Scanner sc = new Scanner (System.in);System.out.println("Size of square?");size = sc.nextInt();
getSize( );
int size;
return size;
int
![Page 40: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/40.jpg)
Method overloading
![Page 41: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/41.jpg)
Drawing a rectangle instead of a square..
* * * * *
* * * * * * * * * *
![Page 42: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/42.jpg)
private static void showStars( int{ for(int i = 1; i <= ; i++) {
for (int j = 1; j<= ; j++) {
System.out.print("*"); } System.out.println(); }}
numIn
numIn
numIn) )rowIn
colIn
rowIn
colIn, int
![Page 43: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/43.jpg)
private static void showStars(int numIn){ // code to draw square here}
private static void showStars(int rowIn, int colIn){ // code to draw rectangle here}
Two or more methods with the same name performing different functions:
“METHOD OVERLOADING”
Method overloading is an example of
“POLYMORPHISM”
![Page 44: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/44.jpg)
private static void showStars(int numIn){ // code to draw square here}
private static void showStars(int rowIn, int colIn){ // code to draw rectangle here}
public static void main (String [ ] args){
}
showStars( 4, 7);
showStars( 6 );
![Page 45: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/45.jpg)
Using methods in menu driven programs.
![Page 46: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/46.jpg)
*** Lab Times ***
[1] TIME FOR GROUP A
[2] TIME FOR GROUP B
[3] TIME FOR GROUP C
[4] QUIT
Enter choice [1-4]: 2
1.OOp.m
![Page 47: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/47.jpg)
*** Lab Times ***
[1] TIME FOR GROUP A
[2] TIME FOR GROUP B
[3] TIME FOR GROUP C
[4] QUIT
Enter choice [1-4]: 5
Options 1-4 only!
![Page 48: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/48.jpg)
*** Lab Times ***
[1] TIME FOR GROUP A
[2] TIME FOR GROUP B
[3] TIME FOR GROUP C
[4] QUIT
Enter choice [1-4]: 1
10.OOa.m
![Page 49: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/49.jpg)
*** Lab Times ***
[1] TIME FOR GROUP A
[2] TIME FOR GROUP B
[3] TIME FOR GROUP C
[4] QUIT
Enter choice [1-4]: 3
11.00a.m
![Page 50: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/50.jpg)
*** Lab Times ***
[1] TIME FOR GROUP A
[2] TIME FOR GROUP B
[3] TIME FOR GROUP C
[4] QUIT
Enter choice [1-4]: 4
Goodbye
![Page 51: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/51.jpg)
public static void main (String [ ] args){ char choice; // declare more variables do {
} while (choice != ‘4’);}
// display menu
// get choice
// process choice (using ‘switch’)
![Page 52: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/52.jpg)
switch (choice){
}
case ‘1’:
case ‘2’:
case ‘3’:
System.out.println(“10.00am”);
System.out.println(“1.00pm”);
System.out.println(“11.00am”);
default: System.out.println(“1-4 only”);
break;
break;
break;case ‘4’: System.out.println(“Goodbye”);
break;
![Page 53: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/53.jpg)
switch (choice){
}
case ‘1’:
case ‘2’:
case ‘3’:
System.out.println(“1.00pm”);
System.out.println(“11.00am”);
default: System.out.println(“1-4 only”);
break;
break;
break;
option1( );
case ‘4’: System.out.println(“Goodbye”);break;
![Page 54: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/54.jpg)
switch (choice){
}
case ‘1’:
case ‘2’:
case ‘3’: System.out.println(“11.00am”);
default: System.out.println(“1-4 only”);
break;
break;
break;
option1( );
option2( );
case ‘4’: System.out.println(“Goodbye”);break;
![Page 55: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/55.jpg)
switch (choice){
}
case ‘1’:
case ‘2’:
case ‘3’:
default: System.out.println(“1-4 only”);
break;
break;
break;
option1( );
option2( );
option3( );
case ‘4’: System.out.println(“Goodbye”);break;
![Page 56: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/56.jpg)
private static void option1 ( ){
System.out.println(“10.00am”);}
private static void option2 ( ){
System.out.println(“1.00pm”);}
private static void option3 ( ){
System.out.println(“11.00am”);}
![Page 57: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/57.jpg)
![Page 58: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/58.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
![Page 59: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/59.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
![Page 60: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/60.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
![Page 61: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/61.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
firstIn
![Page 62: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/62.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
3firstIn
![Page 63: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/63.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
firstIn 3
secondIn
![Page 64: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/64.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
firstIn 3
secondIn 5
![Page 65: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/65.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
firstIn 3
secondIn 5
![Page 66: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/66.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
firstIn 3
secondIn 5
![Page 67: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/67.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( -2 ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
![Page 68: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/68.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
![Page 69: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/69.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
-2
![Page 70: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/70.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
-2
![Page 71: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/71.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
-2
![Page 72: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/72.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
-2
![Page 73: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/73.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
-2
![Page 74: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/74.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
-2
![Page 75: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/75.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
-2
![Page 76: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/76.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
-2
![Page 77: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/77.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( 18 ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
-2
![Page 78: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/78.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
-2
![Page 79: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/79.jpg)
public class MethodsQ1{ public static void main(String[ ] args) { System.out.println( myMethod( 3, 5) ); System.out.println( myMethod( 3, 5, 10) ); }
private static int myMethod(int firstIn, int secondIn, int thirdIn) { return firstIn + secondIn + thirdIn; } private static int myMethod(int firstIn, int secondIn) { return firstIn - secondIn; }}
What would be displayed on the screen when this program was run?
-218
![Page 80: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/80.jpg)
import java.util.*;
public class FindCost3{ public static void main(String[ ] args ) {
Scanner sc = new Scanner(System.in); double price, tax;System.out.println("*** Product Price Check ***");System.out.print("Enter initial price: "); price = sc.nextDouble(); System.out.print("Enter tax rate: "); tax = sc.nextDouble(); price = price * (1 + tax/100); System.out.println("Cost after tax = " + price);
}}
![Page 81: Programming Methodology (1). Implementing Methods main.](https://reader034.fdocuments.in/reader034/viewer/2022051614/551b3119550346dd1a8b4e2d/html5/thumbnails/81.jpg)
import java.util.*;
public class FindCost3{ public static void main(String[ ] args ) {
double price, tax;
}}
// call method to display title
// call method to get price// call method to get tax// call method to calculate new price// call method to display result
displayTitle( );
price = getPrice( );tax = getTax( );price = calculate( price, tax);
displayResult( price);