Sunday, April 19, 2009

Sports

http://www.eng.auburn.edu/~cross/comp1210/lab/projects/Project8.pdf

http://www.eng.auburn.edu/~cross/comp1210/lab/projects/Project9.pdf

import java.io.*;
import java.io.FileNotFoundException;
import java.util.*;
abstract class Competitor {
String name, birthplace, gender;
int age, bestfinish;

public Competitor(){
name = "";
birthplace = "";
gender = "";
age = 0;
bestfinish = 0;
}

public Competitor( String name, String birthplace, String gender, int age, int bestfinish ){

this.name = name;
this.birthplace = birthplace;
this.gender = gender;
this.age = age;
this.bestfinish = bestfinish;
}

public void ReadInputFromFile(Scanner scan){
name = scan.nextLine();
birthplace = scan.nextLine();
gender = scan.nextLine();
age = Integer.parseInt(scan.nextLine());
bestfinish = Integer.parseInt(scan.nextLine());
}

public String toString()
{
String result = "Name: " + name + "\n";
result += "Born in: " + birthplace + "\n";
result += "Gender: " + gender + "\n";
result += "Age: " + age + "\n";
result += "Best Competition Finish: " + bestfinish + "\n";

return result;
}
public static void main(String[] args) throws FileNotFoundException {
String inputFileName = args[0];
}
}

//** try {
//File inFile = new File(fileName);
//BufferedReader br = new BufferedReader(new InputStreamReader(
//new FileInputStream(inFile)));

//DataLine = br.readLine();
//br.close();
//}
//catch (FileNotFoundException ex) {
//return (null);
//}
//catch (IOException ex) {
//return (null);
//}
//return (DataLine);
//




5
1
John Smith
New York, NY
Male
16
4
3
638
12
yes
no
2
Pat Jones
Los Angeles, CA
Female
14
33
19
Washington High School
3
Gina Toms
Dallas, TX
Female
22
1
20 - 25
112
Discus
156.7
4
Logan James
Fort Worth, TX
Male
17
3
15 - 18
334
1500
00:04:22
5
6


import java.io.*;
import java.util.Scanner;

public final class Project8_Driver {
static int numCompetitors = 0;
String temp;

public static void main(String[] args) throws IOException,FileNotFoundException
{

String temp;
String inputFileName = args[0];

Competitor[] comp = new Competitor[20];

int choice = -1;

BufferedReader br = new BufferedReader(
new InputStreamReader(
new FileInputStream(inputFileName)));

temp = br.readLine();
choice = Integer.parseInt( temp );
menuSwitch( choice, comp );
menu();

while ((temp = br.readLine()) != null) {
choice = Integer.parseInt( temp );
menuSwitch( choice, comp );

}
}


public static void menuSwitch( int choice, Competitor[] comp ) throws FileNotFoundException
{
File file = new File("P8input.txt");
Scanner scan = new Scanner(file);
scan.nextLine();
scan.nextLine();
switch( choice )
{

case 1:
//add Stacker
comp[numCompetitors] = new Stacker();
Stacker stk = new Stacker();
stk.ReadInputFromFile(scan);
stk.toString();
System.out.print(stk.toString());
numCompetitors++;
break;

case 2:
//add Speller
comp[numCompetitors] = new Speller();
Speller spl = new Speller();
spl.toString();
System.out.print(spl.toString());
numCompetitors++;
break;

case 3:
//add Thrower
comp[numCompetitors] = new Thrower();
Thrower thr = new Thrower();
thr.toString();
System.out.print(thr.toString());
numCompetitors++;
break;

case 4:
//add Runner
comp[numCompetitors] = new Runner();
Runner run = new Runner();
run.toString();
System.out.print(run.toString());
numCompetitors++;
break;

case 5:
//print out Competitors Info
System.out.println("(Option 5) - Print Competitor Information");
System.out.println("Competitors");
System.out.println("*************");
for(int i = 0; i < numCompetitors; i++)
System.out.println("\n" + comp[ i ]);

break;

case 6:
System.out.println("Goodbye.");
break;
}
}

public static void menu()
{
System.out.println("*************");
System.out.println("(Option 1) - Create new Sport Stacker\n");
System.out.println("(Option 2) - Create new Speller\n");
System.out.println("(Option 3) - Create new Thrower\n");
System.out.println("(Option 4) - Create new Runner\n");
System.out.println("(Option 5) - Print Competitor Information");
System.out.println("Competitors");
System.out.println("*************");

}

}


import java.text.DateFormat;
import java.util.Date;
import java.sql.Time;
import java.util.Scanner;
class Runner extends TrackAthlete {
int primaryeventdistance;
Time besteventtime;

public Runner(){
primaryeventdistance = 0;
}

public Runner( String name, String birthplace, String gender, int age, int bestfinish, int bibnum, String agegroup, int primaryeventdistance, Time besteventtime )
{
super(name,birthplace,gender,age,bestfinish,bibnum,agegroup);
this.primaryeventdistance = primaryeventdistance;
this.besteventtime = besteventtime;
}
public String toString(){
String result = "Type: Runner\n";
result += super.toString();
result += "Primary Event Distance: " + primaryeventdistance + "\n";
result += "Best Time: " + besteventtime + "\n";
return result;
}
public void ReadFromInputFile(){
//ValueOf(besteventtime);
}
}



import java.util.Scanner;
class Speller extends Competitor {
int spellerregnum;
String school;

public Speller()
{
spellerregnum = 0;
school = "";
}

public Speller( String name, String birthplace, String gender, int age, int bestfinish, int stackerregnum, String school )
{
super(name,birthplace,gender,age,bestfinish);
this.spellerregnum = spellerregnum;
this.school = school;
}

public void ReadInputFromFile() {


}

public String toString(){
String result = "Type: Speller\n";
result += super.toString();
result += "Region: " + spellerregnum + "\n";
result += "School: " + school + "\n";
return result;
}
}


import java.util.Scanner;
class Stacker extends Competitor {
int stackerregnum, stackerID, stackernumtimes;
boolean event333,event363;
String event333line,event363line;

public Stacker()
{
stackerregnum = 0;
stackerID = 0;
stackernumtimes = 0;
event333 = false;
event363 = false;
}

public Stacker( String name, String birthplace, String gender, int age, int bestfinish, int stackerregnum, boolean event333, boolean event363, int stackerID, int stackernumtimes )
{
super(name,birthplace,gender,age,bestfinish);
this.stackerregnum = stackerregnum;
this.event333 = event333;
this.event363 = event363;
this.stackerID = stackerID;
this.stackernumtimes = stackernumtimes;
}

public String toString(){
String result = "Type: Sport Stacker\n";
result += super.toString();
result += "ID: " + stackerID + "\n";
result += "Times: " + stackernumtimes + "\n";
result += "Region: " + stackerregnum + "\n";
result += "Event 3-3-3: " + event333 + "\n";
result += "Event 3-6-3: " + event363 + "\n";
return result;
}
public void ReadInputFromFile(Scanner scan) {
super.ReadInputFromFile(scan);
stackernumtimes = Integer.parseInt(scan.nextLine());
stackerID = Integer.parseInt(scan.nextLine());
stackerregnum = Integer.parseInt(scan.nextLine());
event333line = scan.nextLine();
if (event333line == "yes") {
event333 = true;}

}

}


import java.util.Scanner;
class Thrower extends TrackAthlete {
String primaryevent;
int bestdistance;

public Thrower()
{
primaryevent = "";
bestdistance = 0;
}

public void ReadInputFromFile() {


}

public Thrower( String name, String birthplace, String gender, int age, int bestfinish, int bibnum, String agegroup, int bestdistance, String primaryevent )
{
super(name,birthplace,gender,age,bestfinish,bibnum,agegroup);
this.primaryevent = primaryevent;
this.bestdistance = bestdistance;
}
public String toString(){
String result = "Type: Thrower\n";
result += super.toString();
result += "Primary Throwing Event: " + primaryevent + "\n";
result += "Best Distance: " + bestdistance + "\n";
return result;
}

}


import java.util.Scanner;
class TrackAthlete extends Competitor {
int bibnum;
String agegroup;

public TrackAthlete()
{
bibnum = 0;
agegroup = "";
}

public TrackAthlete( String name, String birthplace, String gender, int age, int bestfinish, int bibnum, String agegroup )
{
super(name,birthplace,gender,age,bestfinish);
this.bibnum = bibnum;
this.agegroup = agegroup;
}

public void ReadInputFromFile() {


}

public String toString(){
String result = super.toString();
result += "Age Group: " + agegroup + "\n";
result += "Bib Number: " + bibnum + "\n";
return result;
}
}

No comments:

Post a Comment