My homework 299 lines and thats just 1/6of what i have - TopicsExpress



          

My homework 299 lines and thats just 1/6of what i have written /** This Client is for storing player data @author David Teague @version 1.0.1 */ import java.io.*; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; public class PlayerClient { private Scanner keyboard = new Scanner(System.in); /* This method is the Driver for our program. It will run all the commands that contol this program. */ public static void main (String arg[])throws IOException { int i = 0; int choice; int type; Scanner keyboard = new Scanner(System.in); Player[] array; array = new Player[20]; array[i++] = new QuaterBack(Drew Bledsoe, 42, 10, 20, 30, 40, 50, 60); array[i++] = new Receiver(Adam Dude, 46, 10, 20, 30, 40, 50, 60); array[i++] = new Defensive(Hector Gomes, 22, 10, 20, 30, 40, 50); array[i++] = new QuaterBack(Andrew Asole, 42, 10, 20, 30, 40, 50,60); array[i++] = new Receiver(Roger Dude, 46, 10, 20, 30, 40, 50, 60); array[i++] = new Defensive(Mike Tommy, 22, 10, 20, 30, 40, 50); do { System.out.print(\n\n*****************************\nPlease choose an option,\n1. Enter Player Data\n2.); System.out.print( Search Player Data\n3. Print Player Data\n4. Quit Program : ); choice = keyboard.nextInt(); switch (choice) { case 1: { System.out.print(\n1. QuaterBack\n2. Receiver\n3. Defense : ); type = keyboard.nextInt(); switch (type) { case 1: { newQ(array, i++); } break; case 2: { newR(array, i++); } break; case 3: { newD(array, i++); } break; } } break; case 2: { System.out.print(\n1. Search by Name\n2. Search by Age : ); type = keyboard.nextInt(); switch (type) { case 1: { //SearchByName(array, i); } break; case 2: { searchByAge(array, i); } break; } } break; case 3: { System.out.print(\n1. Print Data to File (root\\players)\n2. Print to Screen\n3. Sort Players : ); type = keyboard.nextInt(); switch (type) { case 1: { pFile(array, i); } break; case 2: { pScreen(array, i); } break; case 3: { System.out.print(\n1. Sort by Name\n2. Sort by Age : ); type = keyboard.nextInt(); switch (type) { case 1: { sortByName(array, i); } break; case 2: { sortByAge(array, i); } break; } } break; } } break; } }while (choice != 4); } public static void newQ (Player[] current, int j) { Scanner keyboard = new Scanner(System.in); int a, td, lp, c, fd, s, i; String name; System.out.print(\nQuaterBacks Stats:\nAll numbers are based by Foot(ft.)\n); System.out.print(\nName: ); name = keyboard.nextLine(); System.out.print(Age: ); a = keyboard.nextInt(); System.out.print(Touch-Downs: ); td = keyboard.nextInt(); System.out.print(Longest Pass: ); lp = keyboard.nextInt(); System.out.print(Completed Passes: ); c = keyboard.nextInt(); System.out.print(First-Downs: ); fd = keyboard.nextInt(); System.out.print(Time Sacked: ); s = keyboard.nextInt(); System.out.print(Thrown Interceptions: ); i = keyboard.nextInt(); Player give = new QuaterBack(name, a, td, lp, c, fd, s, i); current[j] = give; } public static void newR (Player[] current, int j) { Scanner keyboard = new Scanner(System.in); int a, td,c, fd; double yR, rE, lp; String name; System.out.print(\nReceiver Stats:\nAll numbers are based by Foot(ft.)\n); System.out.print(\nName: ); name = keyboard.nextLine(); System.out.print(Age: ); a = keyboard.nextInt(); System.out.print(Touch-Downs: ); td = keyboard.nextInt(); System.out.print(Longest Pass Caught: ); lp = keyboard.nextDouble(); System.out.print(Completed Catches: ); c = keyboard.nextInt(); System.out.print(First Downs: ); fd = keyboard.nextInt(); System.out.print(Rushing Yards: ); yR = keyboard.nextDouble(); System.out.print(Receiving Yards: ); rE = keyboard.nextDouble(); Player give = new Receiver(name, a, td, lp, c, fd, yR, rE); current[j] = give; } public static void newD (Player[] current, int j) { Scanner keyboard = new Scanner(System.in); int a, td, pDef, tack, sack, inte, rFum; String name; System.out.print(\nDefensive Stats:\nAll numbers are based by Foot(ft.)\n); System.out.print(\nName: ); name = keyboard.nextLine(); System.out.print(Age: ); a = keyboard.nextInt(); System.out.print(Deflected Passes: ); pDef = keyboard.nextInt(); System.out.print(Invidiual Tackles: ); tack = keyboard.nextInt(); System.out.print(Quaterback Sacks: ); sack = keyboard.nextInt(); System.out.print(Interceptions: ); inte = keyboard.nextInt(); System.out.print(Recovered Fumbles: ); rFum = keyboard.nextInt(); Player give = new Defensive(name, a, pDef, tack, sack, inte, rFum); current[j] = give; } public static void pFile(Player[] current, int j) { try { File file = new File(players.txt); PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(file))); for (int k = 0; k < j; k++) { output.println(\n*****************************\n); output.println(* + current[k].getType() + *); output.println(\n*****************************); output.println(current[k].toString()); } output.close(); } catch ( IOException e ) { e.printStackTrace(); } } public static void pScreen(Player[] current, int j) { for (int k = 0; k < j; k++) { System.out.print(\n*****************************\n); System.out.print(* + current[k].getType() + *); System.out.print(\n*****************************); System.out.print(current[k].toString()); } } public static void sortByName(Player current[], int holds) throws IOException { boolean swap; // boolean for controlling our loop of sorting Player temp; // A temp Fan.class reference for filling our Array // A counter for index of elements in our Arra do { swap = false; // set swap to false awaiting a possible swap for(int k = 0; k < holds -1; k++) // looping as many times of fans we have { if (current[k+1] == null || current[k] == null); // An if statment that helps catch accidental nulls else if ((current[k].getName())pareTo(current[k+1].getName()) > 0) // An if statment that compares each name { // with the next element in the fan Array temp = current[k]; // Copying current element to a temp object current[k] = current[k+1]; // Making current element the greater valued name current[k+1] = temp; // Setting the Copy to the next element swap = true; // Setting swap to true to restart the loop } } } while (swap); // Test to see if any swaps were made } public static void sortByAge(Player current[], int holds) throws IOException { boolean swap; // boolean for controlling our loop of sorting Player temp; // A temp Fan.class reference for filling our Array // A counter for index of elements in our Arra do { swap = false; // set swap to false awaiting a possible swap for(int k = 0; k < holds -1; k++) // looping as many times of fans we have { if (current[k+1] == null || current[k] == null); // An if statment that helps catch accidental nulls else if ((current[k].getAge()) > (current[k+1].getAge())) // An if statment that compares each name { // with the next element in the fan Array temp = current[k]; // Copying current element to a temp object current[k] = current[k+1]; // Making current element the greater valued name current[k+1] = temp; // Setting the Copy to the next element swap = true; // Setting swap to true to restart the loop } } } while (swap); } public static void searchByAge(Player[] current, int j) { Scanner keyboard = new Scanner(System.in); int findAge, currentAge; do { boolean found = false; System.out.print(\nAge to find to quit>:); findAge = keyboard.nextInt(); for (int k = 0;k < j; k++) { currentAge = current[k].getAge(); if (currentAge == findAge) { System.out.print(\n*****************************\n); System.out.print(* + current[k].getType() + *); System.out.print(\n*****************************); System.out.println(current[k].toString()); found = true; } } if (found != true && findAge != 0) { System.out.print(No Players found for the age + findAge + \n); } } while (findAge != 0); } }
Posted on: Thu, 25 Sep 2014 02:04:12 +0000

Trending Topics



Recently Viewed Topics




© 2015