Logout

Methods With and Without Parameters




MethodsUsingParameters.java




/Users/adelaide/Public/Netbeans - All JSR Projects/DRILL AND PRACTICE - John/src/drillandpracticepackage/MethodsUsingParameters.java
 1 
 2 package drillandpracticepackage;
 3 
 4 import java.io.BufferedReader;
 5 import java.io.InputStreamReader;
 6 
 7 /**
 8  *
 9  * @author John Rayworth
10  */
11 public class MethodsUsingParameters {
12 
13     public static void main(String[] args) {
14         try {
15             BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
16 
17             System.out.println(methodWithReturn());
18             methodWithoutReturn();
19 
20             System.out.println("What is the name of team 1 in this game?");
21             String team1 = br.readLine();
22             System.out.println("How many goals did they score?");
23             int score1 = Integer.parseInt(br.readLine());
24             System.out.println("What is the name of team 2 in this game?");
25             String team2 = br.readLine();
26             System.out.println("How many goals did they score?");
27             int score2 = Integer.parseInt(br.readLine());
28             String winner = calculateWinner(team1, score1, team2, score2);
29             System.out.println("The winner is " + winner + ".");
30 
31 
32         } catch (Exception e) {
33             System.out.println("Error in main.");
34         }
35 
36     }
37 
38     public static String methodWithReturn() {
39         return "hello world";
40     }
41 
42     public static void methodWithoutReturn(){
43         System.out.println("how are you doing?");
44     }
45 
46     public static String calculateWinner(String team1, int score1, String team2, int score2){
47         String winningTeam = "not set yet";
48         if(score1 > score2){
49             winningTeam = team1;
50         }else{
51             winningTeam = team2;
52         }
53         return winningTeam;
54     }
55 
56 }
57 
58