Write a program that takes as input the number of visitors and for each visitor takes the amount of money they have spent in last 5 days. The program must calculate the average expenses (i.e. per day) for each visitor. The program should output the approximately amount of money each visitor will need to stay next 15 days.
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int n;
System.out.println("Enter number of visitors: ");
n=in.nextInt();
int [] money_spent = new int [n];
//for each visitor takes the amount of money they have spent in last 5 days
for(int i=0;i<n;i++){
money_spent[i]=in.nextInt();
}
//The program must calculate the average expenses (i.e. per day) for each visitor.
int [] money_spent_per_day = new int [n];
for(int i=0;i<n;i++){
money_spent_per_day[i]=money_spent[i]/5;
}
//The program should output the approximately amount of money each
//visitor will need to stay next 15 days.
int [] money_spent_15days = new int [n];
for(int i=0;i<n;i++){
money_spent_15days[i]=money_spent_per_day[i]*15;
}
System.out.println("Amount per day: ");
for(int i=0;i<n;i++){
System.out.println("Customer "+(i+1)+money_spent_per_day[i]);
}
System.out.println("Amount in 15 days: ");
for(int i=0;i<n;i++){
System.out.println("Customer "+(i+1)+money_spent_15days[i]);
}
}
}
Comments
Leave a comment