print/search function in bluej?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: print/search function in bluej?

Hybrid View

  1. #1
    Join Date
    May 2012
    Posts
    4

    Exclamation print/search function in bluej?

    hi,

    what is the code required to:

    search for and print all objects that match the term the user enters

    i.e - when i select this function it should pop up a message that allows me to enter a string value. it then searches through my arraylist for any objects with matching string values and prints theme

    i remember using this function before but cannot remember the code.

  2. #2
    Join Date
    May 2012
    Posts
    4

    Re: print/search function in bluej?

    Quote Originally Posted by zelhopper View Post
    prints theme
    i meant; prints them.

  3. #3
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: print/search function in bluej?

    The idea behind homework is you do it yourself and learn from the experience. If you show us what you've done so far and explain where you are stuck we will help you.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  4. #4
    Join Date
    May 2012
    Posts
    4

    Re: print/search function in bluej?

    thank you for responding however i have been trying to do this myself for the past month, i have the "objects first with java" book and still cannot find what i am looking for

    i have 2 classes car and stock
    car:
    Code:
    /**
     * The Car class represents a car object. Information about the car is stored and can be retrieved.
     */
    public class Car
    {
        private String make;
        private String model;
        private String reg;
        private int paid;
        private int sold;
    
        /**
         * Initializing the Car class.
         */
        public Car(String theMake, String theModel, String theReg, int PricePaid, int PriceSold)
        {
            make = theMake;
            model = theModel;
            reg = theReg;
            paid = PricePaid;
            sold = PriceSold;
        }
    
        /**
         * Print details about this Car
         */
        public void print()
        {
            System.out.println("Make: " + make + " - Model: " + model + " - Reg: " + reg + " - Paid: " + paid
                                + " - Sold: " + sold + ".");
        }
    }
    stock:
    Code:
    import java.util.ArrayList;
    import java.util.Iterator;
    /**
     * The Stock class is a functions like a database. It is the facility to store all the information
     * on cars that delboy has.
     */
    public class Stock
    {
        private ArrayList<Car> cars;
    
        /**
         * Construct an empty Stock database.
         */
        public Stock()
        {
            cars = new ArrayList<Car>();
        }
    
        /**
         * Add a new car to the Stock class.
         */
        public void addCar(Car theCar)
        {
            cars.add(theCar);
        }
    
        /**
         * Print a list of all stored Cars.
         */
        public void listCars()
        {
            Iterator<Car> it = cars.iterator();
            while(it.hasNext()) {
                System.out.println(it.next());
            }
        }
    }
    the problem is that i want a search function that will print out a list of results e.g. search for "ford" and it will print out all the cars of make "ford"

  5. #5
    Join Date
    Mar 2010
    Posts
    16

    Re: print/search function in bluej?


  6. #6
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: print/search function in bluej?

    Thanks for the heads up Darryl
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  7. #7
    Join Date
    May 2012
    Posts
    4

    Re: print/search function in bluej?

    yes i posted this in another forum but that is just because i need it solved urgently

  8. #8
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: print/search function in bluej?

    Cross posting wastes the valuable time of the people who you are asking to help you because we end up duplicating answers given on other sites.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center