Announcement

Collapse
No announcement yet.

Programming Question Part 2

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Programming Question Part 2

    Well I'm almost done with part A of task 2 and I've hit a wall. Here's what I have to do:



    Everything on there is pretty much done I think except for part 4 and its subsequent writing to the agentreport.txt. To be honest, I have no idea how to do this map. I don't even know where to begin. I found some basic syntax but that's about it. I really don't understand how the program is going to take each instance of the agent ID and then somehow scan the amount? Here's the listings.txt and what the agentreport.txt should look like:

    Example listings.txt file:

    110001 commercial 500000.00 101
    110223 residential 100000.00 101
    110020 commercial 1000000.00 107
    110333 land 30000.00 105
    110442 farm 200000.00 106
    110421 land 40000.00 107
    112352 residential 250000.00 110

    Example agentreport.txt file:

    COMMERICAL
    FARM
    LAND
    RESIDENTIAL

    101 600000.00
    105 30000.00
    106 200000.00
    107 1040000.00
    110 250000.00

    I honestly have no idea what the **** to do on this and I don't understand how the hell it "reads" the amount. Here's my code so far, maybe you can help me understand this:

    package agentreport;
    import java.util.Scanner;
    import java.io.FileReader;
    import java.io.FileNotFoundException;
    import java.io.PrintWriter;
    import java.util.TreeSet;
    import java.util.Set;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.TreeMap;
    /**
    *
    * @author DriXnaK
    */
    public class Main {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args)
    throws FileNotFoundException
    {
    Scanner console = new Scanner(System.in);

    System.out.print("Input File: ");

    String inputFileName = console.next();

    //Creates treeset propertyType
    Set propertyType = new TreeSet();

    //Adds property types to set
    propertyType.add("farm");
    propertyType.add("land");
    propertyType.add("residential");
    propertyType.add("commercial");


    //Creates FileReader object with name of input file.
    FileReader reader = new FileReader("C:\\Users\\DriXnaK\\Documents\\NetBeansProjects\\A gentReport\\listings.txt");

    //Creates scanner object from FileReader object.
    Scanner agentReport = new Scanner(reader);

    //Prints out to agentreport.txt.
    System.out.print("Output file: ");
    PrintWriter outAgentReport = new PrintWriter("C:\\Users\\DriXnaK\\Documents\\NetBeansProjects\\A gentReport\\agentreport.txt");

    /*Creates set iterator and lists all elements in the propertyType set.
    Converts them to uppercase before printing to the agentreport.txt*/
    Iterator propertyIterator = propertyType.iterator();
    while (propertyIterator.hasNext())
    {
    String upperCaseProperty = propertyIterator.next();
    upperCaseProperty = upperCaseProperty.toUpperCase();
    outAgentReport.println(upperCaseProperty);

    }

    outAgentReport.println(" ");


    outAgentReport.close();
    }

    }
    Last edited by DriXnaK; October 26, 2010, 12:19.

  • #2
    Ok, I think maybe I built the treemap properly, but not how they wanted it in the directions. Here's the code:

    //Creates TreeMap "idMap" and sets keys and values.
    TreeMap <Integer, Double> idMap = new TreeMap <Integer, Double>();
    idMap.put(101, 600000.00);
    idMap.put(105, 30000.00);
    idMap.put(106, 200000.00);
    idMap.put(107, 1040000.00);
    idMap.put(110, 250000.00);
    I get the feeling they want me to somehow scan the document for those numbers instead of manually setting them, but I don't really understand how that's done.
    Last edited by DriXnaK; October 23, 2010, 20:13.

    Comment


    • #3
      Replace < with &lt;
      "The issue is there are still many people out there that use religion as a crutch for bigotry and hate. Like Ben."
      Ben Kenobi: "That means I'm doing something right. "

      Comment


      • #4
        Ok thanks. Forgot about that.

        Comment


        • #5


          This has a better explanation of how to use a Scanner than I would write.

          Comment


          • #6
            Ok, so I am doing this wrong though?

            Comment


            • #7
              Yes. You should make a Scanner on listings.txt and use it to read in all of the property types. Something like:

              while (scanner.hasNextLine()) propertyType.add(scanner.nextLine());

              Comment


              • #8
                Ok, but what I don't understand is how it picks out the property type from that line. If you just do nextline it prints the whole line to the agentreport.txt.

                Comment


                • #9
                  Oh, sorry, I misread the OP.

                  So, initially the Set propertyType will be empty. You don't know the different property types before you read listings.txt. So instead it looks like this:

                  Code:
                  int property;
                  int agent;
                  double price;
                  String type;
                  
                  while (scanner.hasNextLine()) {
                      property = scanner.nextInt();
                      type = scanner.nextString();
                      price = scanner.nextDouble();
                      agent = scanner.nextInt();
                      // do what you need to do with these values
                  }
                  If you were reading through listings.txt normally (in notepad or whatever), and trying to construct an agentreport.txt file according to their spec, what would you do? Then code that.

                  Comment


                  • #10
                    OK, that code right there I think explains to me now how it works. I'll experiment with it tomorrow morning. Thanks!

                    Comment


                    • #11
                      Didn't end up helping me too much. Gave me all kinds of errors and I couldn't get anything to work. There's also no such thing as the nextString method from what I can tell. I think maybe I have to use a delimeter or something? I can't understand it from the java API alone though. There's also nothing about this in my 1224 page book for this course, nor is there anything mentioned about it in the course period. Just another instance of them giving a task that has nothing to do with what the course went over.

                      EDIT: Actually I think I might have something now.
                      Last edited by DriXnaK; October 24, 2010, 13:06.

                      Comment


                      • #12
                        I'm really at a point where I just don't know what the **** to do. It's not even covered in the ****ing book or course but I'm being asked to do it. What kind of ****ing piece of **** course is this? I'm so ****ing tired of this ****ing ****. There's no ****ing reason for this ****.

                        Here's my code:

                        while (console.hasNextLine())
                        {
                        property = console.nextInt();
                        type = console.next();
                        price = console.nextDouble();
                        agent = console.nextInt();
                        propertyType.add(type);
                        }

                        I don't understand how the **** this thing knows to disregard stuff and keep on moving and only entering in the things it needs. There's no ****ing explanation anywhere for this ****. I've ****ing had it.

                        Comment


                        • #13
                          You mean, there's no explanation for how the Scanner actually does what it does? That's why I posted this link:



                          That said, it uses regular expressions, which you don't know yet and don't want to learn yet.

                          Comment


                          • #14
                            Why don't I want to learn it yet? I still don't understand the syntax of what I'm trying to do so I'll re-read that link again and I guess try some more experimenting to see if I can get it right. This course is the most worthless ****ing course I've ever seen in my life.

                            Comment


                            • #15
                              Have you though about choosing some other profession? If you can't wrap your head around some algorithms, maybe you're better off forging steel?
                              Graffiti in a public toilet
                              Do not require skill or wit
                              Among the **** we all are poets
                              Among the poets we are ****.

                              Comment

                              Working...
                              X