Android : find smallest difference

Posted on 2012-08-27
Last Modified: 2013-11-24
Hi Experts,
Could you please help me to resolve following problem.
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.
Question by:Dushan911
    LVL 50

    Accepted Solution

    So if I understand your question correctly you need something like this
    current = 10000
    team = ""
    while (line=read_line_from_file) {
       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"

    Open in new window

    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?
    LVL 14

    Assisted Solution

    by:Hamidreza Vakilian
    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:
    LVL 17

    Author Closing Comment

    Thanks a lot!

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    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 (". It will help one to understand clearly the steps to track a lost android phone.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now