Jump to content

Java Help!

GrayHD

Hey, so for school I have to make a program and I honestly have no idea where to start with this one... I would post what code I have so far but I'm really not sure how to do this. If someone could help me out and show me where to start or how to do this I would really appreciate it.

 

Here's the question:

 

Write WriteKONG a program that will read a file of 6 student records called marks.txt, which you must create yourself as shown below. Each student record consists of a student number (7 digits), a subject (for example "math") and an integer mark.

An example of two records would look like this:

2134523
Math
47

75676881
English
98

Your task is to read the file and create two files, one called pass.txt and the other fail.txt. Both output files should contain only subject and mark.

 

Thanks, and I understand you don't just wanna give me the answer but if you could just help me get started that would be nice.

Link to comment
Share on other sites

Link to post
Share on other sites

This might help you in reading in file http://www.homeandlearn.co.uk/java/read_a_textfile_in_java.html

Do a loop that read each line of the text

Since you already know the order of the data (student number, subject and mark), you can use mod 2 to record the subject and mod 3 to record the mark. If it's < 50 ( assuming 50 is passing) put it in the fail.txt. If its >=50 write it in pass.txt. You can use a data structure temporarily such as linked list or 2d arrays to store the results for pass and fail. Read those 2 linked list or array whichever you prefer and write it in the text file. Hope it helps.

Link to comment
Share on other sites

Link to post
Share on other sites


TextIO.readFile("marks.txt"); //reads from the file 

while (!TextIO.eof()){ //while not at end of the file

TextIO.getln(); //retrieves the next line of text

-do stuff-

}

PSU Tier List | CoC

Gaming Build | FreeNAS Server

Spoiler

i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core

Spoiler

FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210.

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Use one Scanner for reading and two more Scanners for writing pass and fail.txt, respectively.

Link to comment
Share on other sites

Link to post
Share on other sites

Write WriteKONG a program that will read a file of 6 student records called marks.txt, which you must create yourself as shown below. Each student record consists of a student number (7 digits), a subject (for example "math") and an integer mark.

An example of two records would look like this:

2134523

Math

47

75676881

English

98

Your task is to read the file and create two files, one called pass.txt and the other fail.txt. Both output files should contain only subject and mark.

 

So our raw data is thus *6:

2134523Math4775676881English98

I'm making the assumption that each data field (student number, subject & so fourth) are delimited by a return (a new line in the file). Also that we have a fixed 6 lines per record.

 

Our task is then to read this input file (parse it) and then to create two output files; one for passing marks and one for failing marks.

 

If I were to approach this myself I would have three file processors. One for parsing the input and two for writing the output. I would also create a POD for the input records BUT because this is so simple that may not be necessary. I would process the records as they are read in and not after the whole file has been parsed. This will likely show that you have thought about memory usage; i.e. we read a record, create our POD, make our decision based on the mark field and then write the output to the appropriate file.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

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

×