AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-programming: Java Program of Premier League

It is a league in which twenty teams compete for over nine months while playing 38 matches against each other. The team with max points wins the league and Manchester united have won the most number of premier league titles.




So Basically A Team With Max Points Wins The League But What If Two Teams Have The Same Number Of Points?




Premier League authority need your help for building a Java application for this problem.







Input Format : (Assume Top 5 Teams)

First line will be the season.

Remaining five line will contain following:

Team_Name Total_Matches Wins Draws Losses Goals_Scored Goals_Conceded Goal_Difference




Tips:

1 Win Equals 3 Points

1 Draw Equals 1 Points

1 Loss Equal 0 Points







Sample Input :

Season 2011-12

Chelsea 38 18 10 10 65 46 +19

Manchester_United 38 28 5 5 89 33 +56

Arsenal 38 21 7 10 74 49 +25

Tottenham_Hotspur 38 20 9 9 66 41 +25

Manchester_City 38 28 5 5 93 29 +64




Sample Output :

Manchester_City Are The Champions Of Season 2011-12!




Explanation:

Manchester United & Manchester City Had The Same Number Of Points i.e. 89 (Wins * 3 + Draw * 1 + Loss * 0)

But Since Manchester City Had The Greater Goal Difference (64 > 56) They Where Crowned Champions.

corejava x 351
programming x 167
Posted On : 2018-01-26 20:57:07.0
profile Xda Coder - anyforum.in Xda Coder
1300
up-rate
4
down-rate

Answers


import java.util.Scanner;

public class WinnerFinder {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
String seasonName=input.nextLine().trim();
String winner=null;
int maxPoints=0;
int maxGoalDiff=0;
int points=0;
int goalDiff=0;
String[] temp=null;
for(int i=1;i<=5;i++){
temp=input.nextLine().trim().split(" ");
points=Integer.valueOf(temp[2])*3+Integer.valueOf(temp[3]);
goalDiff=Integer.valueOf(temp[7].substring(1));
if(points>maxPoints){
winner=temp[0];
maxPoints=points;
maxGoalDiff=goalDiff;
}else if(points==maxPoints && maxGoalDiff<goalDiff){
winner=temp[0];
maxPoints=points;
maxGoalDiff=goalDiff;
}
}
System.out.println(winner+" Are The Champions Of "+seasonName+"!");
}
}

Posted On : 2018-01-28 18:04:34
Satisfied : 0 Yes  2 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523187021157
Reply This Thread
up-rate
-1
down-rate
Comments
Code is lacking match draw condition
profile Xda Coder - anyforum.in Xda Coder
13  0  0
Posted On :2018-01-29 20:33:04.0
Leave a Comment
I think, it is already there.. give me that test case with input data. I´ll check.
profile Rishi Kumar - anyforum.in Rishi Kumar
523  1870  21157
Posted On :2018-01-29 21:21:53.0
Leave a Comment
Change this statement points=Integer.valueOf(temp[2])*3+Integer.valueOf(temp[2]);
to points=Integer.valueOf(temp[2])*3+Integer.valueOf(temp[3]);
profile sivasurya - anyforum.in sivasurya
0  0  0
Posted On :2018-01-31 11:37:22.0
Leave a Comment
Thanks Sivasurya. I requested admin to update it.
profile Rishi Kumar - anyforum.in Rishi Kumar
523  1870  21157
Posted On :2018-01-31 22:08:38.0
Leave a Comment



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in