Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Create Array Unknown Size Assignment  RSS feed

 
Warren Lucero
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an assignment to create an array of Ticket instances a driver named TicketDriverArray and fill in data from the keyboard. Built to handle arrays of unknown size. Cannot seem to get the totalTicketsSold and totalValueTickets to work.

Ticket




TicketDriverArray

 
Carey Brown
Bartender
Posts: 2992
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really need to go back and repost your code using "Code" tags.

What is the purpose of TicketDriverArray? Looks like it would break if you entered 21 tickets.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Warren, as Carey said, please use code tags. I'll do it for you this time, but in the future, your post may be put on probation until you use the tags.
 
Warren Lucero
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to setup unknown array size. Enter event names, cost of tickets, and number of tickets sold with while loop with yes/no to end. Cannot see to get the sum of total ticket sold and total sales int he Ticket Driver Array line 32 on.



>
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Warren Lucero wrote:I have an assignment to create an array of Ticket instances a driver named TicketDriverArray and fill in data from the keyboard. Built to handle arrays of unknown size. Cannot seem to get the totalTicketsSold and totalValueTickets to work.

OK, well those last two things don't sound like anything to do with handling an array of unknown size, so I'd forget them for now and concentrate on your problem.

In fact, unless you know that your "array of unknown size" logic is working, I'd set this program aside completely and write a simple test class called UnknownSizeArray that
1. Takes an arbitrary number of Strings (or lines) from the keyboard.
2. Adds them to a String[].
3. Prints out the array afterwards.
And don't do anything else until you know that test program works. Every time, and for any number of strings you decide to input.

That allows you to deal with the "array of unknown size" logic in as simple a way as possible, and not get distracted by other stuff.

Once you have your test program working, it should be relatively simple to change your array to a Ticket[] and enter Ticket information. And once you have THAT working, simply copy the code back to your TicketDriverArray class.

Right now, that class has far too much stuff in it, and you can't see the wood for the trees, so isolate the problem.

HIH

Winston
 
Carey Brown
Bartender
Posts: 2992
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well ALL arrays have a known size. Lists are designed for storing a number of items where the quantity is not known in advance. If your goal is to act like a list then you have to create your own class that behaves similar to ArrayList. An ArrayList has-an array. It also has a counter as to how many items are currently stored in the array. If adding a new item would overflow the array, then a new larger array must be created and the old array copied to the new array.

If this is not what you mean by an array of an unknown size, then you will need to be clearer as to what your requirements are.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem I see is that you are using totalTicketsSold and totalValueTickets to accumulate the total and display the total. If you're trying to use the method this way:

...the problem is that the method returns void. Create another two methods that return the tickets sold and the total value.
 
Warren Lucero
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgive me if I am using the wrong terminology. This is my first Java class. I was able to get it running after fixing typing errors and changing values. Here is my finished code. Thank all you for your help.

 
Carey Brown
Bartender
Posts: 2992
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've done very well with creating the three methods printTickets(), printTotalTicketsSold(), and printTotalValueTickets().

Do you plan on addressing the "create array of unknown size" issue? Your current code will break when attempting to add the 21st ticket.
 
Warren Lucero
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Took some trial and error with creating those methods but once I isolated them individually, I was able to work through them.

It looks like there is another assignment for this module covering unknown size handling. She did state in the homework instructions" Let’s assume that we will not have over 20 Ticket instances so make your program to handle any number of them up to 20 (you do not need to write an increaseSize() method)."

I appreciate everyone help. Sometimes I get hard headed when I stuck on an issue. With a little advice and stepping back to see the big picture helps.

Thanks again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!