Can you help with this issue.I have to implement task that have function divides given amount of money among a given number of people and returns a list of values how much each person should receive.The numbers in the output can be with up to 2 decimal places and The difference between 2 amounts from the returned list must not be greater than 0.01, or one.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Insert amount");
double amount = scanner.nextDouble();
System.out.println("Insert people");
int numberOfPeople = scanner.nextInt();
List<Double> values = printList(amount, numberOfPeople);
printresults(values);
}
private static void printresults(List<Double> values) {
for (Double amount : values) {
System.out.printf("%.2f ",amount);
}
}
private static List<Double> printList(double amount, int numberOfPeople) {
double result = 0;
List<Double> moneys = new ArrayList<>();
for (int i = 1; i <= numberOfPeople; i++) {
result = (amount / numberOfPeople);
moneys.add(result);
}
return moneys;
}
}