Results 1 to 3 of 3

Thread: difficulty

  1. #1
    Daniela_v is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default difficulty

    hey guys. I created this code and it's really messy.


    /**
    * enterstudentdetails
    */
    import java.util.*;
    public class function1
    {
    int X;
    int function;

    String desiredChoice= "Unknown";

    public function1() {
    Scanner keyboard= new Scanner(System.in);
    if(function==1){


    String[] marks;
    marks=new String[3];

    marks[1]="Maths";
    marks[2]="Physics";
    marks[3]="Computing";

    int MAX_NO_OF_STUD=1000;
    int N;
    String name;
    int studNo;

    System.out.print("Type the number of students you want to input");
    studNo=keyboard.nextInt();
    marks=new int[studNo];


    for(N=1;N<=studNo;N++){
    grade(N);

    System.out.println("Enter name for student number" +N+ ":" );
    name=keyboard.nextInt();
    System.out.println("Enter form /1-5/ for student " +N+ "." +name+ ":" );
    form=keyboard.nextDouble();

    System.out.println("Enter group /A-D/ for student " +N+ "." +name+ ":");
    group=keyboard.nextChar();
    System.out.println("Enter mark for maths for student" +N+ "." +name+ ":" );
    mark[1]=keyboard.nextDouble();
    System.out.println("Enter mark for physics for student" +N+ "." +name+ ":" );
    mark[2]=keyboard.nextDouble();
    System.out.println("Enter mark for computing for student" +N+ "." +name+ ":");
    }
    }



    After data is input, I need to find the highest mark for each subject (maths,physics and computing) in each individual group(A,B,C,D). I have really struggled a lot and yet can't see how to go about it. How can I link them so dat the marks correspond to each Form and Group :confused::confused:

  2. #2
    bumblyb33 is offline Member
    Join Date
    Feb 2009
    Posts
    9
    Rep Power
    0

    Default

    You have all the code in the constructor. Make a new class with the main method and add all the grades from there. Plus you already initialized the marks array as type String, and you can't change it to type int. I advise you to make 3 arrays, 1 for each subject, then add the marks accordingly. Then loop through the array searching for the highest mark.

  3. #3
    Daniela_v is offline Member
    Join Date
    Mar 2009
    Posts
    5
    Rep Power
    0

    Default

    I understand. I'll try it out it seems simpler that way. I was searching on how to do 2 dimensional arrays but I find it too difficult for my level.

    Thanks for the help, much appreciated

Similar Threads

  1. Replies: 0
    Last Post: 01-03-2009, 10:00 AM
  2. Difficulty in finding the right algorithm
    By SolidCobra in forum New To Java
    Replies: 3
    Last Post: 10-05-2008, 11:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •