DOC PREVIEW
OSU CSE 1223 - PRO11A

This preview shows page 1 out of 4 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

project11a For this lab you will write a Java program that produces a simple formatted report The program will prompt the user to enter a file name author version 20140923 package osu cse1223 import import import import import import import java io BufferedWriter java io File java io FileWriter java util ArrayList java util HashMap java util List java util Scanner public class project11a private static Scanner sc public static void main String args sc new Scanner System in String fileName int totalParticipants 0 List Integer avgScore new ArrayList Integer HashMap Integer String playerInfo new HashMap Integer String System out println Enter file name fileName sc next try File fileOp new File report txt if fileOp exists fileOp createNewFile FileWriter fw new FileWriter fileOp getAbsoluteFile BufferedWriter bw new BufferedWriter fw System out println Final Overall Scores Report n bw write Final Overall Scores Report bw newLine File file new File fileName Scanner fileScanner new Scanner file bw newLine System out println Name t t tMean tMedian tMax tMin bw write Name t t tMean tMedian tMax tMin n bw newLine System out println bw write bw newLine while fileScanner hasNextLine String playerName fileScanner nextLine List Integer playerScores readNextSeries fileScanner totalParticipants bw newLine avgScore add getAverage playerScores playerInfo put getAverage playerScores playerName System out println formatName playerName t getAverage playerScores t getMedian playerScores t getMax playerScores t getMin playerScores n bw write formatName playerName t getAverage playerScores t getMedian playerScores t getMax playerScores t getMin playerScores bw newLine if fileScanner hasNextLine fileScanner nextLine bw newLine System out println nTotal number of participants totalParticipants bw write Total number of participants totalParticipants bw newLine int maxScore getMax avgScore int minScore getMin avgScore bw newLine System out println Highest average score playerInfo get maxScore maxScore n bw write Highest average score playerInfo get maxScore maxScore bw newLine System out println Lowest average score playerInfo get minScore minScore n bw write Lowest average score playerInfo get minScore minScore bw newLine bw close System out println Writing content to report txt file completed n catch Exception e System out println Exception occured e printStackTrace private static List Integer readNextSeries Scanner inScanner List Integer playerScores new ArrayList Integer while inScanner hasNextLine int score inScanner nextInt if score 1 break else playerScores add score return playerScores private static int getMedian List Integer inList int temp int median int intArray new int inList size for int i 0 i inList size i intArray i inList get i for int i 0 i intArray length 1 i for int j i 1 j intArray length j if intArray i intArray j temp intArray i intArray i intArray j intArray j temp int middle intArray length 2 if intArray length 2 0 int medianA intArray middle int medianB intArray middle 1 median medianA medianB 2 else median intArray middle return median private static int getAverage List Integer inList int avg int sum 0 for int i 0 i inList size i sum sum inList get i avg sum inList size return avg private static int getMin List Integer inList int min inList get 0 for int i 0 i inList size i if inList get i min min inList get i return min private static int getMax List Integer inList int max inList get 0 for int i 0 i inList size i if inList get i max max inList get i return max private static String formatName String name if name length 23 return name else for int i name length i 23 i name name return name


View Full Document

OSU CSE 1223 - PRO11A

Documents in this Course
PRO12A

PRO12A

3 pages

PRO10A

PRO10A

3 pages

PRO9A

PRO9A

3 pages

PRO8A

PRO8A

3 pages

PRO7A

PRO7A

2 pages

PRO6A

PRO6A

2 pages

PRO4A

PRO4A

3 pages

PRO3A

PRO3A

3 pages

CL13A

CL13A

2 pages

CL11B

CL11B

2 pages

CL11A

CL11A

2 pages

CL10A

CL10A

2 pages

CL5A

CL5A

2 pages

Load more
Download PRO11A
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view PRO11A and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view PRO11A and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?