Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with turning pseudocode to actual code

Newbie
 
Join Date: Feb 2009
Posts: 24
#1: Apr 6 '09
So I have a program that asks the user to input their information and select services by entering 1 2 3 or etc. and it stores it as an array. This program also stores services it offers as a 2d array with column one as the service name and column two as the cost of service.

I would like to be able to grab a customer from the array and see which services the customer chose then calculate the total cost of the services he chose.

Here is my very rough pseudocode:
Say I want customer 2's info
He chooses service 1 and 3
He chose serviceEntry[1][0] and serviceEntry[3][0]
Get serviceEntry[1][1] + serviceEntry[3][1] and store as sum
return String serviceEntry[1 -1][0] + serviceEntry[3 - 1][0] will cost the variable sum.

My problem is I have an unknown service array length and when the customer enters 1 2 3 or etc, its stored as a string. How do I get those individual numbers and place it as an index in my 2d array. Such as if I had 10 services, how would I get the integer 10 instead of 1 and 0.

Thanks for any help and I'm sorry if the way I described the problem is confusing.

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Apr 6 '09

re: Help with turning pseudocode to actual code


Don't use 2D arrays for that. Write a Service class with name and cost as instance variables. You can then put the services in an ArrayList (which does not have a fixed length). Always think objects in Java rather than arrays.
Reply