Solved

# Android : find smallest difference

Posted on 2012-08-27
880 Views
Hi Experts,
----------------------------------------------------------------------------------------------------------------
The file football.txt contains the results from the English Premier League for 2001/2. The columns labeled ‘F’ and ‘A’ contain the total number of goals scored for and against each team in that season (so Arsenal scored 79 goals against opponents, and had 36 goals scored against them). Need a java program to print the name of the team with the smallest difference in ‘for’ and ‘against’ goals.
-------------------------------------------------------------------------------------------------------------
My main objective of this question is to identify the activities we will be able to write the code and demonstrate some of the practices and techniques that we would use in best practices under industry. I'm mainly be looking for the thought process and how we can complete this task. But points goes to the first/best post.

Thanks a lot Experts.
football-1--1-.txt
0
Question by:Dushan911

LVL 50

Accepted Solution

So if I understand your question correctly you need something like this
(pseudo-code)
``````openfile
current = 10000
team = ""
cells = split(line)
diff = cell(7) - cell(9) // SEE first point - might need to take absolute value here
if (diff < current) {
current = diff
team = cell(2)
}
}
output "Team " + team + " With " + current + " goal diff"
``````

1. It was not clear if you want the difference only to be positive where teams have scored more goals than have been scored against them - or are you only interested in absolute goal difference so if team A scores 80 for and has 60 against diff is 20 but Team B scores 60 and has 65 agains diff is 5 - which team is the one you want?
0

LVL 14

Assisted Solution

Apart the platform you are on; You have to parse the text to read each value associated with each team. You may choose to use simple string handling functions approach but you will have a hard time though. I suggest you to use regular expressions which allows you to parse such texts and detects the elements of the text based on your expression. Regular Expression is well integrated in almost all programmings.

Regex in java:
0

LVL 17

Author Closing Comment

Thanks a lot!
0

## Featured Post

If your app took Google’s lash recently, here are the 5 most likely reasons.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.