java .csv file manipulation

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

34 Replies - 1387 Views - Last Post: 31 August 2018 - 06:03 AM Rate Topic: -----

#1 babzbkt   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 29-August 18

java .csv file manipulation

Posted 29 August 2018 - 05:50 AM

i have some marks for some students in my tutoring class...and also i'm trying to learn how to open and edit csv files as they're not like normal .txt files in Java so i thought this is the perfect opportunity.

i have a Students.csv file in this format:
132567  Amelia
123476  Charlie
123516  Emily
143456  George
123466  Harry
123457  Jack
125456  Joshua
132456  Lily
123456  Oliver
123459  Sophie
123486  Thomas
123518  William

The numbers are their student numbers followed by the students name.

and in a seperate .csv file i have their marks for modules alongside their student numbers in this format:

123456  51.2    57.3    68.2    72.1
123457  60.4    51.3    70       55
123459  45      60.1    62.7    43.2
123466  37.9    44      67.2    48.5
123476  52.7    78.2    73.3    69.8
123486  45.9    61.2    55.4    41.7
123516  61.2    66.4    72.3    57.8
123518  83.2    78.2    66.1    61.7
125456  69.8    60.3    72.1    64
132456  73.1    82.6    71.2    79.5
132567  56.3    48.8    45.7    61.2
143456  41.9    66.2    55.4    63.2


For each of the four modules, i want to create a new file that has all the students results in it. The names of these module report files can be anything for example IR101.txt, ..., IR104.txt. as i can change them later anyway.

i want the end result to be something like this:

Module: IR102
Mean: 62.88
00 -  39.9: 0
40 -  49.9: 2
50 -  59.9: 2
60 -  69.9: 5
70 - 100.0: 3
123466, Harry: 44.0
132567, Amelia: 48.8
123457, Jack: 51.3
123456, Oliver: 57.3
123459, Sophie: 60.1
125456, Joshua: 60.3
123486, Thomas: 61.2
143456, George: 66.2
123516, Emily: 66.4
123476, Charlie: 78.2
123518, William: 78.2
132456, Lily: 82.6


if anyone can do this for me then please do, and then i will contact you...i may have more jobs for you where i will pay you well in order to teach me or help me on a 1 on 1 basis more regularly.

Is This A Good Question/Topic? 1
  • +

Replies To: java .csv file manipulation

#2 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3580
  • View blog
  • Posts: 16,354
  • Joined: 20-September 08

Re: java .csv file manipulation

Posted 29 August 2018 - 05:53 AM

Quote

if anyone can do this for me then please do, and then i will contact you...i may have more jobs for you where i will pay you well in order to teach me or help me on a 1 on 1 basis more regularly.

Are you looking for tuition/mentoring during the task completion? If so, i can probably help. Please PM me
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2654
  • View blog
  • Posts: 10,590
  • Joined: 03-December 12

Re: java .csv file manipulation

Posted 29 August 2018 - 05:59 AM

I'm curious why you are using a file system. This screams database to me.
Was This Post Helpful? 0
  • +
  • -

#4 babzbkt   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 29-August 18

Re: java .csv file manipulation

Posted 29 August 2018 - 06:00 AM

View Postastonecipher, on 29 August 2018 - 05:59 AM, said:

I'm curious why you are using a file system. This screams database to me.


hi yes it would be much easier in php but my task is to do it in java.
Was This Post Helpful? 0
  • +
  • -

#5 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2654
  • View blog
  • Posts: 10,590
  • Joined: 03-December 12

Re: java .csv file manipulation

Posted 29 August 2018 - 06:02 AM

What does php have to do with anything? You do know that Java can connect to databases as well?
Was This Post Helpful? 1
  • +
  • -

#6 babzbkt   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 29-August 18

Re: java .csv file manipulation

Posted 29 August 2018 - 06:04 AM

View Postastonecipher, on 29 August 2018 - 06:02 AM, said:

What does php have to do with anything? You do know that Java can connect to databases as well?


i started learning java 2/3 weeks ago, i'm more used to working with PHP and python so the fact that i have to do this task in java just makes it that slightly more difficult.
Was This Post Helpful? 0
  • +
  • -

#7 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2654
  • View blog
  • Posts: 10,590
  • Joined: 03-December 12

Re: java .csv file manipulation

Posted 29 August 2018 - 06:16 AM

Okay, so this isn't a project to help you organize students, it's an assignment. Gotchya. However, asking for someone to do your homework is not the way to go about this.

What have you tried, considered, attempted so far?
Was This Post Helpful? 0
  • +
  • -

#8 babzbkt   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 29-August 18

Re: java .csv file manipulation

Posted 29 August 2018 - 06:36 AM

View Postastonecipher, on 29 August 2018 - 06:16 AM, said:

Okay, so this isn't a project to help you organize students, it's an assignment. Gotchya. However, asking for someone to do your homework is not the way to go about this.

What have you tried, considered, attempted so far?


public class Exercise5 {

    public static final String students_file = "C:/Users/Babz/Desktop/students.csv";
    public static final String marks_file = "marks.csv";
    public static final String DELIMITER = ",";
    public static void students() {
        Scanner input = null;
        try {
            input = new Scanner(new File(students_file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        String[] tmp = new String[14];

        while (input.hasNextLine()) {
            readRecord (input.nextLine());
        }
        input.close();

    }
    public static void readRecord(String line){
        String[] fields = line.split(DELIMITER);
     //   System.out.println(Arrays.toString(fields));
        String [] id = new String[15];
        String [] name = new String[15];
        for (int i = 0;i<fields.length;i++){
         name[i] = fields[1];
         

        System.out.println(Arrays.toString(name));
        }
    }


    public static void main(String[] args) {
    students();

    }
}



this is what i have so far, im trying to create two arrays, one with the student id and one with the student name, obviously its not working how im expecting it to work but as i type this im in the process of fixing it through trial and error
Was This Post Helpful? 0
  • +
  • -

#9 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2654
  • View blog
  • Posts: 10,590
  • Joined: 03-December 12

Re: java .csv file manipulation

Posted 29 August 2018 - 06:38 AM

Can you use other data structures? You are using Java, have you learned about classes and doing a Student class to hold the data rather than a multi faced parallel array?
Was This Post Helpful? 0
  • +
  • -

#10 babzbkt   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 29-August 18

Re: java .csv file manipulation

Posted 29 August 2018 - 06:40 AM

View Postastonecipher, on 29 August 2018 - 06:38 AM, said:

Can you use other data structures? You are using Java, have you learned about classes and doing a Student class to hold the data rather than a multi faced parallel array?


yes i have learnt about classes, i was actually getting to that but i felt like it would be easier to hold data in an array...maybe if you dont mind you could point me in the right direction on how to get started?
Was This Post Helpful? 0
  • +
  • -

#11 andrewsw   User is offline

  • Unprocessable Entity
  • member icon

Reputation: 6595
  • View blog
  • Posts: 26,834
  • Joined: 12-December 12

Re: java .csv file manipulation

Posted 29 August 2018 - 06:43 AM

You have identified the delimiter as a comma but your data files have no commas.
Was This Post Helpful? 0
  • +
  • -

#12 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 100
  • View blog
  • Posts: 710
  • Joined: 05-December 13

Re: java .csv file manipulation

Posted 29 August 2018 - 06:45 AM

You could use a stream reader, to read the csv file and iterate a loop through the results and feed it to an array and sort the values from there.
Was This Post Helpful? 0
  • +
  • -

#13 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2654
  • View blog
  • Posts: 10,590
  • Joined: 03-December 12

Re: java .csv file manipulation

Posted 29 August 2018 - 06:45 AM

Define your classes. What data does the class need to model? How many classes are needed to define a single student? Pattern it out for one and then it doesn’t matter how many students you need to go through.


Specifically, what data does the class need to hold to give you the data you are looking to obtain?
Was This Post Helpful? 0
  • +
  • -

#14 babzbkt   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 13
  • Joined: 29-August 18

Re: java .csv file manipulation

Posted 29 August 2018 - 06:49 AM

View Postastonecipher, on 29 August 2018 - 06:45 AM, said:

Define your classes. What data does the class need to model? How many classes are needed to define a single student? Pattern it out for one and then it doesn’t matter how many students you need to go through.


Specifically, what data does the class need to hold to give you the data you are looking to obtain?


for each student i'd need 6 classes if im correct:
NAME
ID
MOD1
MOD2
MOD3
MOD4

MOD1,MOD2,MOD3 and MOD4 are the results for each module
Was This Post Helpful? 0
  • +
  • -

#15 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 100
  • View blog
  • Posts: 710
  • Joined: 05-December 13

Re: java .csv file manipulation

Posted 29 August 2018 - 06:50 AM

That escalated quickly, 5 replies since writing that last post :omg:
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3