Answer to Question #235719 in Java | JSP | JSF for jeffy

Question #235719

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.


1
Expert's answer
2021-09-10T18:52:19-0400
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]);
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS