Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account

# Java - Array or ArrayList?

### #1 rhymin Posted 08 March 2013 - 02:58 AM

rhymin

Member

• Member
• 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

### #2 Bismillah Posted 08 March 2013 - 04:33 AM

Bismillah

Member

• Member
• 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 Posted 08 March 2013 - 06:47 AM

rhymin

Member

• Topic Starter
• Member
• 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 Posted 08 March 2013 - 07:45 AM

Bismillah

Member

• Member
• 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