Write a JAVA program to calculate the total amount, the maximum and the minimum
ID: 3861327 • Letter: W
Question
Write a JAVA program to calculate the total amount, the maximum and the minimum donations an organization got the last year. It uses a loop to ask the user to enter a series of donation.
The end of input is-1. Then the program calculates and displays the total amount, the maximum and the minimum donations for the organization. Below is a sample of the input and output.
Please enter the donation: (-1 ends the input):100
Please enter the donation: (-1 ends the input):200
Please enter the donation: (-1 ends the input):-1
The total amount of donations is 300, the maximum donation is 200, and the minimum donation is 100.
Explanation / Answer
public static void main(String[] args0
{
int totalamount=0;
int counter;
int donations;
double max=0;
double min=0;
Scanner Numscanner=new Scanner(System.in);
System.out.println("total number of denotions u want to enter");
counter=NmumScanner.nextInt();
System.out.println("enter the donations of the last year");
for(int i=1;i<=counter;i++)
{
donations=Numscanner.nextInt();
totalamount=toyalamount+donations;
Syatem.out.println();
if(donations>max)
{
max=donations;
}
if(donations<min)
{
min=donations;
}
if(donations>-1 && donations<300)
{
totalamount=totalamount+donations;
}
else//where donations=-1//
{
System.out.println("invalid input");
}
}
}
}