Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java - Programming Problems

nzeukoue
nzeukoue 


1) Develop a program in Java to calculate the League Table of the Football Premier League. The file matches.csv is in the comma separated value (.csv) text format (can be visualized with Wordpad or Excel), containing the data of all the football matches played in the season 2013/2014; the file teams.txt contain the list of teams, one team per line, and the team names in the teams.txt file are exactly the same string as the team names in matches.csv file. The matches file is an excerpt of the file containing the up-to-date results of the current season 2013/2014 available on-line at: http://football-data.co.uk/; the matches.txt file is a simplified subset of such file. A single football match can end with a win or a draw: in first case the winner team get 3 points and the loser none, in the second case (draw) each of the two teams get 1 point. For example, the first line of the file matches.txt is as follow: 17/08/2013, Arsenal, Aston Villa, 1, 3 This means that a match has been played on the 17/08/2013 where Arsenal scored 1 goal while Aston Villa 3 goals: thus Arsenal got 0 points while Aston Villa 3 points. The third line of the file matches.txt is as follow: 17/08/2013, Norwich, Everton, 2, 2 This means that both Norwich and Everton scored 2 goals: the match is a draw and each team get 1 point. The goal of the problem is to read this file and print the league table on screen and on a new file table.txt: the following example showed the desired output using the matches played so far, where the leading time (Chelsea) has 66 points to the bottom team (Fulham) with 24 points. The other columns contain the number of matches played and the Goal Difference (GD), that is (total goals scored) – (total goals conceded). Position Team Played GD Points 1 Chelsea 30 33 66 2 Liverpool 29 41 62 3 Arsenal 29 25 62 4 Man City 27 44 60 5 Tottenham 30 -1 53 6 Everton 28 12 51 7 Man Utd 29 12 48 8 Southampton 30 6 45 9 Newcastle 29 -3 43 10 Aston Villa 29 -6 34 11 Stoke 30 -12 34 12 West Ham 29 -6 31 13 Hull 29 -7 30 14 Swansea 29 -5 29 15 Norwich 30 -24 29 16 West Brom 29 -10 28 17 Crystal Palace 29 -19 28 18 Sunderland 27 -16 25 19 Cardiff 30 -29 25 20 Fulham 30 -35 24 In order to sort the list of teams you might want to use any simple sorting algorithm: bubble sort can be the simplest option; you can download from Moodle an implementation in C bubblesort.c together with the matches.txt file. An additional feature of the program is to display and print on a file the league table until a date inserted by the user. 2) Solve the following problem with a java language of choice. Critically discuss and evaluate the algorithm of your solution. London sightseeing tours by bus are very popular among tourists! Some people go alone; other people go in groups, and don't want to board the bus unless they can all go together. And everyone who gets on the bus wants to get on again. A ride costs (ideally) 1 Pound per person; your job is to figure out how much money the London bus company will make in one single day. The bus can hold k people at once. People queue for it in groups. Groups board the bus, one at a time, until there are no more groups left or there is no room for the next group; then the bus goes, whether it's full or not. Once the ride is over, all of its passengers re-queue in the same order. The bus will run R times in a day. For example, suppose R=4, k=6, and there are four groups of people with sizes: 1, 4, 2, 1. The first time the bus goes, the first two groups [1, 4] will ride, leaving an empty seat (the group of 2 won't fit, and the group of 1 can't go ahead of them). Then they'll go to the back of the queue, which now looks like 2, 1, 1, 4. The second time, the bus will hold 4 people: [2, 1, 1]. Now the queue looks like 4, 2, 1, 1. The third time, it will hold 6 people: [4, 2]. Now the queue looks like [1, 1, 4, 2]. Finally, it will hold 6 people: [1, 1, 4]. The bus has made a total of 21 Pounds! Input The first line of the input gives the number of test cases, T. T test cases follow, with each test case consisting of two lines. The first line contains three space-separated integers: R, k and N. The second line contains N space-separated integers gi, each of which is the size of a group that wants to ride. g0 is the size of the first group, g1 is the size of the second group, etc. Output For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of Euros made by the bus. Limits (3a. small dataset) 1 ≤ T ≤ 50 ; gi ≤ k. 1 ≤ R ≤ 1000. 1 ≤ k ≤ 100. 1 ≤ N ≤ 10. 1 ≤ gi ≤ 10. Example Input Output 3 Case #1: 21 4 6 4 Case #2: 100 1 4 2 1 Case #3: 20 100 10 1 1 5 5 10 2 4 2 3 4 2 1 2 1 3 Problem 3b (large dataset) Improve the solution of the previous problem in order to manage a large dataset, that is: 1 ≤ R ≤ 108. 1 ≤ k ≤ 109. 1 ≤ N ≤ 1000. 1 ≤ gi ≤ 107. Attachments Tags Clarifications

Answers

Half Solution

mariobeka
mariobeka 



As mentioned in the email. Attachments
Format.java (1 K) Download Preview
ch) { if (s.length() < width) return s + makeString(ch, width - s.length()); else if (s.length() == width) return s; else return s.substring(0, s.length() - 1); } private static String makeString(char c, int length) { if (length <=

GameResult.java (1 K) Download Preview
} public GameResult(Team home, int homeGoals, Team away, int awayGoals){ this.homeTeam = home; this.awayTeam = away; this.homeGoals = homeGoals; this.awayGoals = awayGoals; } public GameResult(Team home, Team away, int homeGoals, int awayGoals){ this(home, homeGoals, away, awayGoals); } public Object clone(){ try{ return super.clone(); } catch (CloneNotSupportedException e) {return null;} }

League.java (2 K) Download Preview
The collection of results in the turnament: GameResult objects */ private Collection<GameResult> gameResults; /** * Return a new collection of those game result objects of this turnament * that fulfills the predicate p */ public Collection gameFiltering(Predicate p) { Collection result = GameResult.makeGameResultCollection(); for (Iterator i = gameResults.iterator(); i.hasNext();) {

Predicate.java (1 K) Download Preview
object that encapsulates an boolean condition */ abstract class

Team.java (6 K) Download Preview
&& // thisTeam is // away team in // game result gr.awayGoals() > gr.homeGoals()); else return false; // cannot happen } }); return matchingGames; } public int numberOfWonMatches(League turnament, final int where) { Collection matchingGames = wonMatches(turnament, where); return matchingGames.size(); } public Collection lostMatches(League turnament, final int where) { Collection

TeamComparator.java (1 K) Download Preview
= team1.goals(contextualLeague) - team1.goalsAgainst(contextualLeague); //<e:teamDiff1/> int teamDiff2 = team2.goals(contextualLeague) - team2.goalsAgainst(contextualLeague); //<e:teamDiff2/> if (teamDiff1 > teamDiff2) return -1; else if (teamDiff1 < teamDiff2) return 1; else if (teamDiff1 == teamDiff2){ int goals1 = team1.goals(contextualLeague);//<e:goals1/> int goals2 = team2.goals(contextualLeague);//<e:goals2/> if (goals1 > goals2) return

StandingLeage.java (4 K) Download Preview
try { br.close(); // br1.close(); } catch (IOException e) { e.printStackTrace(); } } } } private static void readCsvFile(String csvFile, BufferedReader br) { // SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); String cvsSplitBy = ","; String line; int x = 0; try { // br1 = new BufferedReader(new FileReader(teamsFile)); br = new

Screenshots
Purchase Answer

Problem 2 solved

zkingleo2009
zkingleo2009 



Attached is the solved problem 2. Attachments
London Bus.zip (12 K) Download









Preview
version="1.0" encoding="utf-8" ?> <configuration>

Preview
6 4 1 4 2 1 5

Preview
money = money + list[j]; seats = seats - list[j]; listSize--; tempList.Add(list[j]); list.RemoveAt(j--); } } seats = k; for (int a = 0; a < tempList.Count; a++) { list.Add(tempList[a]); } tempList.Clear(); } Console.WriteLine("Case # " +

Preview
[assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("50171fa0-b896-44d4-adee-3b2fb23f00d2")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // //

Screenshots
Purchase Answer

London Bus Problem

zkingleo2009
zkingleo2009 



Attached is the java implementation of the london bus problem provided. The last one was for visual studio C#. You Can check all the test cases by entering them on the console. Attachments
londonbus.zip (1 K) Download
Preview
: "); int tests = input.nextInt(); for (int i = 0; i < tests; i++) { System.out.println("Enter the number of times the bus will run : "); int Run = input.nextInt(); System.out.println("Enter the capacity of the bus : "); int capacity =

Screenshots
Purchase Answer