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 6 of 6

Thread: how to test a class ??

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default how to test a class ??

    hey i need help on testing a class it is confusing me on how to do it i was wondering how would i do it.

    i need to create 3 objects in another classes constuctor n store them in an arraylist


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how to test a class ??

    You'll have to provide more details.
    Use the new statement to create an instance of an object
    Use the add() method to add objects to an arraylist.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: how to test a class ??

    yeah i get that but i have to do it in another classes constuctor in the test class. like below i have to create a vehicle object in the class below's constuctor n store it , but in the test class ?

    import java.util.*;
    import java.awt.*;
    import java.io.*;
     
    /** The Reservation System class stores all the data about the vehicles in the rental company. Also to allow the use to see what vehicles are allowed to be
     * rented by the company.
     * 
     */
     
    public class ReservationSystem
    {
        private String name;
        private ArrayList<Vehicle> vehicleList;
     
        /**
         * Constructor for the Reservation System class which.
         */
        public ReservationSystem( String name)
        {
         this.name = name;
          vehicleList = new ArrayList <Vehicle>();
        }
     
     
       /** This method allows users to be able to add a vehicle object which will then be stored in the arraylist.
        */
       public void storeVehicle(Vehicle newVehicle)
        {
            vehicleList.add(newVehicle); //Adds to arraylist.
     
        }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how to test a class ??

    What is the problem with creating an object in any class and storing it in an arraylist?
    Can you post the code you are having problems with?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: how to test a class ??

    there is no problem i was just wondering how i would create a class that woould do it

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how to test a class ??

    What have you tried?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How can I write a class or something so I can run and test the following code?
    By michael305rodri in forum Java Theory & Questions
    Replies: 3
    Last Post: October 18th, 2012, 10:46 PM
  2. Replies: 4
    Last Post: September 3rd, 2012, 02:47 AM
  3. create a test class (main method) to start(run) the class in Java
    By curious725 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 1st, 2012, 03:21 AM
  4. Inheritance; Problem with Test class
    By Charlie.beat in forum What's Wrong With My Code?
    Replies: 19
    Last Post: April 8th, 2012, 10:59 PM