Results 1 to 2 of 2
- 03-27-2012, 12:57 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 5
- Rep Power
- 0
Need help passing Scanner objects into char arrays
Ok so I am doing this lab assignment in which I have to use arrays to process input from a file and display results. The code for the main program was already provided by my instructor and this is it right here:
Alright so I am going to have to write a class with two fields that both reference Char arrays but just how do I pass the data from the Scanner objects into char arrays? So far this is what I have. The "int questions" receives the total size of both arrays.Java Code:import java.util.Scanner; import java.io.*; import DriverExam.DriverExam; public class Chapter7ALabDemo { public static void main (String [] args) throws IOException { File file; Scanner readKey; Scanner readAnswers; String str; int numQuestions; DriverExam student; int [] missedQuestions; Scanner keyboard = new Scanner(System.in); System.out.println("Enter the name of the file that is the test key "); str = keyboard.nextLine(); file = new File(str); readKey = new Scanner(file); System.out.println("Enter the name of the file with the student answers."); str = keyboard.nextLine(); file = new File(str); readAnswers = new Scanner(file); System.out.println("How many test questions are there?"); numQuestions = keyboard.nextInt(); student = new DriverExam(readKey, readAnswers, numQuestions); missedQuestions = student.questionsMissed(); System.out.println(student); if (student.passed()) System.out.println("The student passed."); else System.out.println("The student did not pass."); System.out.println("The student got " + student.totalCorrect() + " answers correct."); System.out.println("The student got " + student.totalIncorrect() + " answers incorrect."); System.out.println("The following questions were missed by the student: "); student.printMissed(missedQuestions); } }
Java Code://Mark Herrera package DriverExam; import java.util.Scanner; public class DriverExam { private char[] answerKey; private char[] studentAnswers; public DriverExam(Scanner rKey, Scanner rAnswers, int questions) { } }
- 03-27-2012, 02:28 AM #2
Re: Need help passing Scanner objects into char arrays
If the Scanner methods you are using read Strings, the contents of the Strings can be extracted to char arrays using String class methods.how do I pass the data from the Scanner objects into char arraysIf you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
passing objects w/RMI
By nicoeschpiko in forum Advanced JavaReplies: 5Last Post: 02-06-2011, 08:59 AM -
scanner objects with arrays again..
By nevermiind in forum New To JavaReplies: 18Last Post: 05-24-2010, 11:45 AM -
Comparing two Char arrays
By viperlasson in forum New To JavaReplies: 3Last Post: 01-30-2010, 08:05 AM -
Passing Objects
By Java_Developer in forum New To JavaReplies: 6Last Post: 10-29-2009, 01:32 PM -
MVC passing objects
By simo_mon in forum New To JavaReplies: 1Last Post: 07-17-2009, 06:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks