8 Replies - 674 Views - Last Post: 20 November 2011 - 05:15 PM Rate Topic: -----

#1 mitchnufc  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 49
  • Joined: 31-March 11

Help with use of Multiple Arrays in Jave

Posted 20 November 2011 - 03:48 PM

Hello,

I am after some advise creating a JAVA based GUI system which handles booking for customers on a train journey, so far I have an arraylist for customer which will create customers and add them to the array via the Java GUI system I have deigned. I also have two arraylists one for outbound journey and one for return not data is passed to this as the details of the journeys are already defined within the class. Now I need to create a booking class, this is the section I am struggling with. This must create an array of bookings per train journey it must also store the customer details held for that particular customer using the details stored in my customer arrayList. can anyone help me with this?



Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Help with use of Multiple Arrays in Jave

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2203
  • View blog
  • Posts: 5,235
  • Joined: 10-September 10

Re: Help with use of Multiple Arrays in Jave

Posted 20 November 2011 - 03:54 PM

What do you need help with? What's your question?

You already have an outbound and inbound journey class. It seems a "booking" might be a collection of inbound and outbound journeys, though one of the legs could be null or 0, like a one-way ticket. Maybe the booking class you're thinking of could be a Ticket class, but maybe that's a difference in our languages.

What were you thinking? What's the assignment say to do?
Was This Post Helpful? 0
  • +
  • -

#3 mitchnufc  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 49
  • Joined: 31-March 11

Re: Help with use of Multiple Arrays in Jave

Posted 20 November 2011 - 04:00 PM

The Assisgnment I have to do will basically allow you to create customers then book them onto a journey which will be a return journey, what I can't get my head around is how to create a number of bookings per flight and when I create a booking it will use the customerArrayList details stored for that customer and create a booking Array entry which will store all of the customers details automatically with the addition of a bookingID which will be allocated my the booking class.

So far I have tried this for my booking class.


package Booking;
import CustomerClasses.*;
import java.util.*;



public class Booking
{

private static int bookingIDGenerator = 000000001;
private CustomerArrayList customers;
private String bookingID;
private ArrayList <CustomerArrayList> bookings;

public Booking()

{
    bookings = new ArrayList <CustomerArrayList>();

}

}



Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2203
  • View blog
  • Posts: 5,235
  • Joined: 10-September 10

Re: Help with use of Multiple Arrays in Jave

Posted 20 November 2011 - 04:07 PM

A booking will become an array of customers, identified uniquely by a booking number. Only so many bookings are allowed per flight. The number of bookings allowed per flight is an arbitrary number that should have been given to you. If not, make it up. Each customer added to the flight decreases the number of available bookings.

I imagine that a booking class will have a method:

addBooking( Customer customer ) {}

that will check if there is room on the flight, add the customer to the flight if there's room, decrease the number of bookings available, assign a seat?, and return a seat or confirmation number (?).
Was This Post Helpful? 1
  • +
  • -

#5 mitchnufc  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 49
  • Joined: 31-March 11

Re: Help with use of Multiple Arrays in Jave

Posted 20 November 2011 - 04:14 PM

for this assignment, we don't have to restrict the number of seats free on a flight we just have to place a customer onto that flight by creating a booking. There must be an array of customers per flight basically but each customer must be assigned a bookingID for the flight as we must also be able to cancel a booking by using a search bookingID method via the Java GUI. I am sorry if this doesn't make much sense but all we have done in class is one arrayList never used arrays within arrays etc.......
Was This Post Helpful? 0
  • +
  • -

#6 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2203
  • View blog
  • Posts: 5,235
  • Joined: 10-September 10

Re: Help with use of Multiple Arrays in Jave

Posted 20 November 2011 - 04:22 PM

It makes perfect sense.

Don't get stressed about "arrays within arrays." I'm not even sure you'll have that here. You'll have a class that includes an array of other classes, but that's not big deal. You've probably done that with arrays before, but you did it with ints, Strings, or some other type.

public Customer
{
}

protected Booking
{
  Customer[] customerArray;
}

There's nothing hard or complicated here, and I'll bet you've done it before.
Was This Post Helpful? 0
  • +
  • -

#7 mitchnufc  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 49
  • Joined: 31-March 11

Re: Help with use of Multiple Arrays in Jave

Posted 20 November 2011 - 04:31 PM

How does this work, Is that creating an array of customer based on the customerArray?

thanks for the help but I'm still struggling.
Was This Post Helpful? 0
  • +
  • -

#8 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2203
  • View blog
  • Posts: 5,235
  • Joined: 10-September 10

Re: Help with use of Multiple Arrays in Jave

Posted 20 November 2011 - 04:42 PM

My little snippet of code declared an array of Customer objects called customerArray. You said you've used arrays before. If so, you've surely done something like:

int[] intArray;   // declares an array of ints called intArray
intArray = new int[5];  // creates an int array of 5 items

In fact, you said you're familiar with ArrayList - same animal of a different color. Instead of an array of primitives, like int, or objects you're more familiar with, String, you're creating an array (or ArrayList) of another object called Customer.
Was This Post Helpful? 0
  • +
  • -

#9 mitchnufc  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 49
  • Joined: 31-March 11

Re: Help with use of Multiple Arrays in Jave

Posted 20 November 2011 - 05:15 PM

I know how to create a new but I want to create an array based on customers held in my customerarraylist with the addition of a bookingid
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1