WE HAVE MOVED : SG-GAMING.NET
WE HAVE MOVED TO SG-Gaming.net!

<meta HTTP-EQUIV="REFRESH" content="0; url=http://sg-gaming.net">
WE HAVE MOVED : SG-GAMING.NET
WE HAVE MOVED TO SG-Gaming.net!

<meta HTTP-EQUIV="REFRESH" content="0; url=http://sg-gaming.net">
WE HAVE MOVED : SG-GAMING.NET
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeLatest imagesSearchRegisterLog in

 

 Computer Science help

Go down 
3 posters
AuthorMessage
superh20man
Server Moderator
Server Moderator
superh20man


In-Game Name : superh20man
Posts : 73
Points : 96
Join date : 2011-07-30
Age : 28
Location : United States, Texas

Computer Science help Empty
PostSubject: Computer Science help   Computer Science help I_icon_minitimeWed Jan 18, 2012 8:12 pm

Can someone help me with my computer science homework. It is in java and i am supposed to find the batting average of a baseball player

Here is the assignment:

A batter in baseball makes one or more plate appearances. In this problem, there are only six different outcomes of a plate appearance: a single(S), Double(D), triple(T), home run(H),out(O),or a walk(W). All of these plate appearances, except a walk or an out, are considered hit. A player's batting average is the number of hits divided by the number of at-bats, rounded to three decimal places, You are to write a program that computes a player's batting average.

Input Format: the first line in the data file indicates the number of data sets. The data set will be on one line and contain no less than one and no more than ten plate appearances.

Here is how the Data file I have to read it from looks
5
HOOWTDSOHW
WWW
WWOOWWWOO
OOSWHHDO
OO

Nevermind I figured it out, my hits and out were ints instead of doubles so it wouldn't average out right. Here is my new code:

PS. It doesnt let me post the for loops right



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

public class BattingAverage {


public BattingAverage() {

}


public static void main(String[] args) throws IOException{
Scanner infile = new Scanner (new File("C:\\CSA\\BattingAverage.txt"));
String at_bat="";
double avg=0.0;
String possibilities="SDTHOW";
char S=possibilities.charAt(0);
char D=possibilities.charAt(1);
char T=possibilities.charAt(2);
char H=possibilities.charAt(3);
char O=possibilities.charAt(4);
char W=possibilities.charAt(5);
double hits=0; //S D T H
double out=0;

BattingAverage ex= new BattingAverage();
int num_batters=infile.nextInt();
for(int batter=0;batter at_bat=infile.next();
hits=0;
out=0;
for(int plate_app =0; plate_app
char character=at_bat.charAt(plate_app);
if(character==S||character==D||character==T||character==H)
hits++;
else if(character==O)
out++;

}

int batternum=batter+1;
if(hits==0&&out==0)
System.out.printf("Batter %d did not get an at bat\n", batternum);
else{
avg=hits/(hits+out);
System.out.printf("Batter %d had a %.3f batting average\n", batternum,avg);
}

}
}
}


Last edited by superh20man on Thu Jan 19, 2012 7:31 pm; edited 1 time in total (Reason for editing : Problem Solved)
Back to top Go down
spaghettiboy200
Server Moderator
Server Moderator



Posts : 569
Points : 685
Join date : 2011-07-22
Age : 25
Location : Rhode Island, USA

Computer Science help Empty
PostSubject: Re: Computer Science help   Computer Science help I_icon_minitimeWed Jan 18, 2012 8:58 pm

that is computer science? O.o looks moar like a video game program thingy...you know, the code it uses?
Back to top Go down
superh20man
Server Moderator
Server Moderator
superh20man


In-Game Name : superh20man
Posts : 73
Points : 96
Join date : 2011-07-30
Age : 28
Location : United States, Texas

Computer Science help Empty
PostSubject: Re: Computer Science help   Computer Science help I_icon_minitimeWed Jan 18, 2012 10:04 pm

spaghettiboy200 wrote:
that is computer science? O.o looks moar like a video game program thingy...you know, the code it uses?

My computer science class is mainly programming in java
Back to top Go down
spaghettiboy200
Server Moderator
Server Moderator



Posts : 569
Points : 685
Join date : 2011-07-22
Age : 25
Location : Rhode Island, USA

Computer Science help Empty
PostSubject: Re: Computer Science help   Computer Science help I_icon_minitimeThu Jan 19, 2012 12:08 am

you have to type this out yourself?
Back to top Go down
Dragonkin
First Time Gaming Moderator
First Time Gaming Moderator
Dragonkin


In-Game Name : Dragonkin
Posts : 513
Points : 594
Join date : 2011-06-24
Location : Soon to be Russia!

Computer Science help Empty
PostSubject: Re: Computer Science help   Computer Science help I_icon_minitimeThu Jan 19, 2012 4:24 am

Uh, we're working in Excel, sorry xD
Back to top Go down
spaghettiboy200
Server Moderator
Server Moderator



Posts : 569
Points : 685
Join date : 2011-07-22
Age : 25
Location : Rhode Island, USA

Computer Science help Empty
PostSubject: Re: Computer Science help   Computer Science help I_icon_minitimeThu Jan 19, 2012 7:45 am

are u talking to me?
I just decided...ill become a regular chef, not a videogame making one
Back to top Go down
superh20man
Server Moderator
Server Moderator
superh20man


In-Game Name : superh20man
Posts : 73
Points : 96
Join date : 2011-07-30
Age : 28
Location : United States, Texas

Computer Science help Empty
PostSubject: Re: Computer Science help   Computer Science help I_icon_minitimeThu Jan 19, 2012 6:30 pm

Never mind, I got it to work
Back to top Go down
spaghettiboy200
Server Moderator
Server Moderator



Posts : 569
Points : 685
Join date : 2011-07-22
Age : 25
Location : Rhode Island, USA

Computer Science help Empty
PostSubject: Re: Computer Science help   Computer Science help I_icon_minitimeFri Jan 20, 2012 8:30 pm

yay!
Back to top Go down
Sponsored content





Computer Science help Empty
PostSubject: Re: Computer Science help   Computer Science help I_icon_minitime

Back to top Go down
 
Computer Science help
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
WE HAVE MOVED : SG-GAMING.NET :: Global General :: Off Topic / Spam-
Jump to: