Program not outputting properly

Hey guys, I have this code that's supposed to take in 2 values per line from a file ( the first is a long, then a string stored in a class Student) and store them as a binary heap (a class I created and works properly), then print out the contents of the heap. Here is the code:
import java.util.Scanner;
public class ListPrinter
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        BinHeap<Student> heap = new BinHeap();
        System.out.println("Enter location of student records: ");
        Scanner fileScan = new Scanner(scan.nextLine());
        while(fileScan.hasNext()){
            if(fileScan.hasNextLong()){
                long id = fileScan.nextLong();
                if(id > 0){
                    if(!(scan.hasNextDouble())){
                        String name = fileScan.next();
                        heap.insert(new Student(id, name));
                else
                    fileScan.nextLine();
            else
                fileScan.nextLine();
        System.out.println("Sudent list:");
        int i=1;
        while(!(heap.isEmpty())){
            System.out.println(i + ". " + (heap.deleteMin()).toString());
            i++;
}Right now I'm inputting only correct values from a file. When run, the program displays:
cameron@cameron-laptop:~/Desktop/cpe103/project2$ java ListPrinter
Enter location of student records:
LPTest.txt
Sudent list:
cameron@cameron-laptop:~/Desktop/cpe103/project2$
There should be 2 student items printed, but there's nothing. Whats going on? Keep in mind that both classes BinHeap and Student are implemented correctly so I know the problem is not there. Thanks for any help!
Edited title by: sublimeph03nix on Apr 26, 2009 5:07 PM

I've tried taking in the line as a string and then parsing it, which seems to be simpler. However, now when I enter the loop, fileScan.nextLine() for some reason scans LPTest.txt as the value instead of what is in that .txt file.
Here's the new code with the test System.out.println()'s in it:
public class ListPrinter
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);      // scanner to read the filename
        BinHeap<Student> heap = new BinHeap();      // binary heap which stores student records
        System.out.println("New heap created"); // REMOVE -- TEST LINE
        System.out.println("Enter location of student records: ");
        String temp = scan.nextLine(); // REMOVE -- TEST LINE
        Scanner fileScan = new Scanner(temp);    // scanner to read the records in given file
        System.out.println("File to scan: " + temp); // REMOVE -- TEST LINE
        while(fileScan.hasNext()){
            System.out.println("Loop entered..."); // REMOVE -- TEST LINE
            String record = fileScan.nextLine();
            System.out.println("Scanned line..." + record); // REMOVE -- TEST LINE
            String[] split = record.split(" ");
            if(split.length == 2){
                try{
                    long id = Long.parseLong(split[0]);
                    System.out.println("Id scanned..." + id); // REMOVE -- TEST LINE
                    if(id > 0){
                        String name = split[1];
                        System.out.println("Name scanned..." + name); // REMOVE -- TEST LINE
                        heap.insert(new Student(id, name));
                        System.out.println("Student inserted..."); // REMOVE -- TEST LINE
                } catch(NumberFormatException e){
        System.out.println("Exited the loop..."); // REMOVE -- TEST LINE
        // prints the list of student records in ascending order
        System.out.println("Student list:");
        int i=1;
        while(!(heap.isEmpty())){
            System.out.println(i + ". " + (heap.deleteMin()).toString());
            i++;
}Also, here is a copy of the program run in the terminal:
cameron@cameron-laptop:~/Desktop/cpe103/project2$ java ListPrinter
New heap created
Enter location of student records:
LPTest.txt
File to scan: LPTest.txt
Loop entered...
Scanned line...LPTest.txt
Exited the loop...
Student list:
cameron@cameron-laptop:~/Desktop/cpe103/project2$
It's Student not Sudent...Thanks, I changed that.
Edited by: sublimeph03nix on Apr 26, 2009 7:27 PM

Similar Messages

  • Help T_T - Program not compiling properly

    I'm trying to add a short animation to the source file for a
    game that was built by an outside studio. Unfortunately, I can't
    seem to get the program to compile correctly: I get tons of errors,
    graphics dont diplay properly, etc. I thought perhaps I had just
    messed something up with my codes and animations, but even if i try
    to compile the original unedited file as a control test, i get the
    same problems. I have all the external files, scripts, etc.
    None of our scripters are in-house, so there's no one I can
    ask about this. I know just enough actionscript to prevent Flash
    from exploding into a gooey mass (which is how I ended up getting
    tasked with this), but basically my knowledge of flash is limited
    to it as an animation program so I'm not really sure if theres some
    kind of settings I need to change, specifically need to export as
    an .exe (shouldn't be, since the game runs as a .swf), or what.
    I know i'm not providing a whole lot of information about the
    problem, but thats because I'm not really sure what info is
    relevant. Let me know if there's anything people need from me and
    I'll get it to you.
    Thanks!

    Just a had brief look, but shouldn't it be:public class TempConversion extends JFrameIf you post code it is a good idea to use the formatting tags:
    http://forum.java.sun.com/help.jspa?sec=formatting
    Basically the idea is you put [code] at the start of your code and [/code]
    at the end.

  • Programs not quitting properly

    I'm not sure when this started: is it because of the last OS upgrade or is it something I've added? I don't know.
    I quit a program. I know I have quit because I have checked several times using Option+Cmd+Esc to see if it still needs quitting and all is OK, so I switch off. When I restart, the program restarts too - frequently before Finder has properly installed itself, which causes further problems.

    I have never seen or at least noticed a box like that. I had a look at Systems Preferences to see if there was anything there, but couldn't find anything.
    I shut down by pressing Shut Down from the Apple menu with Option pressed. My feeling is that it no longer shuts down properly - in other words, it's not making sure everything is off, but then I have already done that by inspecting Force Quit. It mainly happens with games, but not the same game and the other day it was QuickTime.

  • Program not installed properly???

    When opening QT 6.5.2 with win 98 i get...QTstreaming authoring failed to load because version of Qtstreaming and QT authoring do not match. I click ok, then get "QTstreaming extras failed to load because the versions of Qtstreaming and QT streaming extras do not match, click ok and then the player opens. Guided by an earlier recommendation, I clicked "update existing software" in the control panel and it said that the prog was not properly installed - reload. So I reloaded from the same install prog I downloaded from apple.com and still had the problem.
    What do i have to do to watch mov files????? Would it do any good to download 6.5.2 from the site again? Thanks

    I'd try removing QuickTime and go with a new installer.

  • Second display resolution not outputting properly

    I have two iMacs (details below) in my office with matching second monitors: LG Flatron W2252S
    -- a mid 2007 20" iMac Intel Core 2 Duo with Apple Mini DVI-VGA Adapter
    -- a late 2009 21.5" iMac Intel Core 2 Duo (Penryn) with Apple Mini DisplayPort to VGA Adapter
    On the older iMac I can run the LG monitor at a maximum resolution of *1680x1050 (60 Hz)*
    However, the newer iMac will only output at *1400x1050 (60 Hz*).
    It seems to have the option of 1600x1200 in System Preferences>Displays but if I select this output I get the message "Out of Range 74.7 kHz / 60 Hz"
    Is there any reason why the 2 monitors are acting differently? I've swapped them around a few times and the problem seems to lie with the iMac rather than the screens or cables
    Help! Please!
    Message was edited by: robbo™

    Hi Robbo, did this work?
    I have a very similar issue in that my Viewsonic sometimes is a VGA monitor in the prefferences and other times its VA2213. I'm not sure what the issue is but I can only use a VGA adaptor as there is no DVI port on the Viewsonic monitor. Sometimes my resolution is 1920x1080, other times its 1400x1050. I have a thread going, one person told me to switch on my second monitor first but that's not helping either.
    Fergul

  • Program not working properly.

    Hello all,
    The code below display a button and 3 option (radio) buttons. The program must uncheck the selected radio button when the button is clicked. Actually nothing happens in this code, that is the selected radio button has no change. Can anyone give a helping hand.
    regards,
    ==================
    import java.awt.*;
    import java.awt.event.*;
    public class CheckGroupDemo extends Frame {
         private CheckboxGroup cg;
         private Checkbox[] cb;
         private String[] cbLbl = { "Red", "Blue" ,"Green" };
         private Button cancel;
         public CheckGroupDemo () {
              super("Checkbox Group Demo");
              Panel p = new Panel();
              cg = new CheckboxGroup();
              p.setLayout(new GridLayout(3,1));
              cb = new Checkbox[cbLbl.length];
              for (int i=0; i<cbLbl.length; i++) {
                   cb[i] = new Checkbox(cbLbl,cg,false);
                   p.add(cb[i]);
              cancel = new Button("Clear All");
              cancel.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        for (int i=0; i<cbLbl.length; i++) {
                             if (cb[i].is)
                             cb[i].setCheckboxGroup(cg);
                             cb[i].setState(false);
              setLayout(new BorderLayout());
              add(cancel,"North");
              add(p,"Center");
              pack();
         public static void main(String[] a) {
              CheckGroupDemo app = new CheckGroupDemo();
              app.setVisible(true);
              app.addWindowListener(new WindowAdapter () {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);

    Hello, I have tried using JRadioButton objects,but when i click on the Cancel button the selected JRadioButton does not get deselected. please tell me what is wrong in my code?
    regards,
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class CheckGroupDemo extends JFrame {
         private ButtonGroup cg;
         private JRadioButton[] rb;
         private String[] cbLbl = { "Red", "Blue" ,"Green" };
         private JButton cancel;
         private JPanel p;
         public CheckGroupDemo () {
              super("Checkbox Group Demo");
              p = new JPanel();
              cg = new ButtonGroup();
              p.setLayout(new GridLayout(3,1));
              rb = new JRadioButton[cbLbl.length];
              for (int i=0; i<cbLbl.length; i++) {
                   rb[i] = new JRadioButton(cbLbl,false);
                   cg.add(rb[i]);
                   p.add(rb[i]);
              cancel = new JButton("Clear All");
              cancel.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        for (int i=0; i<cbLbl.length; i++) {
                             if (rb[i].isSelected())                          
                                  rb[i].setSelected(false);
                                  rb[i].repaint();
              setLayout(new BorderLayout());
              add(cancel,"North");
              add(p,"Center");
              pack();
         public static void main(String[] a) {
              CheckGroupDemo app = new CheckGroupDemo();
              app.setVisible(true);
              app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  • Apple + Tab between programs not working properly

    I've never had a problem with tabbing between programs until the past week. Specifically, it's tabbing from any program back to Firefox. I'm running OS X 10.4.11 on an iBook G4 and Firefox version 2.0.0.14. Basically, what is happening when I tab to Firefox is that Firefox becomes the active program (the program appears in the top bar) but the browser window doesn't show up. The only way I can get the window to show up is to open a new browser window followed by closing it (or by pressing F9 and selecting the window manually), then the original browser window becomes the active one. Has anyone ran into a similar problem? Or more importantly, does anyone have a solution?

    I can confirm it IS NOT the remote. We have 4 ATV G2 here and all the remotes work fine for three of the boxes. One box, even after factory reset, will not allow any of the remotes to scroll/select up direction in menus. Again- multiple remotes that work fine for other ATV boxes will not work in the up direction on a single ATV. Definitely a problem after latest update on at least some of the hardware!

  • Purchase Order History Program - not working properly

    Dear friends
    i am developing purchase order history program in ALV,
    which shows the report of purchase order status
    i.e (fields as below).
    document no
    PO date
    line item
    material number
    material name
    purchase org
    plant
    purchase group
    orderd quantity
    ordered amount
    delivered quantity
    delivered amount
    to be delivered quantity
    to be delivered amount
    invoice quantity
    invoice amount
    to be invoiced quantity
    to be invoiced amount
    how to test from me23n
    open me23n
    enter PO number
    press status tab
    you can get some fields for verification..
    the problem is
    i can get all the details correctly except delivered amount and to be delivered amount
    it works fine in both ( material purchase order and service purchase order )
    sometimes i am getting incorrect values in service purchase order specifically in delivered amount and to be delivered amount
    why i am getting these incorrect values ??
    only couple of POs generate these things.
    i am getting these values from EKBE table and using proper filtration like movement type and etc...
    if anyone can resolve ... would be appreciable
    avirat.

    Hi,
    for getting proper Po History you need to select PO's details from EKKO table and
    Header details from CHANGEDOCUMENT_READ_HEADERS based on the details got from this FM pass
    to the FM CHANGEDOCUMENT_READ_POSITIONS and get proper details.
    This is the logic used by the standard program also to get the PO History.
    Hope this helps.
    Regards
    Bikas

  • Why is my Acer "Ab Files" program not working properly when I download it to my Acer Aspire One?

    Hello there, Im having an issue with trying to download Acers Ab files that works with the apps for Iphone. When I do download it and I click on it, my screen goes black for a second and then everything on my screen gets huge like its in SAFE MODE. I've tried to uninstall it and it keeps doing the same darn thing. I've checked for recent updates for windows and spy and malware and any corrupt files using a program that detects and fixes them. It comes up clean. This program used to work on my computer and now it doesn't. So far, I think its the only one that works convienently using wireless, unless theres another app that does the same. Anyone have this problem? Thanks....

    Charliewhitepaw,
    When you say this program used to work on your computer, what has changed since then? Have you attempted to go back (system restore) to when it worked to see if that resolves the issue?

  • In XML Output the values of Number column tags are not displayed properly

    Hi,
    Our Client have been using AR Invoice Print Program for a long time and it is heavily customized. Also they are using an old version of the RDF. So we have taken the latest version of the RDF (RAXINV.rdf) for Oracle Apps 11.5.10.2 by raising a SR and implement Client's old RAXINV.rdf into it.
    All was ok, but when we are running the program, the XML Output did not generate properly. For the Q_INVOICE query (G_ORDER_BY, G_INVOICE and G_INV_TERM group), the value of some of the scaler number columns are not appeared properly. The tags are coming correctly, but the value is appearing as '*', instead of the correct value. We have checked in the RDF Level (By putting srw.message and check in the log file) that those columns are having proper value. So there is no issue with the RDF.
    But because of the above mentioned problem, the some of the PDF output field values also is not generated correctly.
    I think that because of the lexical parameters which was implementing the Q_INVOICE query (&COMMON_QUERY) this issue is coming. Because the issue is only in the Q_INVOICE query group (G_ORDER_BY, G_INVOICE and in G_INV_TERM group) not in any other query group.
    There is no problem with the scaler character columns. The issue is only with the number columns.
    Also we have checked that if we hardcode the value of the number columns in the above mentioned lexical parameter, this problem doesn't appear.
    If we put TO_CHAR function to those number columns in the lexical parameter (COMMON_QUERY), then this issue get solved. But we can't do it because of performance issue and also Client won't approve it.
    Please help.
    With Thanks and Regards

    I don't know how to read the code you pasted or I would have checked this myself.
    Do your fields in the internal table reference dictionary objects or elementary types? If not using dictionary types, the column names will be blank by default. If you can't change your fields to be dictionary types, you can try this to change the column names:
    I made a method inside my local class to add the names:
            call method set_colname
              EXPORTING iv_tab = alv_tab
                        iv_colid = 'xxxx'  "fieldname from the table
                        iv_stxt = text-t54
                        iv_mtxt = text-t55
                        iv_ltxt = text-t55.
    METHOD set_colname .
      data:
              alv_cols type REF TO cl_salv_columns_table,
              alv_col type REF TO cl_salv_column.
      TRY .
    *... Change fieldnames
            call METHOD iv_tab->get_columns RECEIVING value = alv_cols.
            call method alv_cols->get_column EXPORTING columnname = iv_colid RECEIVING value = alv_col.
            IF iv_stxt <> ''.
              CALL METHOD alv_col->set_short_text EXPORTING value = iv_stxt.
            ENDIF.
            IF iv_mtxt <> ''.
              CALL METHOD alv_col->set_medium_text EXPORTING value = iv_mtxt.
            ENDIF.
            IF iv_ltxt <> ''.
              CALL METHOD alv_col->set_long_text EXPORTING value = iv_ltxt.
            ENDIF.
       CATCH cx_salv_not_found.
      ENDTRY.
    ENDMETHOD. "set_colname

  • Billing output not processed properly

    when i applied output with output type (RD00) for invoice it is not activated properly. screen become blank.
    kindly help me.

    Dear Kiran,
    Please look in these areas
    Maintanance of the condition record in VV32 transaction
    Check the printer related settings.
    Check the transmision medum and partner function in the condition record.
    Make sure that output program and smart form or script program have been assigned to the output type RD00..
    And also chek is there any routine assigned in the requirement colomun of your output procedure control data.
    The invoice document has been released to accounting or not.
    I hope this will help you,
    Regards,
    Murali.

  • Background program is not working properly,when i am using job_open ,submit

    hai ,
    i am using job_open ,submit and job_close for scheduling one program background and use submit to another program ,all are working properly but it is working as a forground program not as abackground program. i want to work it as a background program.
    plz give a solution.

    Hi,
    Please find a sample program format for executing a submit program in background.
    DATA: number           TYPE tbtcjob-jobcount,
          name             TYPE tbtcjob-jobname VALUE 'JOB_TEST',
          print_parameters TYPE pri_params.
    CALL FUNCTION 'JOB_OPEN'
      EXPORTING
        jobname          = name
      IMPORTING
        jobcount         = number
      EXCEPTIONS
        cant_create_job  = 1
        invalid_job_data = 2
        jobname_missing  = 3
        OTHERS           = 4.
    IF sy-subrc = 0.
      SUBMIT submitable TO SAP-SPOOL
                        SPOOL PARAMETERS print_parameters
                        WITHOUT SPOOL DYNPRO
                        VIA JOB name NUMBER number
                        AND RETURN.
      IF sy-subrc = 0.
        CALL FUNCTION 'JOB_CLOSE'
          EXPORTING
            jobcount             = number
            jobname              = name
            strtimmed            = 'X'
          EXCEPTIONS
            cant_start_immediate = 1
            invalid_startdate    = 2
            jobname_missing      = 3
            job_close_failed     = 4
            job_nosteps          = 5
            job_notex            = 6
            lock_failed          = 7
            OTHERS               = 8.
        IF sy-subrc <> 0.
        ENDIF.
      ENDIF.
    ENDIF.
    Thanks & Regards,
    Harish

  • I have tried to update my itunes program. It was running great until I attempted the update now all I get is an error message that says "Itunes was not installed properly, Please reinstall itunes, Error 7 (Windows erroe 126)". What can I do to get my it

    I tried updating my itune program. Now all I get is the following message "Itunes was not installed properly. Please reinstall itunes. Error 7 (Windows error 126). WHAT can I do to get back to where my itunes program is running again?
    I have uninstalled the proram and tried reinstalling and get the same error message. The other error message I get is "The program can't start because MSVCR80.dll is missing from your computer. Try reinstalling the program to fix this problem".  I have tried that twice with no luck. Can someone help me get my music back???

    Go to Control Panel > Add or Remove Programs (Win XP) or Programs and Features (later)
    Remove all of these items in the following order:
    iTunes
    Apple Software Update
    Apple Mobile Device Support (if this won't uninstall move on to the next item)
    Bonjour
    Apple Application Support
    Reboot, download iTunes, then reinstall, either using an account with administrative rights, or right-clicking the downloaded installer and selecting Run as Administrator.
    The uninstall and reinstall process will preserve your iTunes library and settings, but ideally you would back up the library and your other important personal documents and data on a regular basis. See this user tip for a suggested technique.
    Please note:
    Some users may need to follow all the steps in whichever of the following support documents applies to their system. These include some additional manual file and folder deletions not mentioned above.
    HT1925: Removing and Reinstalling iTunes for Windows XP
    HT1923: Removing and reinstalling iTunes for Windows Vista, Windows 7, or Windows 8
    tt2

  • Satellite Pro U200: VGA output not working properly when AC adapter was connected

    Hi,
    I have a problem with vga output. When I'm working on battery and connect my notebook to external monitor it's ok, but when I connect AC adaptor then start waving also bluetooth and wlan does not work properly. In other case when I remove battery from notebook and connect AC adaptor it works properly.
    thanks in advance

    As long as you use a CRT you should set the refresh rate new, at least 85Hz. Standard is 60Hz as far as I know, and that hurts in your eyes.
    The wireless lan behaviour is quite normal as long as your not right next to the access point. On battery power the wireless lan card reduces its energy consumption thus the connection will be poor if you dont have a perfect signal. You can turn this off in the iNTEL Pro/SET wireless software, where you can configure the adaptor. Try to change the powersafe mode to manual and full power, this should solve your problem.

  • WBS element output not coming properly .

    Hi ,
    I have a customized report with , project(proj-pspid) ,wbs element( prps-posid) as selection parameters . The output is coming preperly when project is given as output but is not coming properly when wbs element is given as input. I am using PSJ logical database . Not sure why in debugging while giving only wbs element it is going to 'Conversion_exit_abpsn_input' instead of teh conversion exit 'Conversion_exit_abpsp_input' . Any idea on how it can be resolved?

    Hi,
         Please refer the WBS element to PSPNR (PRPS-PSPNR) instead of prps-posid ,
         prps-posid refers to exit 'Conversion_exit_abpsn_input' and not 'Conversion_exit_abpsp_input'.
    Regards,
    Srini.

Maybe you are looking for