Sign in to follow this  
Followers 0

Java hw help please

7 posts in this topic

Posted

Need help writing a code that reads a file, gathers the tokens, and then gives the user back an awnser based on the information from the tokens. In this case the tokens are names and test scores and the out puts are names and final grades. They are to all be displayed at once and it does not have to use any popup windows. Below are the teachers hw asignment and a piece of program he gave us to get started with

[b]""Homework-2[/b]

You do not need to send me your input file. Your program should work with my input file named [b]hw2.txt[/b].
Write a java program [b]FirstnameLastnameHw2.java[/b] that reads student info from an external file with the following data, and displays the grades as displayed below.
Input file hw2.txt (be aware of copy/paste issue). Add a record with your own name (and some numbers).

Max Batman 73 83 93 20 20 20 18
Jim Harper 76 88 68 15 20 20 20
Joanna Karr 62 92 91 12 20 20 18
Sue Hammond 75 88 78 20 0 20 20
Mickie Foxx 65 77 91 12 0 0 20
Sue Sirmons 98 52 94 20 20 20 0
Jacqueline Savannah 98 87 99 0 20 20 20
your name . . . .

There are three test scores, out of 100 each, worth 60% and four homework scores, out of 20 each, worth 40% of grade.
Apply 90%, 80%, 70% and 60% (standard) cutoff levels for letter grade computation.

Example output (grades/averages are not accurate):

Student Names Average Letter Grades
--------------------------------------------
Batman, Max 87 B
Harper, Jim 73 C
Karr, Joanna 78 C
Hammond, Sue 82 B
Foxx, Mickie 53 F
Sirmons, Sue 93 A
Savannah, Jacqueline 94 A
Your name .. ..
--------------------------------------------""



[font="Courier New"][color="#941edf"][font="Courier New"][color="#941edf"]""import[/color][/font][/color][/font][font="Courier New"][color="#000000"] java.util.scanner;[/color][/font]
[font="Courier New"][color="#941edf"][font="Courier New"][color="#941edf"]import[/color][/font][/color][/font][font="Courier New"][color="#000000"] java.io.*;[/color][/font]

[font="Courier New"][color="#941edf"][font="Courier New"][color="#941edf"]public[/color][/font][/color][/font][font="Courier New"][color="#000000"] [/color][/font][font="Courier New"][color="#941edf"][font="Courier New"][color="#941edf"]class[/color][/font][/color][/font][font="Courier New"][color="#000000"] FileReader
{ [/color][/font][font="Courier New"][color="#941edf"][font="Courier New"][color="#941edf"]public[/color][/font][/color][/font][font="Courier New"][color="#000000"] [/color][/font][font="Courier New"][color="#941edf"][font="Courier New"][color="#941edf"]static[/color][/font][/color][/font][font="Courier New"][color="#000000"] [/color][/font][font="Courier New"][color="#941edf"][font="Courier New"][color="#941edf"]void[/color][/font][/color][/font][font="Courier New"][color="#000000"] main(String[] args) [/color][/font][font="Courier New"][color="#941edf"][font="Courier New"][color="#941edf"]throws[/color][/font][/color][/font][font="Courier New"][color="#000000"] Exception
{ File file1 = [/color][/font][font="Courier New"][color="#941edf"][font="Courier New"][color="#941edf"]new[/color][/font][/color][/font][font="Courier New"][color="#000000"] File([/color][/font][font="Courier New"][color="#00cb00"][font="Courier New"][color="#00cb00"]"hw2.txt"[/color][/font][/color][/font][font="Courier New"][color="#000000"]); [/color][/font][font="Courier New"][color="#fa6400"][font="Courier New"][color="#fa6400"]// finds file[/color][/font][/color][/font]
[font="Courier New"][color="#000000"]Scanner inFile = [/color][/font][font="Courier New"][color="#941edf"][font="Courier New"][color="#941edf"]new[/color][/font][/color][/font][font="Courier New"][color="#000000"] Scanner(file1); [/color][/font][font="Courier New"][color="#fa6400"][font="Courier New"][color="#fa6400"]// reads file[/color][/font][/color][/font]

[font="Courier New"][color="#941edf"][font="Courier New"][color="#941edf"]while[/color][/font][/color][/font][font="Courier New"][color="#000000"] (inFile.hasNext())
{ String line = inFile.nextLine();
System.out.println(line);
}



}
}""[/color][/font]

Share this post


Link to post
Share on other sites

Posted

how about you do your own homework?

If you have any specific problems with the concepts then feel free to ask about those here.... :-)

Share this post


Link to post
Share on other sites

Posted

Well ive been working on it all weekend but i cant seem to get it started. Thats really what i need help with is just geting started. Our teacher hasnt gone over using tokens yet which is making this very difficult

Share this post


Link to post
Share on other sites

Posted

http://lmgtfy.com/?q=tokenizing+a+string+with+java

Share this post


Link to post
Share on other sites

Posted

String has split method - so you can split the string at empty spaces " "
Integer class has parse to get the integer from a string

Share this post


Link to post
Share on other sites

Posted

Just read up on Java strings, for ex. [url="http://home.cogeco.ca/~ve3ll/jatutor7.htm"]this tutorial[/url].

Share this post


Link to post
Share on other sites

Posted

I would read each line and each line use split string each space. This will return an array with first name, last name and grades in their own spot. Array[0] is first name. Array[1] last name etc. Then you can call a for loop on that array from 2 to array. Length. Then grab each grade and use parse into to return the intended value of that string. Then average the grade.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.