Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Java - Array or ArrayList?


  • Please log in to reply

#1
rhymin

rhymin

    Member

  • Member
  • PipPipPip
  • 210 posts
First of all, this program is going to do the following:

  • Allow input of two salesperson's names AND input of their yearly sales
  • Calculate how much each salesperson earns each year by adding their yearly salary and commission from sales
  • Compare the two salesperson's yearly compensation (salary AND commission) and display the name of the salesperson that earned the higher amount
  • Calculate the difference between the 2 earnings and display that value as well

Questions (I know how to perform the calculations and how to display the results, but I am confused about a couple things):

1) This would use an array and not arraylist, correct? (I think because we know only 2 salespersons are entering information, it would be an array)

2) I'm not quite sure how to combine user input with arrays, could somebody show a simple example?
  • 0

Advertisements


#2
Bismillah

Bismillah

    Member

  • Member
  • PipPipPip
  • 514 posts
Array or Arraylist? It depends if you are using multiple datatypes, if it is just strings you would use an Array, Many types of datatypes and you would use an ArrayList.

For an ArrayList you need to create an ArrayList Class.
An example is here http://javarevisited...a-tutorial.html

An example of an array:
String Fruit[] = {"Apple", "Pear", "Banana", "Strawberry"}

int i;

for (i = 0;i < Fruit.lenth;i++ ){
System.out.println("Some fruit:" + Fruit[i]);

}

Many of these questions can be answered by a simple google search, also please stick with one topic and post all your questions in to that one.
  • 0

#3
rhymin

rhymin

    Member

  • Topic Starter
  • Member
  • PipPipPip
  • 210 posts
I will be using 2 datatypes.

String for the names and double for sales/salary.

Thanks.

Edited by rhymin, 08 March 2013 - 06:47 AM.

  • 0

#4
Bismillah

Bismillah

    Member

  • Member
  • PipPipPip
  • 514 posts
then you need an ArrayList or LinkedList
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP