hey guys i'm pulling my hair out trying to solve this! i have been here for like 2 hours and it's probably something really easy. it's an array question:
Every year at Christmas, the Institute of Technology Termonfeckin sends out thank you cards to its wealthiest donors. This year the college is trying to save money on card preparation and postage costs, so has decided to only send cards to donors who donated more than 100 euro. They will also send a hamper to the company who gave the most. They have given you a list of 5 companies (below) and the amount they donate. You must write a program which initialises and stores this exact data in an array. You must then loop through the array and print out the following information:
1. Which companies will be sent cards
2. Which company will be sent a hamper
3. The total number of cards to be sent
Finally, the program must sort the arrays in order of most money donated and print the results out.
- Company list: “Termonfeckin Ferrys”, “Louth Industries”, “Ninja Enforcement Ltd”, “Termonfeckin Enterprises”, “Pirate Limb Replacement Corp.”
- Amount donated by each company: 120.50, 75.10, 500.00, 50.25, 350.50
i'm stuck on the first part "which companies will be sent cards". i have to print out all the companies who donated over 100 (which is 3 companies). what i'm trying to do is create an array to store the companies who donated over 100 then i will print this array out (thus completing the first part) what i'm trying to do is loop around the amount array and when the array location is > 100 (let's say it's amount[0]) i want to get it's equal equivalent in the names array (names[0]) and put that String in the cards array.
there is probably a way better and easier way of doing it, if there is please tell me or atleast let me know what i'm doing wrong please i'm only in my first semester so if i'v explained something wrong please let me know!
this is the code i have so far:
import java.util.Scanner;
class ArrayTest
{
public static void main(String args [])
{
Scanner input = new Scanner(System.in);
// arrys which will store names and donations
String names[] = { "Termonfeckin Ferrys", "Louth Industries", "Ninja Enforcement Ltd", "Termonfeckin Enterprises", "Pirate Limb Replacement Corp." };
double amount[] = { 120.50, 75.10, 500.00, 50.25, 350.50 };
String cards[] = { }; // array which will hold the donations above 100 who will receive cards
for(int i = 0; i < amount.length; i++)
{
if(amount.length > 100)
{
cards[i] = names[i]; // the part i'm having trouble with
}
}
System.out.println(cards);
}
}