Can't get my file to read correctly.. keep getting mismatch error
below will be my code and the file it is supposed to read.. I can't get it to
work. It keeps giving me a mismatch error.
import java.util.*;
import java.io.*;
public class TestStudent{
public static void main(String[] args){
try {
Scanner s = new Scanner(new File("StudentGrades.txt"));
if(s.hasNext()){
String title = s.next(); //throws away the title line
s.useDelimiter("[,\\n+]");
while(s.hasNext()){
String name = s.next();
int id = s.nextInt();
double attGr = s.nextDouble();
double hwGr = s.nextDouble();
double e1Gr = s.nextDouble();
double e2Gr = s.nextDouble();
double fExGr = s.nextDouble();
System.out.println(name+attGr+hwGr+e1Gr+e2Gr+fExGr);
//Construct the Student object based on the above data
catch(Exception e){
System.out.println(e);
file:: Studentgrades.txt has this info in it
Name,id,attGr,HkGr,E1Gr,E2Gr,FExGr
Alex Smith,111111,75,80,75,78,73
Mary Alexander,222222,95,90,87,93,85
Johnson White,333333,80,80,75,67,73
Andrew Black,44444,95,85,86,93,95
Gary Shippment,55555,86,78,87,72,68
Walter Green,666666,67,90,90,95,85
Mario Winter,777777,95,90,95,87,92
Henry Summer,888888,87,100,85,83,72
Michel Spring,999999,56,100,75,78,85
April May,112222,40,85,65,55,65
May Spring,113333,25,65,50,45,50
Helen Hunter,114444,79,88,66,73,67
Ammy Gram,115555,87,90,90,87,95
Bill Bonnet,223333,95,100,95,82,95
Larry Smith,224444,100,87,73,80,76
Julia Winter,334444,35,75,55,63,70
Suzan Snow,335555,67,65,40,65,60
Gary Carpenter,336666,98,80,65,78,83
Last Not Least,337777,97,90,87,94,88
Hi,
forget my previous answer.
You have mistake in your pattern, so I do it by different way. Instead of doubles I put ints, because all your numbers are int. However you can put doubles there as well.
So the code:
import java.util.*;
import java.io.*;
public class TestStudent{
public static void main(String[] args){
try {
Scanner scanner = new Scanner(new File("StudentGrades.txt"));
if(scanner.hasNext()){
String title = scanner.next(); //throws away the title line
scanner.useDelimiter(System.getProperty("line.separator"));
while (scanner.hasNext()) {
parseLine(scanner.next());
catch(Exception e){
System.out.println(e);
private static void parseLine(String line) {
Scanner lineScanner = new Scanner(line);
lineScanner.useDelimiter(",");
String name = lineScanner.next();
int id = lineScanner.nextInt();
int attGr = lineScanner.nextInt();
int hwGr = lineScanner.nextInt();
int e1Gr = lineScanner.nextInt();
int e2Gr = lineScanner.nextInt();
int fExGr = lineScanner.nextInt();
System.out.println(name+attGr+hwGr+e1Gr+e2Gr+fExGr);
}L.P.
Similar Messages
-
having problems opening a pdf file with reader 10/11 get error msg cannot open close reader and try again any ideas
Hi George ,
Is it happening with all the PDF' or any specific one?
Could you please share the error message so that we can replicate at our end ?
Try repairing reader once and see if that fixes the issue.
Launch Reader>Navigate to Help>Repair Adobe Reader Installation
Regards
Sukrit Dhingra -
Why can't I move files in Reader.
When I scroll to find the folder to place the file in, reader shut down.
Get the update to Reader 11.2.1 in the App Store.
-
Just got an iPhone and can't get iTunes Match to connect. Keep getting a message that I'm not subscribed, but already did on my pc. Any ideas?
You must be signed into the mobile iTunes Store using the same Apple ID you used to originally purchase iTunes Match. On the iOS device go to Settings > iTunes and App Stores and tap the Apple ID. Log out, then log in with the correct ID.
-
I can´t rent movies on Apple TV I keep getting this message: Verification Required Before you can make purchases, you must go to the ITunes Store on your Computer and verify your payment information ? Done and still aren´t able to rent.
Hi.
You will need an iTunes acount !! then just log in to it and confirm your card payment details.
I've don the same think!! good luck! it works for me. -
MacBook Pro running 10.7.5. Can I u/g to Yosemite? I keep getting messages to do it but when I search for updates it is never offered
Click here, then on View in Mac App Store, and try downloading it. If you're told that it's incompatible, no.
(118792) -
I live in the Atlanta area. I use Internet Explorer and have Windows 7. I can't play You Tube videos. I keep getting this message: An error occurred, please try again later. Please help!
First, confirm that ActiveX Filtering is configured to allow Flash content:
https://forums.adobe.com/thread/867968
Internet Explorer 11 introduces a number of changes both to how the browser identifies itself to remote web servers, and to how it processes JavaScript intended to target behaviors specific to Internet Explorer. Unfortunately, this means that content on some sites will be broken until the content provider changes their site to conform to the new development approach required by modern versions of IE.
You can try to work around these issues by using Compatibility View:
http://windows.microsoft.com/en-us/internet-explorer/use-compatibility-view#ie=ie-11
If that is too inconvenient, using Google Chrome may be a preferable alternative. -
I am trying to convert a video clip, already in imovie so that I can slow down the clip speed, but I keep getting an error -34. Any ideas?
Thanks!Hi Russ,
Thanks for your response. I am not an experienced user of FC or other video editing software but if its that hit and miss I think I will go to the trouble of finding some better software - I have a busy enough life as is, I don;t want to get into second guessing what a software problem might be!
I have just successfully exported my video to a master file using one of the Apple codec options so it looks like it could be to do with the H.264 codec. I am wondering if Apples Compressor software would solve this problem - the only way to try this it to buy it, there is not trial for the compressor app. Any ideas?
Thanks
Gerry -
Trying to convert a word file to pdf and keep getting "An error occured while signing in"?
Trying to convert a word file to pdf and keep getting "An error occured while signing in"?
Or contact Adobe Customer Service via http://helpx.adobe.com/contact.html?product=export-pdf
-
Can not update or restore my ipod touch, keep getting the error message 13019
can not update or restore my ipod touch, keep getting the error message 13019
Start here:
iTunes: Error 13019 during sync -
I installed itunes and quick time but when I try to open itunes I get a message that reads "quicktime failed to initialize (error -2096). I have removed both itunes and quicktime from my computer and re-installed them and I still get the same message. What do I do to get itunes to work?
That one is often a compatibility mode problem. Try the following document, only be sure that none of the boxes in the compatibility mode tab are checked (not just the compatibility mode box itself):
iTunes for Windows: How to turn off Compatibility Mode -
What can I do to update iphoto app I keep getting this message:
'You cannot update this software since you have not owned the major version of this software?.Going from iPhoto v 8.x.x to V 9.x.x is called an upgrade and requires the purchase of iPhoto 9.
To go from v 8.1 to v 8.1.2 is an update and is free.
OT -
I have downloaded and installed the new ios7 software on my iphone 4s but im having trouble getting through the activation process i keep getting the message "iphone could not be activated because the activation server cannot be reached"? any suggestions?
The activation servers are probably overloaded with everyone trying to update to iOS 7 today. You might need to wait and try again later.
-
Hello, i am having problems getting face time to work, I keep getting an error message saying the server could not process the registration, I am using the username and password I always have and it has always worked in the past, any ideas?
We aren't Apple, just users like you volunteering to help other users with problems. Threatening to go to Samsung doesn't mean anything to us. What troubleshooting have you tried so far?
-
HELP, i am unable to get Facebook to run. I keep getting the following error: Error signing in, unable to communicate with server.
>tutorial on learning PE
Here are some links I've saved
Saving & Sharing http://forums.adobe.com/thread/1051093
Steve's Basic Training Tutorials... steps are the same for several versions
-http://forums.adobe.com/thread/537685
-v10 http://www.amazon.com/Muvipix-com-Guide-Premiere-Elements-Version/dp/1466286377/
-All http://www.amazon.com/Tricks-Adobe-Premiere-Elements-Muvipix-com/dp/1451529724/
-and http://forums.adobe.com/thread/498626
-and http://prodesigntools.com/five-hours-free-tutorials-photoshop-and-premiere-elements-7-and- 8.html
FAQ http://forums.adobe.com/community/premiere_elements/premiere_elements_faq
TIPS http://forums.adobe.com/community/premiere_elements/premiere_elements_tips
Another help site http://muvipix.com/ or http://muvipix.com/phpBB3/
User Guide PDF http://help.adobe.com/en_US/premiereelements/using/index.html
Right click PDF link in the upper right corner and select to save to your hard drive
-the page also has links to help pages for previous versions
Maybe you are looking for
-
hey guys... the specifictaion says when you define a class final, all methods are implicity final as well and they may be inlined. that's cool but why does the compiler explicit store the information into the class file that a method is final when th
-
Hi everyone, I am quite new to Web services and Jdeveloper in particular, but here is what Im trying to accomplish. I have created a Web Service Proxy using Jdeveloper 11g. I am trying to consume an external Service that is using SSL. I can see the W
-
Need to enter invoice and payment in the system after a manual check issued
Client Need to enter invoice and payment in the system after a manual check is issued for some urgent transactions. Please suggest few ways to do this .
-
I am asking you this because I did not find this problem in any of the other browsers I have (chrome, opera, ie, safari). I uploaded a simple html file to show this problem here: http://rvyu.com/mKLG Notice that if you don't change the language you h
-
Right click table cell selection
I'm making a GUI interface including a table. What I'd like to implement is ability to right click on the cell and open the options selection, similar as to when right click the icon on the desktop. Any ideas ?