Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 13 of 13

Thread: Adventure ride project

  1. #1
    Junior Member Ciwan's Avatar
    Join Date
    Feb 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Adventure ride project

    Hi Guys

    before I begin, I want to let you all know that I'm a total n00b in Java, so please go easy one me

    I am planning on doing an Adventure Ride Project. It is an application where the person would choose what rides he wants to use and hire. It would look something like this >


    When the person clicks the [Plan] button, then something like this would be displayed:



    Then maybe have a Total at the bottom of the 2nd GUI, and fields where the user can input the miles he/she wants to ride each transport vehicle and of course an [Confirm] button which I have forgotten to put on.

    The person would move from one adventure ride to another, How fun right ?

    Now I know this is BIG (or at least I think it is for me !!) and that is why I want to start with the most basic things first !

    What is the best way to go about creating the code for the list of each class ! I realise it will be similar for all three, because they will all be using the same layout.

    Is an ArrayList the best thing to use ? An Arraylist which would hold Bicycles ? Or is there a better way for doing this ?

    I would GREATLY APPRECIATE any help given.

    Thanks Guys.
    Last edited by Ciwan; February 11th, 2009 at 04:14 PM.
    "Extraordinary Claims Require Extraordinary Evidence" .... American Astrochemist Carl Sagan.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help with my AR Project

    Hey Ciwan,

    Just to clarify, you are programming in Java and not JavaScript right?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member Ciwan's Avatar
    Join Date
    Feb 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with my AR Project

    Hi JavaPF

    Yes I am programming in Java

    NOT JavaScript
    "Extraordinary Claims Require Extraordinary Evidence" .... American Astrochemist Carl Sagan.

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help with my AR Project

    Cool..

    Id suggest downloading Netbeans if you haven't done so already. You can use it to easily design the graphical user interface.

    There are several ways you could store the information, I personally would save the details in a .txt file and then have the code loop through and display the different bike options. You can easily add to it then without having to recode..

    Check out the Tips & Tutorials section of the forum. There are code examples there that will help you.

    Keep me updated and I will help you along the way.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. #5
    Junior Member Ciwan's Avatar
    Join Date
    Feb 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with my AR Project

    Hi JavaPF

    Slight change of plan (Read first post)

    Now that it is all clear, do you still think I can do this by saving the info in a text file or text files ?

    If so .. Would I need 3 text files ? One for Cycling, one for Driving and one for Flying ?

    How would I go about saving all the data for each bicycle/car/airplane model in the text file ?

    In the meantime I am heading over the Tips & Tutorials section to Read every single post in there, hopefull I'll be able to answer my own questions

    PS. I already have NetBeans 6.5 (with all latest updates for its plugins) + UML Plugin

    I would greatly appreciate any help given.

    THANK YOU
    "Extraordinary Claims Require Extraordinary Evidence" .... American Astrochemist Carl Sagan.

  6. #6
    Junior Member Ciwan's Avatar
    Join Date
    Feb 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Re: Help with my AR Project

    I've just read every single post in the Tips & Tutorials section.

    I think the only one that applies to me is the one about >> Text Processing with Regular Expressions

    But I'm still not sure, how I would write the data in the text file (if that indeed is the best way to implement this project).
    "Extraordinary Claims Require Extraordinary Evidence" .... American Astrochemist Carl Sagan.

  7. #7
    Junior Member Ciwan's Avatar
    Join Date
    Feb 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with my AR Project

    I've created this UML model of the app, I don't know if it is any good ? I would appreciate it if you point out any errors !!



    Thanks
    "Extraordinary Claims Require Extraordinary Evidence" .... American Astrochemist Carl Sagan.

  8. #8
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help with my AR Project

    Hey Ciwan,

    Sorry I haven't got back to you sooner.

    Storing the data in a text file is just an idea. There are a few different ways you could do this and an Array or ArrayList would be just fine.

    If you wanted to use the .txt file option then these links are useful:

    http://www.javaprogrammingforums.com...sing-java.html

    http://www.javaprogrammingforums.com...line-line.html

    I think for now, it may be easier for you just to use arrays.

    Have you started designing the GUI yet? I don't normally use netbeans but ive just installed it so ill have ago at making a simple interface with some code examples for you to expand on.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  9. #9
    Junior Member Ciwan's Avatar
    Join Date
    Feb 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with my AR Project

    Hi JavaPF

    Yes I have started working on the GUI, I'll post a screenshot later on today (I'm currently at work)

    I've been doing some research and I find many people saying data saved in XML files is easier to handle, because the data has a defined structure .. is this true ?

    If it is true, then I think I'll go ahead with saving the data in an XML file (I know how to do that so don't worry ) .. however I'll need a bit of help on how how to " READ " the data from the file > I'll have a good read of them threads you've linked me to.

    I'll let you guys know how I'm advancing by this evening

    Thanks for everything JavaPF
    "Extraordinary Claims Require Extraordinary Evidence" .... American Astrochemist Carl Sagan.

  10. #10
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help with my AR Project

    Hey Ciwan,

    Storing & parsing XML data is a lot harder than reading a text file.
    Here is an example of parsing an XML document using DOM Parse so you can see what I mean:

    http://www.javaprogrammingforums.com...dom-parse.html

    Seeing as your new to Java, i'd aim to make this application as simple as possible. The more complicated it is the harder it will be for you to code and understand!

    Maybe you should try making a really simple version first and then make it more complicated in version 2

    Just a thought.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  11. #11
    Junior Member Ciwan's Avatar
    Join Date
    Feb 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Re: Help with my AR Project

    Hi JavaPF

    Quote Originally Posted by JavaPF View Post
    Storing & parsing XML data is a lot harder than reading a text file.
    Really ? I don't think it is that hard ! I followed your tutorial and I managed to do it ! Either it is NOT as hard as you say it is .... OR... you are REALLY GOOD at writing Tutorials

    Quote Originally Posted by JavaPF View Post
    Seeing as your new to Java, i'd aim to make this application as simple as possible. The more complicated it is the harder it will be for you to code and understand!
    I know I said I was new to Java, but I am not a total n00b. I'm actually studying Java at University (just started) and we have already created simple applications (with no GUIs), so I know the main concepts of OO Programing in Java. But no where I'm as good as you !!

    That is why I need help with bits and pieces
    "Extraordinary Claims Require Extraordinary Evidence" .... American Astrochemist Carl Sagan.

  12. #12
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Help with my AR Project

    OK. That is good to hear

    If you wish to store the information as XML then go for it!! Its all good practise.

    I look forward to seeing your progress.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  13. #13
    Junior Member Ciwan's Avatar
    Join Date
    Feb 2009
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Re: Help with my AR Project

    OK, here is where I'm at so far.

    XML File:

    <?xml version="1.0" encoding="UTF-8"?>
     
    <cycling>
      <bicycle>
        <make>Dawes</make>
        <model>Giro 300</model>
        <price>20</price>
      </bicycle>
      <bicycle>
        <make>Kona</make>
        <model>Kona Road</model>
        <price>25</price>
      </bicycle>
      <bicycle>
        <make>Felt</make>
        <model>F95</model>
        <price>25</price>
      </bicycle>
      <bicycle>
        <make>Lapierre</make>
        <model>R LITE 300 09</model>
        <price>30</price>
      </bicycle>
    </cycling>

    DataReader Class:

    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NodeList;
    import java.io.*;
     
    /*
     * The DataReader class's job is to " read " data from the XML file.
     */
     
    /**
     *
     * @author Andy Green
     */
    public class DataReader
    {
        public static void main(String[] args)
        {
     
          File file = new File("/home/andy/NetBeansProjects/cycling.xml");
     
          try {
          DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
          Document doc = builder.parse(file);
     
          NodeList nodes = doc.getElementsByTagName("bicycle");
     
          for (int i = 0; i < nodes.getLength(); i++) {
     
             Element element = (Element) nodes.item(i);
     
             NodeList name = element.getElementsByTagName("make");
             Element line = (Element) name.item(0);
     
             System.out.println("Bicycle Make: " + line.getFirstChild().getTextContent());
     
             NodeList age = element.getElementsByTagName("model");
             line = (Element) age.item(0);
             System.out.println("Model: " + line.getFirstChild().getTextContent());
     
             NodeList hobby = element.getElementsByTagName("price");
             for(int j=0;j<hobby.getLength();j++)
             {
                line = (Element) hobby.item(j);
                System.out.println("Price: £" + line.getFirstChild().getTextContent());
             }
     
             System.out.println();
          }
          }
          catch (Exception e)
          {
          e.printStackTrace();
          }
        }
    }

    Result of running the DataReader Class:

    Bicycle Make: Dawes
    Model: Giro 300
    Price: £20

    Bicycle Make: Kona
    Model: Kona Road
    Price: £25

    Bicycle Make: Felt
    Model: F95
    Price: £25

    Bicycle Make: Lapierre
    Model: R LITE 300 09
    Price: £30
    However, looking at my DataReader class, I feel there are bits of code that aren't really needed for my XML file, but are there from the previous file you used in your Tutorial example. I say this because all I have done is Copy and Paste from your class into my calss in NetBeans.

    I'd appreciate it if you could tell me which bits I can remove, I think I have a rough idea myself, but I don't want to destroy the whole thing !

    Thanks
    "Extraordinary Claims Require Extraordinary Evidence" .... American Astrochemist Carl Sagan.

Similar Threads

  1. Program to take name as input and write it backwards
    By snake101 in forum Java Theory & Questions
    Replies: 7
    Last Post: June 10th, 2009, 04:35 AM
  2. Database connection without using netbease
    By haygaurav in forum Java IDEs
    Replies: 9
    Last Post: December 9th, 2008, 07:14 AM
  3. Replies: 4
    Last Post: May 22nd, 2008, 10:59 AM