Get user input and find file and read it.....argh

Ok, so I have to write a program that asks a user for the name of the file they want opened and then it is to read it and then display the max score and the minimum score on the file. also to display the average score on the file. Along with that it is supposed to display how many As, Bs, Cs, Ds, and Fs were on the file IE: a: 1 b: 3 c: 0 d: 4 f: 1. etc.
Also, the next part is to have the program open the input file and then write all the information to an output file. I was able to do this and have the output file show the peoples names and their score along wtih their grade adn then the whole score average at the end of the output file....
My question is how do I do the first part by asking the user for the name of file and then for the program to find the file and then display the max, min, average and how many letter grades the class got?

this is what i have so far and the code before didnt work with JCreator, came up with lots of errors......
What do i have to do to get the max value and min value to display along with the amount of As, Bs, Cs, Ds, and Fs????
import java.io.*;
class extest
public static void main(String [] args) throws IOException
// First, open the input file
TextReader filein = new TextReader(new FileInputStream("test.txt"));
// Read our number
int x;
x = filein.readInt();
String [] first=new String[x];
String [] last=new String[x];
int [] score=new int[x];
// load data from the input file test1.txt
for (int i=0; i<x; i++)
first=filein.readWord();
last[i]=filein.readWord();
score[i]=filein.readInt();
     WriteTestFile(first, last, score, x);
public static void WriteTestFile(String f[], String last[], int score[], int x)
double average=0;
// Next, open the output file
try
PrintWriter fileout = new PrintWriter(
new FileWriter("grade.txt") );
// OK, now write to the file
fileout.println(x);
for (int i=0; i<x; i++)
average=average+score[i];
if (score[i]>90)
fileout.println(f[i]+" "+last[i]+" " + score[i] +": "+"A");
else if (score[i]>80)
fileout.println(f[i]+" "+last[i]+ " " + score[i] + ": "+"B");
else if (score[i]>70)
fileout.println(f[i]+" "+last[i]+ " " +score[i] + ": "+"C");
else if (score[i]>60)
fileout.println(f[i]+" "+last[i]+ " " +score[i] + ": "+"D");
else
fileout.println(f[i]+" "+last[i]+" " +score[i] + ": "+"F");
fileout.println("The average score of the class is "+average/x);
// we're done with the output file
fileout.close();
catch (IOException e)
throw new RuntimeException(e.toString());
System.out.println("***** Welcome to the Grade Program! *****");
     System.out.println("");
     System.out.println("Please enter the name of the file you want to open: ");
     TextReader input = new TextReader(System.in);
     String fileName = input.readLine();
System.out.println("The average of the scores is: "+average/x);
System.out.println("The maximum score is: ");
System.out.println("The minimum score is: ");
System.out.println("Number of scores by letter grade:");
System.out.println("A: ");
System.out.println("B: ");
System.out.println("C: ");
System.out.println("D: ");
System.out.println("F: ");

Similar Messages

  • How get output generated as csv file  by reading  by buffered reader and wr

    how get output generated as csv file by reading by buffered reader and writer

    String file_location = "C\temp\csv.txt");
    try {
         URL fileURL = getClass().getResource(file_location);
         if (fileURL != null){
              BufferedReader br = new BufferedReader(new InputStreamReader(fileURL.openStream()));
              String s = br.readLine();
              while (s != null)  {
                   if (!s.equals ("")) {
                        System.out.println(s);
                   s = br.readLine();
              br.close();
         else {
              // error
    catch (IOException ex){ex.printStackTrace();}rykk
    Message was edited by: a dummy
    rykk.

  • How to compare user input and database data?

    hi, I am new to JAVA, i hope i didnt post wrong forum :P
    I would like to know how to get user data input from web page(client side) and compare with the data in database (server side)?
    What i doiong is using the JavaScript to get the user input and compare with the JSP. but this way it seem like not a good way! Because i facing a lot of problem to get the user input!!
    Thx a lot!!
    function pasteData(obj){
              var em_num_select = obj;
         //document.write(em_num_select);
              <%
                SQLSelectNO = "SELECT em_num FROM emmast ";
                   try {
                        getEmpNo = db.execSQL(SQLSelectNO);
                   }catch(SQLException e){
                        System.err.println("Query Error!!");
                   while(getEmpNo.next()){
                        matchEmpNo = getEmpNo.getString("em_num");
                        %>if (em_num_select == '<%=matchEmpNo%>'){
                        <%
                                  String SQLgetAllInfo = "SELECT em_num, em_name, em_init, "+
                                                                                         "em_buyer_flag, em_dsgn_cde, em_proj_all, "+
                                                                                         "em_proj_cde1, em_proj_cde2, em_proj_cde3 "+
                                                                                         "FROM emmast "+
                                                                                         "WHERE em_num = '"+matchEmpNo+"' ";
                                  try{
                                       getAllInfo = db.execSQL(SQLgetAllInfo);
                                  }catch(SQLException e){
                                       System.err.println("Query Error");
                                  while(getAllInfo.next()){%>
                                       document.all.emp_name.value = '<%=getAllInfo.getString("em_num")%>'
                                       document.all.emp_init.value = '<%=getAllInfo.getString("em_name")%>'
                                       document.all.emp_disg.value = '<%=getAllInfo.getString("em_dsgn_cde")%>'
                                       document.all.emp_buyer_flg.value = "<%=getAllInfo.getString("em_buyer_flag")%>";
                                       document.all.emp_basis.value = "<%=getAllInfo.getString("em_proj_all")%>";<%System.out.println(getAllInfo.getString("em_proj_cde1"));%>
                                       document.all.emp_pro_cde1.value = "<%=getAllInfo.getString("em_proj_cde1")%>";
                                       document.all.emp_pro_cde2.value = "<%=getAllInfo.getString("em_proj_cde2")%>";
                                       document.all.emp_pro_cde3.value = "<%=getAllInfo.getString("em_proj_cde3")%>";
                             <%}%>
                             }//close if (em_num_select == '<%=matchEmpNo%>')
              <%}// close hile(getEmpNo.next())%>
         }// close function pasteData(obj)

    Hi,
    This forum is exclusively for Sun Java Studio Creator.
    You may need to post this question at:
    http://forum.java.sun.com/forum.jspa?forumID=45
    Thanks,
    Creator Team.

  • How to get user profiles and tasklists in axf

    Hi,
    We have configured the the views in the BPM Worklist ,restart all the managed servers like SOA Server,IPM Server and UCM Server.
    After that navigate to url-http://ipm:16000/imaging/faces/Driver.jspx to configure command driver input parameter settings-like SolutionNamespace     
    CommandNamespace     and provide the username.
    After clicking on Execute request it generates the conversation id but when we clicked on Execute Response button the AXF Task lists and user profile fields are empty.
    can anybody suggest the way to get user profiles and axf tasklist?
    Snehal

    Assign proper groups and/or users to BPM view created.
    In IPM login and logout for that user. It will start appearing.
    Regards,
    Vikrant Korde

  • Get User Names and Mail Ids present in Exchange Server

    Hello All,
    Can we get all the names and mail ids present in the exchange Server global address book?
    I tried one example but it is giving error.
    Exception in thread "main" javax.naming.CommunicationException: [LDAP: error
                code 2 - Protocol Error]; remaining name 's=satheesh'
    Code is given below:
    Hashtable env = new Hashtable(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL, "ldap://mailserver:389");
    DirContext ctx = new InitialDirContext(env);
    Attributes answer = ctx.getAttributes("s=satheesh");
    Any example code to get user names and mail ids will be helpful.
    Thanks in advance.
    Regards,
    Satheesh A
    [email protected]

    Hi Satheesh,
    I am new to LDAP. I am facing the exact same problem as you mentioned. Did you solve your problem?
    Thanks for any help you can provide.
    Hello All,
    Can we get all the names and mail ids present in the
    exchange Server global address book?
    I tried one example but it is giving error.
    Exception in thread "main"
    read "main" javax.naming.CommunicationException:
    [LDAP: error
    code 2 - Protocol Error]; remaining name
    aining name 's=satheesh'
    Code is given below:
    Hashtable env = new Hashtable(11);
    env.put(Context.INITIAL_CONTEXT_FACTORY,
    "com.sun.jndi.ldap.LdapCtxFactory");
    env.put(Context.PROVIDER_URL,
    "ldap://mailserver:389");
    DirContext ctx = new InitialDirContext(env);
    Attributes answer = ctx.getAttributes("s=satheesh");
    Any example code to get user names and mail ids will
    be helpful.
    Thanks in advance.
    Regards,
    Satheesh A
    [email protected]

  • I using new ipad 32gb and i cant get user name and password how i configure it ? please give me solution

    im using new ipad 32gb and i cant get user name and password how i configure it ? please give me solution

    What do you mean 'can't get user name and password' ? What are you trying to do with your iPad and what happens when you do it ?

  • I cannot get my bookmarks and reading lists to sync over my devices.  I've checked the iCloud settings on both devices and still nothing.  Using a retina iPad and a new mac book pro

    I cannot get my bookmarks and reading lists to sync over my devices.  I've checked the iCloud settings on both devices and still nothing.  Using a retina iPad and a new mac book pro

    Welcome to the Apple Community.
    In order to change your Apple ID or password for your iCloud account on your iOS device, you need to delete the account from your iOS device first, then add it back using your updated details. (Settings > iCloud, scroll down and hit "Delete Account")
    In order to change your Apple ID or password for your iTunes account on your iOS device, you need to sign out from your iOS device first, then sign back in using your updated details. (Settings > store, scroll down and tap your ID)

  • How to get user input to keep in array in the form of int[]?

    I really want to know how to get user input to keep in an array. Or if it's impossible, can i use the value in "int" and transfer it to an array?

    What I understand is that you want to set an input from the user in an array of int.
    Here is how it work:
    1. Create a stream and a buffer to get and store the informations entered by the user:
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    2. Set this input in a String:
    String input = stdin.readLine();
    3. Set this string in an int:
    int userInput = Integer.parseInt(input);
    4. Then you can put this int in the array.
    Warning this code throws IOExceptions and NumberFormatException ( when you try to set letters as int ). But you can catch them easily.

  • I get itunes can't find file when I tried to play a TV show I had purchased that was supposed to be in the cloud. There are several of these, including an entire season. In the store it shows that I purchased these shows when I checked them.

    I get itunes can't find file when I tried to play a TV show I had purchased. I then checked and had this problem with an entire TV season I had purchesed. The shows were supposed to be in the cloud. I went to the itunes store, went to the tv shows and they showed that I had purchesed them. They do not show up when I click on purchesed in the store.

    Try this...
    Empty/corrupt library after upgrade/crash
    Hopefully it's not been too long since you last upgraded iTunes, in fact if you get an empty/incomplete library immediately after upgrading then with the following steps you shouldn't lose a thing or need to do any further housekeeping. In the Previous iTunes Libraries folder should be a number of dated iTunes Library files. Take the most recent of these and copy it into the iTunes folder. Rename iTunes Library.itl as iTunes Library (Corrupt).itl and then rename the restored file as iTunes Library.itl. Start iTunes. Should all be good, bar any recent additions to or deletions from your library.
    See iTunes Folder Watch for a tool to catch up with any changes since the backup file was created.
    When you get it all working make a backup!
    tt2

  • Problems with getting user input

    Hi All,
    I want to get user input from a command line and i am NOT using a GUI.
    The user can still see their password when they are typing it in.
    Is there anyway to show '******' when they type in their password??
    This is what I have so far..
    public static void getPassword() {
    System.out.print("Enter password-->");
    DataInputStream input = new DataInputStream(System.in);
    try{  
    password = input.readLine();
    catch (IOException e){
    System.out.println("ERROR " + e);
    Any help would be greatly appreciated.
    Thanks
    Kal.

    Kal,
    I'm pretty sure you're going to need some kind of GUI (either a Java window or an HTML page) to get the desired effect. There might be a way to set the echo character in the command line, but I'm not sure.
    - Sheepy

  • How to get User input in JTextField?

    How to get User input in JTextField? Can u anyone give me some code samples? thanks

    read the API!!!

  • "catching" a prompt for user input and answering it through zenity?

    I'm trying to write a script (or multiple scripts) that will allow me to use command-line only applications via user defined actions in my file manager without having to open a terminal. Now I realize this basic functionality is already available, but as it stands I am unable to respond to command-line prompts for user input without opening a terminal. Is it possible to write a shell script that would act as a wrapper and allow me to use zenity (or another popup program) to respond to such queries?
    For example if I used a command-line program that prompted me for a password, could I "catch" that prompt with a shell script and answer it through another program, such as zenity?
    Last edited by falconheart (2011-01-16 22:37:25)

    The easier way to do this is to collect the info with zenity first, then pass it on the command line.  If the program insists on prompting, then you could try feeding it the info with redirection if it accepts it from stdin.  For example
    command < info.txt
    where info.txt is a temp file created by your script which contains whatever you want entered into the prompts.  This will work in some cases.

  • User inputs and simple anim.

    I know this is a bit basic, but I'm having trouble getting this animation to respond to user inputs. I want the circle to start near the centre of the screen and move up until it hits Y less than 10. Here, I've started the animation thread as a response to the user input, I know this probably isn't the best way to do it.
    import java.applet.Applet;
    import java.awt.Graphics;
    import java.awt.Color;
    import java.awt.*;
    import java.awt.event.*;
    public class basicAnimation extends Applet implements Runnable, KeyListener
    {Thread aThread;
            public int Y;
         public void start()
              if (aThread == null)
              {aThread = new Thread(this);
                   aThread.start();}
         public void stop()
              if (aThread != null)
              {aThread = null;}
         public void run()
              while (true)
                   for(Y=350; Y<10; Y--)
                   {repaint();
                        try { Thread.sleep(100); }
                        catch (InterruptedException e) { }}
         public void init()
         {Y=350;}
         public void paint(Graphics g)
         {g.fillOval (415, Y, 10, 10);}
       public void keyPressed(KeyEvent e)
           int keyCode = e.getKeyCode();
           switch(keyCode)
           {case KeyEvent.VK_SPACE:
                   aThread.start();
                 break;}
       public void keyTyped(KeyEvent e){}
       public void keyReleased(KeyEvent e){}
    }

    Sorry, now that I have gotten a better look at your run() method. You need to replace what you have with the code that I gave you in the previous post. If you run a for loop that is inside the thread, you will change Y from being at the center to Y == 10 in one thread iteration. This is much too fast for what you want to do.
    Don't forget that the thread is executing something like 1000 times every second (depending on how you set it up and the speed of your machine). So if you put a for loop inside the thread you are running the for loop about 1000 times a second when all you meant to do is run through one time.

  • Dealing w/ User Input and Multiple Objects

    I am trying to write a simple interface where a user inputs his/her name and id and then a Patron object is created based on their given input. I am having trouble when there are multiple patrons. My problem is referencing the different Patron objects with the different names and id's. I was wondering how I could maybe filter through the objects to retrieve the one that I want. He is some code.
    With this works for me because each object has a unique name:
    lib.addBook(book);
                        lib.addBook(book2);
                        lib.addPatron(patron);
                        lib.addPatron(patron2);
    This does not work though because each patron object being added has the same name:
    System.out.print("\nName: ");
                        name = br.readLine();
                        System.out.print("ID: ");
                        id = br.readLine();
                        pat = new Patron(name, id);
                        lib.addPatron(pat);
    If I did not explain my problem well please let me know. Thanks.

    Without any interface I can create my objects like this giving them all unique names, such as patron1, patron2, patron3, and so on.
              lib.addBook(book);
                        lib.addBook(book2);
                        lib.addPatron(patron);
                        lib.addPatron(patron2);
    With and interface I am having trouble finding a way to give each object a unique name. This is my code for adding a new patron to the Hashset.
    System.out.print("\nName: ");
                        name = br.readLine();
                        System.out.print("ID: ");
                        id = br.readLine();
                        pat = new Patron(name, id);
                        lib.addPatron(pat);
    How can I reference a specific object in the Hashset? This is my problem. Thanks.

  • How to take user input and place it in a variable

    All I want to know is how to copy user input from the message pop up and store in a local variable?
    Thanks.

    Hi
    Just take a look at thread's example
    http://forums.ni.com/t5/NI-TestStand/TestStand-Message-Popup/m-p/1792424/highlight/true#M35397
    The trick is done by Message-Popup PostExpression: Locals.strMyResponse = Step.Result.Response
    Hope this helps
    Juergen
    =s=i=g=n=a=t=u=r=e= Click on the Star and see what happens :-) =s=i=g=n=a=t=u=r=e=

Maybe you are looking for