Results 1 to 3 of 3

Thread: String things

  1. #1
    gquach is offline Member
    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Default String things

    i need help as well.

    how can you count the number of people having full marks out of 20 from each record line, from a given file?

    this is inputfile - the file from Scanner constructor:
    A A A A A A B A A A B C A A A A C B D A
    B D A A C A B A C D B C D A D C C B D A
    B D A A C A B A C D B C D A D C C B D A


    Java code:

    import java.io.*;
    import java.util.Scanner;
    import java.util.*;
    /*
    * Read char from file using DataInputStream | Java Examples - Java Program Sample Source Code
    */

    public class DriverExam {
    boolean passed; //passed if student passes exam
    int allRightQuestions=0; //counts number of people having full marks
    int lessThan5score=0; //counts number of people having < 5 scores
    int lessThan10Score=0; //counts number of people having < 10 scores
    int totalCorrect; //number of questions being answered correctly
    int totalIncorrect; //number of questions being answered wrongly
    int questionsMissed[][]; //array for storing the missed question numbers
    int row = 0;
    int column = 0;

    char[] trueanswers = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A'};
    String answers[] = { "B", "D", "A", "A", "C", "A", "B", "A", "C", "D", "B", "C", "D", "A", "D", "C", "C", "B", "D", "A"};//the exam solution
    String[] realanswers = new String[20];

    char[][] studentanswers = new char[30][20];//ignore
    String[][] pupilanswers = new String[30][20];


    public DriverExam(Scanner inputFile)
    {
    // TODO Auto-generated constructor stub
    Scanner file = inputFile;

    if ( pupilanswers.length < 30)
    while (file.hasNext() && row < pupilanswers.length )
    {
    for ( int i = 0; i < pupilanswers.length; i++)
    {
    pupilanswers[row][column] = file.nextLine();
    column++;
    }
    row++;
    getallRight();
    }

    }

    public void getallRight()
    {
    int startcolumn = 0;
    int beginrow = 0;
    do
    {
    if (pupilanswers[beginrow][startcolumn] == answers[startcolumn] )
    {
    passed = true;
    totalCorrect +=1;
    passNo();
    allRightQuestions +=1;
    }
    startcolumn++;
    if ( startcolumn == 20)
    {
    startcolumn = 0;
    beginrow++;
    }
    }
    while( row < pupilanswers.length && column < pupilanswers.length);
    getallright();//counts number of people having full marks
    }

    public int getallright()
    {
    return allRightQuestions;
    }

    public int passNo()
    {
    return totalCorrect;
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default Re: Help with string and array in java

    Do not hijack someone else's thread. Especially long dead ones.
    Create your own.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default Re: String things

    And now I've shifted this to its own thread (couldn't think of a meaningful title).

    When posting code please use [code] tags [/code] to retain formatting.
    Unformatted code is hard to read, and I'm sure you want to make this as easy for us as possible.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Fixes for things that bug me?
    By jhsachs in forum NetBeans
    Replies: 0
    Last Post: 09-18-2013, 06:14 PM
  2. String Method returning... odd things
    By whooplaah in forum New To Java
    Replies: 1
    Last Post: 07-23-2012, 08:02 AM
  3. XML, and other things.
    By Tortex in forum New To Java
    Replies: 5
    Last Post: 03-28-2010, 05:53 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
  •