Programming Methodology (1). Implementing Methods main.

Slides:



Advertisements
Similar presentations
IS Programming Fundamentals 1 (Lec) Date: September 14, Array.
Advertisements

Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
Introduction to Programming
1 Lecture 16/3/11: Contents Example of an array of user-defined objects: Car and Carr Constructor Providing functionalities for a user- defined object.
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Computer Programming Lab(7).
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
Building Java Programs Interactive Programs w/ Scanner What is a class? What is an object? What is the difference between primitive and object variables?
Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
Interfaces CSC 171 FALL 2004 LECTURE 14. Project 1 review public class Rational { private int numerator, denominator; public Rational(int numerator, int.
CS110 Programming Language I
MSc IT Programming Methodology (2). number name number.
Using Classes to Store Data Computer Science 2 Gerb.
Notes from HW3 / Lab3 Program documentation – At the top of every class: //************************************************************ // seu01.java Author:
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
Building Java Programs
Computer Programming Lab 8.
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
What have we learned so far… Preprocessor directives Introduction to C++ Variable Declaration Display Messages on Screen Get Information from User Performed.
Methods. int month; int year class Month Defining Classes A class contains data declarations (static and instance variables) and method declarations (behaviors)
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
School of Computing Science CMT1000 © Ed Currie Middlesex University Lecture 10: 1 TEST!!
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
Unit 2: Java Introduction to Programming 2.1 Initial Example.
MSc IT Programming Methodology (2). MODULE TEAM Dr Aaron Kans Dr Sin Wee Lee.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Week 2 - Wednesday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
Chapter 4 -2 part Writing Classes 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design © 2007 Pearson Addison-Wesley. All.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
 2005 Pearson Education, Inc. All rights reserved. 1 Introduction to Classes and Objects.
Method OverloadingtMyn1 Method overloading Methods of the same name can be declared in the same class, as long as they have different sets of parameters.
Classes - Intermediate
Method Examples CS 139 Algorithm Development 10/06/2008.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Class Everything in Java is in a class. The class has a constructor that creates the object. If you do not supply a constructor Java will create a default.
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Chapter 2 Clarifications
More Sophisticated Behavior
AKA the birth, life, and death of variables.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Lecture 10: More on Methods and Scope
Introduction to Methods in java
Methods.
Something about Java Introduction to Problem Solving and Programming 1.
Method Mark and Lyubo.
March 29th Odds & Ends CS 239.
CSC 113 Tutorial QUIZ I.
Introduction to Classes and Methods
Classes, Encapsulation, Methods and Constructors (Continued)
CS2011 Introduction to Programming I Methods (II)
AKA the birth, life, and death of variables.
class PrintOnetoTen { public static void main(String args[]) {
Scope of variables class scopeofvars {
CSE Module 1 A Programming Primer
Eighth step for Learning C++ Programming
Corresponds with Chapter 5
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Programming Methodology (1)

Implementing Methods main

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.

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

Using methods: a first example…

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( )privatestaticvoid displayMessage( ); displayMessage( );

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

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( )privatestaticvoid displayMessage( ); // more code here

Another example: The DisplayStars program

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( );

Let’s look at the version of DisplayStars where the user chooses the size of the square.. * * * * * * * * *

* * * * * * * * * * * * * * * * * * * * * * * * *

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( ); }

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 showStars( num ); int ) numIn numIn num numIn ? actual parameter formal parameter

Remember parameters are copies!

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

Some more examples of writing methods: add

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) ;

public static void main (String [ ] args) { } int x, y, z; x = 10; y = 20; x + y; private staticadd ( )int num1, int num2int {}{} return num1 + num2; add (x, y) ;z = System.out.println( );x + y add (x, y)

Some more examples of writing methods: isEven

if( ) { } else { } isEven( )intnumberInprivatestaticboolean { return true; return false; numberIn % 2 == 0 } return (numberIn % 2 == 0 ); }

Using the isEven method….

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

Revisiting the DisplayStars Program * * * * * * * * *

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( );

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

Method overloading

Drawing a rectangle instead of a square.. * * * * * * * * * * * * * * *

private static void showStars( int { for(int i = 1; i <= ; i++) { for (int j = 1; j<= ; j++) { System.out.print("*"); } System.out.println(); } numIn ))rowIn colIn rowIn colIn, int

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”

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 );

Using methods in menu driven programs.

*** 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

*** 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!

*** 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

*** Lab Times *** [1] TIME FOR GROUP A [2] TIME FOR GROUP B [3] TIME FOR GROUP C [4] QUIT Enter choice [1-4]: a.m

*** 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

public static void main (String [ ] args) { char choice; // declare more variables do { } while (choice != ‘4’); } // display menu // get choice // process choice (using ‘switch’)

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; case ‘4’:System.out.println(“Goodbye”); break;

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; option1( ); case ‘4’:System.out.println(“Goodbye”); break;

switch (choice) { } case ‘1’: case ‘2’: case ‘3’:System.out.println(“11.00am”); default:System.out.println(“1-4 only”); break; option1( ); option2( ); case ‘4’:System.out.println(“Goodbye”); break;

switch (choice) { } case ‘1’: case ‘2’: case ‘3’: default:System.out.println(“1-4 only”); break; option1( ); option2( ); option3( ); case ‘4’:System.out.println(“Goodbye”); break;

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”); }

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?

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?

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?

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

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? 3 firstIn

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

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

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

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

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?

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?

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

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

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

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

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

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

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

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

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

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

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 18

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); }

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);