Handling files with different sizes of content (please help)!

Hi,
I have a written a program to tell customers how much certain apartments are to rent.
It asks the reader to input a floor number and the number of bedrooms in the apartment. I then returns the price.
The contents of the file look like this:
0 400 450 510
1 500 560 630
2 625 676 740
3 1000 1250 1600
the first column of numbers refer to the floor number (0-3) and the following columns relate to the prices of bedrooms. The first is 0 rooms, then 1 room, then 2 rooms.
So a one bedroom appartment on the 0th (ground) floor would be 450.
This program works perfectly for this set of data and returns the correct answer. What i want to try and do is make it work with different sets of data
e.g more floors and moree rooms. up to an unlimited number of both
Can anyone help me with this because im not sure how.
heres the code
import java.io.*;
import java.util.Vector;
public class FlatCost
    public static void main(String[] args) throws IOException    {
        FileInputStream stream = new FileInputStream(args[0]);
        InputStreamReader reader = new InputStreamReader(stream);
        StreamTokenizer tokens = new StreamTokenizer(reader);       
        Vector v = new Vector();
        while(tokens.nextToken() != tokens.TT_EOF)        {           
            v.add(new Integer((int) tokens.nval));
            System.out.println(new Integer((int) tokens.nval));       
        System.out.println("Enter floor number: ");       
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line1 = in.readLine();
        int x = Integer.parseInt(line1);
        if(x > 3) System.out.println("Sorry, out of range");
        System.out.println("Enter no. rooms: ");       
        String line2 = in.readLine();          
        int y = Integer.parseInt(line2);
        if(y > 2) System.out.println("Sorry, out of range");
        int numFloors = v.size()/4;               
        int dest = ((x*4) + y + 1);
        System.out.println("PRICE: " + v.get(dest));   
}Thanks
Sarah x

Try this
import java.io.*;
import java.util.ArrayList;
public class FlatCost
  ArrayList floors = new ArrayList();
  public FlatCost()
    try
      readDataFromFile();
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int floor;
      int rooms;
      String another = "y";
      while(another.equalsIgnoreCase("y"))
        System.out.print("\nEnter floor number (0 for ground): ");
        floor = Integer.parseInt(in.readLine());
        if(floor < 0 || floor > floors.size())
          System.out.println("floor out of range, try again");
        else
          System.out.print("\nEnter no. rooms: ");
          rooms = Integer.parseInt(in.readLine());
          if(rooms < 1 || rooms > ((String[])floors.get(floor)).length)
            System.out.println("rooms out of range, try again");
          else
            System.out.println("\nThe cost of a "+rooms+"-room flat is $"+
                                   ((String[])floors.get(floor))[rooms]);
            System.out.print("\nAnother? (y/n): ");
            another = in.readLine();
    catch(Exception e){System.out.println("error - terminating");}
  public void readDataFromFile() throws Exception
    BufferedReader br = new BufferedReader(new FileReader("FlatData.txt"));
    String line = "";
    while((line = br.readLine()) != null) floors.add(line.split(" "));
    br.close();
  public static void main(String[] args){new FlatCost();}
}

Similar Messages

  • My MacBook just has a white screen and a flashing file with a question mark. Please help:(

    I don't really understand what's happening, but I tried to update the software. Then all these codes appeared on the screen so I help down alt, command and R and it then reset and now it's just a white screen with a flashing file and questionmark. Please help.

    That is a sign that the MBA cannot locate the OSX.  The storage drive may be damaged.
    LaurenDavie123 wrote:
    I help down alt, command and R and it then reset a
    What exactly did your reset? 
    Ciao.

  • How to merge two java files with InputDialog to select?Please help me!?

    //Addition Java application
    import javax.swing.JOptionPane; // import the class
    public class Addition {
    // main method
    public static void main(String[] args)
    String firstNumber, secondNumber;
    int number1, number2, sum;
    // read the first number
    firstNumber = JOptionPane.showInputDialog("Please enter a integer: ");
    // read the second number
    secondNumber = JOptionPane.showInputDialog("Please enter another integer: ");
    // data type conversion
    number1 = Integer.parseInt(firstNumber);
    number2 = Integer.parseInt(secondNumber);
    sum = number1 + number2;
    // display the result
    JOptionPane.showMessageDialog(null, "The sum is " + sum + ".", "Results", JOptionPane.PLAIN_MESSAGE);
    System.exit(0);
    //Multiplication Java Application
    import javax.swing.JOptionPane;
    public class Multiplication5
    public static void main(String args[])
    int number1, number2, number3, number4, number5, product;
    String firstNumber, secondNumber, thirdNumber, forthNumber, fifthNumber ;
    firstNumber =
    JOptionPane.showInputDialog("Please input an integer");
    secondNumber =
    JOptionPane.showInputDialog("Please input another integer");
    thirdNumber =
    JOptionPane.showInputDialog("Please input the third integer");
    forthNumber =
    JOptionPane.showInputDialog("Please input the forth integer");
    fifthNumber =
    JOptionPane.showInputDialog("Please input the fifth integer");
    number1 = Integer.parseInt(firstNumber);
    number2 = Integer.parseInt(secondNumber);
    number3 = Integer.parseInt(thirdNumber);
    number4 = Integer.parseInt(forthNumber);
    number5 = Integer.parseInt(fifthNumber);
    product = number1 * number2 * number3 * number4 * number5;
    JOptionPane.showMessageDialog(null, "The product is " + product, "Results", JOptionPane.PLAIN_MESSAGE);
    System.exit(0);
    I seek for help to merge above two java application files.
    I need to call JoptionPane.showInputDialog to prompt the user to input the operation, 1 for addition, 2 for multiplication. In this dialog, the user is expected to enter the integer of 1 or 2 for the calculation.
    Please help me ! Thank you!

    Hi CRay,
    You just need to call the main methods of the 2 classes according to "1" or "2" entered.
    It is better if the "multiplication" and "addition" are declared as methods rather than in main methods.
    Example:-
    public static void Addition()
    Then call
    Addition.addition();
    than
    Addition.main(new String[]{});
    as shown below.
    import javax.swing.JOptionPane; // import the class
    public class Test{
        public static void main(String[] args){
            // read which  operation to perform
            String operation = JOptionPane.showInputDialog("Please enter which operation : ");
            if(operation.equals("1")){
                Addition.main(new String[]{});
            else{
                Multiplication5.main(new String[]{});
    }Rose

  • Problem with array size...PLEASE HELP

    hi...
    I want to keep putting the Strings that user inputs, in an array. I don't know how many of them there are, and I don't want to define a big array like :
    String myArray[]= String [1000];
    what am I suppose to do?
    PLEASE HELP...!
    Thanks

    Use a Vector or an ArrayList instead of a straight array.

  • Why would two copies of Lightroom 5 create DNG files with different sizes from the same RAW file? (size is dramatically different, on the order of doubled in size.)

    I have a copy of LIghtroom 5 on my office computer and a personal copy on my home computer. I convert my RAW files to DNG with Lightroom when I import them. Files I shoot for work also get imported on my home workstation. I noticed today that the resulting DNG files for the same RAW image are widely different in size. The ones at home are roughly twice as big as the ones from the office.
    To the best of my knowledge, things are set up the same on both workstations. Any idea what setting might be causing this variation?

    I don't think it's possible to apply lossy compression when importing directly into Lightroom.  I know you can do it with the DNG converter and on export but I don't think this is the case here.
    In which case we need to determine which set-up producing is the "correctly" sized files.  What's the camera and what are the respective file sizes from work and home?

  • Urgent help please, I made an file with the size 1024x768, then i made two folios, one for retina 2048x1536 and one for non retina 1024x768, i have alot of video content in it, everything works perfect on my retina ipad, but when i open it on ipad 2 an er

    Urgent help please, I made an file with the size 1024x768, then i made two folios, one for retina 2048x1536 and one for non retina 1024x768, i have alot of video content in it, everything works perfect on my retina ipad, but when i open it on ipad 2 an error appears on the pages with video content?

    its in german:
    der Vorgang könnte nicht abgeschlossen werden.
    something like the process coundnt be completed

  • Parsing XML file with different languages (Xerces)

    How do we code or program to an XML file with different
    languages , say english and spanish. WHen we parse such a document with the default locale , the presence of special characters throws errors .For eg when I use xerces and use
    DOMParser parser = new DOMParser();
    try
    // Parse the XML Document
    parser.parse(xmlFile);
    catch (SAXException se)
    se.printStackTrace();
    org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xfc) was found in the element content of the document.
    System Error:          void org.apache.xerces.framework.XMLParser.parse(org.xml.sax.InputSource)
    So what locale do we set before we parse ?How to handle this problem

    You need an encoding attribute in the xml declaration. If you don't, the parser assumes UTF-8, which are ASCII characters up to 127 - useful (only) for English.
    So, something like this would allow you to use characters above 127, ISO-8859-1 is the encoding used by standard PCs.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    You can find a (offical) list of encodings at:
    http://www.iana.org/assignments/character-sets
    I'm not sure about mixing various encodings. I think you have to resort external parsed entities, which can have their own encoding, but I think you cannot mix encodings in one XML file.
    Good luck.

  • How can i compare two excel files with different no. of records.

    Hi
    I am on to a small project that involves us to compare two excel files. i am able to do it but am struck up at a point. When i compare 2 different .csv files with different no. of lines i am only able to compare upto a point till when the number of lines is same in both the files.
    Eg. if source file has 8 lines and target file has 12 lines. The difference is displayed only till 8 lines and the remaining 4 lines in source lines are not shown.
    Can you help me in displaying those extra 4 lines in source file. I am attaching my code snippet below..
    while (((strLine = br.readLine()) != null) && ((strLine1 = br1.readLine())) != null)
                     String delims = "[;,\t,,,|]";
                    String[] tokens = strLine.split(delims);
                    String[] tokens1 = strLine1.split(delims);
                   if (tokens.length > tokens1.length)
                    for (int i = 0; i < tokens.length; i++) {
                        try {
                            if (!tokens.equals(tokens1[i])) {
    System.out.println(tokens[i] + "<----->" + tokens1[i]);
    out.write(sno + " \t" + lineNo1 + " \t\t" + tokens[i] + "\t\t\t\t" + tokens1[i]);
    out.println();
    sno++;
    } catch (Exception exception)
    out.write(sno + " \t" + lineNo1 + " \t\t" + tokens[i] + "\t\t\t\t" + "");
    out.println();
    Thanks & Regards                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    A CSV file is not an Excel file.
    But apart from that your logic makes no sense.
    If the 2 files are of different sizes the files are different by definition, so further comparison isn't needed, you're done.
    If you want to compare individual records, you need to compare all records from one file with all records from the other, unless the order of records is important in which case your current system might work.
    That system however is overly complicated for comparing CSV files.
    As you assume a single record per line, and if one can assume those records to have identical layout (so no leading or trailing whitespace in or between columns in one file that's not in the other) comparing records is simply a matter of comparing the entire lines.

  • From sap to excel file with different sheets?

    can  i upload   an internal table  from  SAP to single Excel file with different sheets for example like : sheet1, sheet2, sheet3.......sheet10. , but need to upload data from sap to excel worksheets ie. from multiple named tabs in Excel. Is this possible, and if so, please can you help and advise me how?
    thanks
    venkat.
    Edited by: Matt on Feb 16, 2009 2:15 PM  Removed excessive question marks...!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Hi venkat,
    Yes indeed it is possible to write data from internal table to different excel sheets. Check out SAP's Microsoft OLE functionality.Search on SDN for OLE . Following are some links
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/sample%252bprogram%252bto%252bopen%252bexcel%252bsheet%252busing%252bole
    You can also check out FM ALSM_EXCEL_TO_INTERNAL_TABLE to check how to read different worksheets.
    Using the above two resources you can create a program that can upload data to multiple worksheets in the same workbook.
    Also see this link
    Creating Excel with More than one page
    Edited by: aditya aghor on Feb 16, 2009 1:57 PM
    Edited by: aditya aghor on Feb 16, 2009 2:02 PM

  • How to generate a second csv file with different report columns selected?

    Hi. Everybody:
    How to generate a second csv file with different report columns selected?
    The first csv file is easy (report attributes -> report export -> enable CSV output Yes). However, our users demand 2 csv files with different report columns selected to meet their different needs.
    (The users don't want to have one csv file with all report columns included. They just want to get whatever they need directly, no extra columns)
    Thank you for any help!
    MZ

    Hello,
    I'm doing it usually. Typically example would be in the report only the column "FIRST_NAME" and "LAST_NAME" displayed whereas
    in the csv exported with the UTL_FILE the complete address (street, housenumber, additions, zip, town, state ... ) is written, these things are needed e.g. the form letters.
    You do not need another page, just an additional button named e.g. "export_to_csv" on your report page.
    The csv export itself is handled from a plsql procedure "stored procedure" ( I like to have business logic outside of apex) which is invoked by pressing the button "export_to_csv". Of course the stored procedure can handle also parameters
    An example code would be something like
    PROCEDURE srn_brief_mitglieder (
         p_start_mg_nr IN NUMBER,
         p_ende_mg_nr IN NUMBER
    AS
    export_file          UTL_FILE.FILE_TYPE;
    l_line               VARCHAR2(20000);
    l_lfd               NUMBER;
    l_dateiname          VARCHAR2(100);
    l_datum               VARCHAR2(20);
    l_hilfe               VARCHAR2(20);
    CURSOR c1 IS
    SELECT
    MG_NR
    ,TO_CHAR(MG_BEITRITT,'dd.mm.yyyy') AS MG_BEITRITT ,TO_CHAR(MG_AUFNAHME,'dd.mm.yyyy') AS MG_AUFNAHME
    ,MG_ANREDE ,MG_TITEL ,MG_NACHNAME ,MG_VORNAME
    ,MG_STRASSE ,MG_HNR ,MG_ZUSATZ ,MG_PLZ ,MG_ORT
    FROM MITGLIEDER
    WHERE MG_NR >= p_start_mg_nr
    AND MG_NR <= p_ende_mg_nr
    --WHERE ROWNUM < 10
    ORDER BY MG_NR;
    BEGIN
    SELECT TO_CHAR(SYSDATE, 'yyyy_mm_dd' ) INTO l_datum FROM DUAL;
    SELECT TO_CHAR(SYSDATE, 'hh24miss' ) INTO l_hilfe FROM DUAL;
    l_datum := l_datum||'_'||l_hilfe;
    --DBMS_OUTPUT.PUT_LINE ( l_datum);
    l_dateiname := 'SRNBRIEF_MITGLIEDER_'||l_datum||'.CSV';
    --DBMS_OUTPUT.PUT_LINE ( l_dateiname);
    export_file := UTL_FILE.FOPEN('EXPORTDIR', l_dateiname, 'W');
    l_line := '';
    --HEADER
    l_line := '"NR"|"BEITRITT"|"AUFNAHME"|"ANREDE"|"TITEL"|"NACHNAME"|"VORNAME"';
    l_line := l_line||'|"STRASSE"|"HNR"|"ZUSATZ"|"PLZ"|"ORT"';
         UTL_FILE.PUT_LINE(export_file, l_line);
    FOR rec IN c1
    LOOP
         l_line :=  '"'||rec.MG_NR||'"';     
         l_line := l_line||'|"'||rec.MG_BEITRITT||'"|"' ||rec.MG_AUFNAHME||'"';
         l_line := l_line||'|"'||rec.MG_ANREDE||'"|"'||rec.MG_TITEL||'"|"'||rec.MG_NACHNAME||'"|"'||rec.MG_VORNAME||'"';     
         l_line := l_line||'|"'||rec.MG_STRASSE||'"|"'||rec.MG_HNR||'"|"'||rec.MG_ZUSATZ||'"|"'||rec.MG_PLZ||'"|"'||rec.MG_ORT||'"';          
    --     DBMS_OUTPUT.PUT_LINE (l_line);
    -- in datei schreiben
         UTL_FILE.PUT_LINE(export_file, l_line);
    END LOOP;
    UTL_FILE.FCLOSE(export_file);
    END srn_brief_mitglieder;Edited by: wucis on Nov 6, 2011 9:09 AM

  • SSIS project - read multiple flat files with different formats

    hi all,
    i need to import multiple flat files with different formats into different tables of the sql server database and not able to figure out the best way out in ssis to do so...
    please advise the possible methods in ssis to do so and if possible the process which can be dynamic as file names or columns might change in future.

    Hi AK1987,
    To import flat files with dynamic columns, we can use Script Task inside a Foreach Loop Container to parse the first row of the flat file to get the columns names and save them into a .NET variable, then, we can create “Create Table” script based on this
    variable, and then store the script into a SSIS package variable. After that, we create a staging table based on the package variable, load the flat file data to the staging table. Eventually, we load data from the staging table to the destination table. For
    the detail steps, please walk through the following blog:
    http://www.citagus.com/citagus/blog/importing-from-flat-file-with-dynamic-columns/ 
    Regards,
    Mike Yin
    TechNet Community Support

  • SSIS - Import Multiple flat files with different metadata

    Hi ,
    I have set of flat files with different metadata structure, I would like to load them into staging tables. 
    1. ) Can we load the flatfiles into the staging tables with out having multiple data flow task.
    2.) If possible , can we programmatically select the staging table based on the metadata of the flatfile and load them.
    Please advise.
    Thanks
    Thiya

    Nope in SSIS a data flow task needs to have a fixed metadata. So if your file metadata varies then best option would be use OPENROWSET syntax to pull the data and populate into your staging table. You may also use 
    SELECT .. INTO StagingTable ... FROM OPENROWSET (...)
    syntax to create staging table at runtime based on the file metadata
    http://sqlmate.wordpress.com/2012/08/09/use-your-text-csv-files-in-your-queries-via-openrowset/
    If you want to do this in SSIS you need to create data flow dynamically using script task and build the metadata
    see
    http://www.selectsifiso.net/?p=288
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Printing different/selective files with different copies

    Hi everyone,
    I've been working on finding a solution, on how to print different pdf files with different copies, without opening the pdf-files.
    Task:
    I have a folder, with 25 pdf files
    I want to make a php overview, of the folder
    At the end of each line/file - i would like to add a number for the copies
    In the end, I would like to simply press print - and every document ive added a number/copies to - are being printet...
    I guess I need to use PrintPDF - but does anyone know any pre-made program/function - that could handle the "copies" part...?
    I hope someone can help me out,
    Thanks
    Jan

    Well, i had hoped that the acrobat could open silent - eventhough they've removed that feature in the newer versions.
    Even though the program would open - if the amount of copies was added - and i just hat to press print - it would ease the job alot.

  • Multiple masters with DIFFERENT sizes?

    Hi,
    I think this is a NO, but I have to ask.
    Is it possible to have different master pages in a single document, each with a different size?
    If not, how do I tackly my problem?
    I am making a sales matrix and it will be comprised of 3.5 inch by 7 inch pages with some 3.5 by 3.5 inch pages interspersed throughout.
    I don't want to have two InDesign files, so it would be great if I could have masters with different sizes, OR if there was a way to use the larger of the two sizes, 3.5x7 and then set my square 3.5x3.5 pages doubled up on the larger page.
    I know I can use the 'book' feature, but sometimes that is more trouble than it's worth, especially with different size pages. What do you suggest?

    Peter,
    why do you say easier to work the other way?
    I think this spread thing may just work.
    I normally have facing pages in all of my saddlestitched letter size docs and output via Export to PDF with trim marks on. That gives me a pdf and eachpage has trim marks.
    Doing it this way with a 3.5x3.5 document and outputting spreads, I get exactly what I want. A pdf with one 7 inch page and 4 3.5 inch pages all with trim marks at the right places.
    Before I proceed though, I want to hear why this might be a bad idea....

  • Streaming files with different folders

    Hi
    i am new to FMS4 and i am having a problem playing some files with different folders.
    i have different folders in C:\media3\feeds
    in that directory i have folder "1", "2" and "3"
    other words C:\media3\feeds\1
    C:\media3\feeds\2
    C:\media3\feeds\3
    in config folder i changed fms.ini
    VOD_DIR = C:\media3\feeds\
    and
    VOD_COMMON_DIR = C:\media3\feeds\
    i only got the f4v files to work in C:\media3\feeds\ which link is rtmp://localhost/vod/mp4:testfile.f4v
    so i tired to have some folders in C:\media3\feeds\ like mention above
    i tried to put <Streams>/;<C:\media3\feeds\1</Streams> in Applications.xml file in the C:\Program Files\Adobe\Flash Media Server 4\applications\vod
    and used rtmp://localhost/vod/1/mp4:testfile.f4v
    here is piece of the App file
    <Application>
    <StreamManager>
    <VirtualDirectory>
          <!-- Specifies application specific virtual directory mapping for recorded streams.   -->
    <Streams>/;${VOD_COMMON_DIR}</Streams>
    <Streams>/;${VOD_DIR}</Streams>
    <Streams>/;<C:\media3\feeds\1</Streams>
    <Streams>/;<C:\media3\feeds\2</Streams>
    </VirtualDirectory>
    nothing worked
    can some one help me with this??

    If you are using
    VOD_DIR = C:\media3\feeds\ or VOD_COMMON_DIR = C:\media3\feeds\
    and having files in folder "1" which is under "C:\media3\feeds\"
    then you URI should be rtmp://localhost/vod/mp4:1/testfile.f4v (where testfile.f4v is present under C:\media3\feeds\1)
    If you are using
    <Streams>/;C:\media3\feeds\1</Streams>
    <Streams>/;C:\media3\feeds\2</Streams>
    Then your URI should be rtmp://localhost/vod/mp4:testfile.f4v  (where testfile.f4v is present under C:\media3\feeds\1 or C:\media3\feeds\2)
    Also please note in your configuration which you have specified
    <Streams>/;<C:\media3\feeds\1</Streams><Streams>/;<C:\media3\feeds\2</Streams>
     please remove "<" in "<C:\media3\feeds\1" and "<C:\media3\feeds\2"

Maybe you are looking for

  • Non-conforming dimension filters

    Hi, Here how my join looks FACT1>>product(dim)<< FACT2>>ledger(dim)>>RPT(dim) Here RPT(dim) is non conforming dimension for FACT1 and product(dim) is common for both FACT1 and FACT2 I have set content level(LTS) only for conformed dim.( to detail) Wh

  • Unwanted line in DW when adding a Flash item...Help!

    Guys/Gals When I try to put a movie item in my Dreamweaver page, an additional line appears underneath - that I do not want. See this page: http://perryautolaval.com/autoaboutfr.php right under the flash banner, a grey lines appears. It should look l

  • Error  message for inventory

    Hi,   While activating multiprovider made on inventory cube and dso, error is "The InfoCube contains non-cumulative values. A validity table is created for these non-cumulative values, in which the time interval is stored, for which the non-cumulativ

  • Characterstic variable with customer exit

    Can u some bady help me. How to express about Characterstic variable with customer exit Edited by: chenna reddy on Aug 7, 2008 9:48 PM

  • How to "extend" jsp:include ... / ?

    Hello! Does anybody know how to create custom-tag which extends the <jsp:include page='xxx'/>? I need to pass some info in the included xxx page and I don?t want to do it by the <jsp:param /> tags. For example: I need the tag <my:object id='7'/> and