Menu
Question Index
...


Write a program to find the result of a cricket match. The method takes two innings and compares them to give the results. The Innings class and the MatchResult class are already defined.

Input (Innings 1 and Innings 2 Details) (Team Name, score, wickets and overs) Output (Match Result)
Innings 1 = "India", 243, 5, 50.0
Innings 2 = "Australia", 231, 9, 50.0
winner = "India"
loser = "Australia"
wonByWickets = false
wonByRuns = true
runs = 243 - 231 = 12
wickets = 0
Innings 1 = "India", 243, 5, 50.0
Innings 2 = "Australia", 245, 9, 48.3
winner = "Australia"
loser = "India"
wonByWickets = true
wonByRuns = false
runs = 0
wickets = 10 (Total Wickets) - 9 = 1
Innings 1 = "India", 243, 5, 50.0
Innings 2 = "Australia", 243, 9, 50.0
wonByWickets = false
wonByRuns = false
runs = 0
wickets = 0

class FindMatchResult

{    public static void main(String s[])
    {
        Innings india = new Innings("India", 243, 5, 50.0);
        Innings australia = new Innings("Australia", 231, 9, 50.0);
        
        MatchResult result = findMatchResult(india, australia);
        
        if(result.wonByWickets)
        {
            System.out.println(result.winner + " won over " + result.loser  + " by " + result.wickets + " wickets.");
        }
        else if (result.wonByRuns)
        {
            System.out.println(result.winner + " won over " + result.loser  + " by " + result.runs + " runs.");
        }
        else
        {
            System.out.println("The match between India and Australia was a tie.");
        }

    }


public static MatchResult findMatchResult(Innings team1, Innings team2)
{
//Write code here to create the MatchResult by comparing the innings and return the same.
}
}
class Innings
{
String teamName;
int runs;
int wickets;
double overs;

Innings(String teamName, int runs, int wickets, double overs)
{
this.teamName = teamName;
this.runs = runs;
this.wickets = wickets;
this.overs = overs;
}
}

class MatchResult
{
String winner;
String loser;
boolean wonByWickets;
boolean wonByRuns;
int wickets;
int runs;
}

Doubts

Problems

Topic: Is Java Pass by Reference or Pass by Value

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App