Project #1: Initial Requirements
Overview: This is the first project of four this semester. In this
project, we will write a small program that reads input from standard
input, parses it, calculates the mean of scores, and prints the results to
standard output.
Specification: We will read input from standard input with the following
format:
[last name], [first name], [middle initial].;[score1], [score2], ...
[score5]
An example of an input line would be:
Stevens, Frank, Z.; 87, 86.0, 92, 78.7, 86.3
You'll be required to read this line, parse it, and calculate the mean
test score. You will only need to process a single line of input for this
project. Each score can be a decimal value, not a simple integer. You'll
need to be able to handle only five of scores, currently. The output
format is:
[first name] [middle initial]. [last name], Mean: [mean value]; Scores:
[score1], [score2], ... [score5]
e.g.
Frank Z. Stevens, Mean: 86.0; Scores: 87, 86.0, 92, 78.7, 86.3
You'll need to be able to handle any name, but only five test scores. The
test scores will only have either no or a single significant digit
following the decimal point. You don't need to worry about error handling
at this point. If the input is incorrect, you don't need to handle the
condition at this point. I won't submit poorly formatted input to your
program in grading this project.
Here is what I have, my teacher is to educated and half of the class is
retaking the class because they did not pass last semester.
{code}
//-----------------------------------------------------------------------------
// project1mean.java
//
/*This program will parse a line of data
[last name], [first name], [middle initial].; [score1], [score2],
[score3], [score4], [score5]
then returns:
--------------------------------------
[first name] [middle initial]. [last name], Mean: [mean value]; Scores:
[score1], [score2], [score3], [score4], [score5]*/
//
//-----------------------------------------------------------------------------
public class project1mean
{
// parsing the data into a Number Block = nb ; and Grade Block =
gb
public static void main (String[] args)
{
String input =("Stevens, Frank, Z.; 87, 86.0, 92, 78.7,
86.3");
int count = 5;
double sum = (0);
double mean = (0);
Scanner s = new Scanner(input) .useDelimiter (";");
String nb = s.next();
String gb = s.next();
s.close();
Scanner sc = new Scanner(input) .useDelimiter (",");
String lstName = sc.next();
String firstName = sc.next();
String lastName = sc.next();
String middleInitial = sc.next();
double score1 = sc.nextInt();
double score2 = sc.nextInt();
double score3 = sc.nextInt();
double score4 = sc.nextInt();
double score5 = sc.nextInt();
sc.close();
sum = score1 + score2 + score3 + score4 + score5;
mean = sum / count;
System.out.print ("firstName ");
System.out.print ("middleInitial. ");
System.out.print ("lstName, ");
System.out.print ("Mean: ");
System.out.print (" + mean + ");
System.out.print ("Scores: ");
System.out.print (" + score1 + ");
System.out.print (" + score2 + ");
System.out.print (" + score3 + ");
System.out.print (" + score4 + ");
System.out.print (" + score5 + ");
}
}
Andrew Thompson - 20 Jun 2005 09:24 GMT
> Project #1: Initial Requirements
The initial requirements on c.l.j.help are that you do your
*own* *homework*!
Asking a single question about some aspect of the code is
generally OK, so why don't you come back when you
have a specific question about code?
But please research the answer first and show us ..
1) what you've tried,
2) describe what went wrong
3) describe your current understanding of the problem.

Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Matt Parker - 20 Jun 2005 13:16 GMT
>>Project #1: Initial Requirements
>
[quoted text clipped - 8 lines]
> 2) describe what went wrong
> 3) describe your current understanding of the problem.
Please, I'm a long time lurker here, and you are starting to get right
up my nose with your high and mighty postings. If you actually READ his
post you'll find that he DID post his code.
Most of your posts are criticisms of other posts rather than actually
helping. If you're not going to help, don't bother to post. Surely it's
that simple?
*Deity* help your work collegues...
Matt
Andrew Thompson - 20 Jun 2005 13:36 GMT
>>>Project #1: Initial Requirements
>>
>> The initial requirements on c.l.j.help are that you do your
>> *own* *homework*!
..
> Please, I'm a long time lurker here, and you are starting to get right
> up my nose with your high and mighty postings.
Poor thing.
>..If you actually READ his
> post you'll find that he DID post his code.
Oops! Yes you are correct. My bad.
> Most of your posts are criticisms of other posts rather than actually
> helping. If you're not going to help, don't bother to post. Surely it's
> that simple?
<please feel free to..>
Continue to lurk Matt, you can occasionally be of use.
</please feel free to..>

Signature
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Boudewijn Dijkstra - 20 Jun 2005 19:58 GMT
> [...]
>
[quoted text clipped - 4 lines]
> <please feel free to..>
> Continue to lurk Matt, you can occasionally be of use \
to the evil scheme that will grant world domination to Andrew Thompson?
> .
> </please feel free to..>
Patricia Shanahan - 20 Jun 2005 13:25 GMT
...
> Here is what I have, my teacher is to educated and half of the class is
> retaking the class because they did not pass last semester.
What happens when you try to compile and run your code?
> double score1 = sc.nextInt();
> double score2 = sc.nextInt();
> double score3 = sc.nextInt();
> double score4 = sc.nextInt();
> double score5 = sc.nextInt();
This looks wrong. Why are you asking your Scanner for an int, when you
want a double?
Patricia
bbyrd3663 - 20 Jun 2005 18:24 GMT
Here is what I got when compiled, and good point I did change the int to
nextDouble().
project1mean.java:16: cannot resolve symbol
symbol : class Scanner
location: package util
import java.util.Scanner;
^
project1mean.java:33: cannot resolve symbol
symbol : class Scanner
location: class project1mean
Scanner s = new Scanner(input) .useDelimiter (";");
^
project1mean.java:33: cannot resolve symbol
symbol : class Scanner
location: class project1mean
Scanner s = new Scanner(input) .useDelimiter (";");
^
project1mean.java:39: cannot resolve symbol
symbol : class Scanner
location: class project1mean
Scanner sc = new Scanner(input) .useDelimiter (",");
^
project1mean.java:39: cannot resolve symbol
symbol : class Scanner
location: class project1mean
Scanner sc = new Scanner(input) .useDelimiter (",");
Tor Iver Wilhelmsen - 20 Jun 2005 18:56 GMT
> project1mean.java:16: cannot resolve symbol
> symbol : class Scanner
> location: package util
> import java.util.Scanner;
> ^
That class was added in Java 1.5 - are you sure that's the compiler
version you use?
bbyrd3663 - 20 Jun 2005 18:25 GMT
Here is what I got when compiled, and good point I did change the int to
nextDouble().
project1mean.java:16: cannot resolve symbol
symbol : class Scanner
location: package util
import java.util.Scanner;
^
project1mean.java:33: cannot resolve symbol
symbol : class Scanner
location: class project1mean
Scanner s = new Scanner(input) .useDelimiter (";");
^
project1mean.java:33: cannot resolve symbol
symbol : class Scanner
location: class project1mean
Scanner s = new Scanner(input) .useDelimiter (";");
^
project1mean.java:39: cannot resolve symbol
symbol : class Scanner
location: class project1mean
Scanner sc = new Scanner(input) .useDelimiter (",");
^
project1mean.java:39: cannot resolve symbol
symbol : class Scanner
location: class project1mean
Scanner sc = new Scanner(input) .useDelimiter (",");