Please Use JAVA The college of art and science at C State University has obtaine
ID: 3683898 • Letter: P
Question
Please Use JAVA
The college of art and science at C State University has obtained pledges from its faculty for the match of Dimes for March for Babies. Each faculty participant has benn sponsord by a major corporation. The fondation mission is the improvement of the health of babies by preventing birth defects, premature birth and infant mortality. March for babies will be held on saturday, December 12, 2010. They need you to write a program to read the information from the database. Firstly, they need you to write a program to read the information from the database (textefile). the database(march4babies.txt) contain the following information.
LastName First Initial. -String
Departement-String
Miles Walked-Integer
Pledge amount per mile-Double
Sample line input:
Bajwa J.,CSC,25,1000.00
Secondly, They need you to ptrepare a report containing the following informstion:
1-Read and display the contents of the file.
2-Compute the total amount of pledges obtained per person.
3-Display a list of race participants name and total pledge amounts sorted by total pledge amount.
4-Display alist of all participants who walk at least fifteen miles
5-Compute and display the total and average pledges for BAJWA State University.
6- Display the following informations by departement:
a-Total participant
b-Total amount of pledges in $
7- The departement with the most pledges will receive a prize. determine and display which departement get the prize.
Contents of march4babies.txt.
Bajwa J.,CSC,25.1000.00
Matlock B., ENG,10,110.00
Fletcher J,ENG, 5,100.00
Frazier W., CSC,12,220.00
Caldwell B., CSC, 20,3000.00
Bethea J., CSC,25,750.00
Flinston F., ENG, 5,40.00
RubbleB,MAT,10,50.00
Keaton W., ENG,10,10.00
Graham M., CSC,13,100.00
Barkly J, MAT,10,50.00
Madison K., ENG,10,25.00
Posten F., CSC, 10,300.00
Browne J., MAT,5,60.00
Black B., ENG,10,300.00
Patton C., MAT,7,60.00
Lofton C., CSC, 6,40.00
Batton P., MAT, 10,100.00
Explanation / Answer
import java.io.BufferedReader;
import java.io.FileReader;
public class march {
public static void main(String[] args) throws Exception {
//reading text file
BufferedReader br = new BufferedReader(new FileReader("march4babies.txt"));
String line = null;
//creating arrays for fields
String[] participants = new String[50];
String[] departments = new String[50];
int[] miles = new int[50];
int i=0;
double total=0,average;
int length;
double[] amount = new double[50];
System.out.println("content of database: ");
while ((line = br.readLine()) != null) {
String[] values = line.split(",");
System.out.println(Arrays.toString(values));
//storing data from textfiel into individual fields
participants[i] = values[0];
departments[i] = values[1];
miles[i] = Integer.parseInt(values[2]);
amount[i] = Double.parseDouble(values[3]);
i++;
//calculating total amount
total = total + amount[i];
}
//calculating average of amount
length=participants.length;
average = total/length;
System.out.println("List of participants:");
for(i=0;i<participants.length;i++)
System.out.println(participants[i]);
System.out.println("participants who walked atleast 15 miles ");
for(i=0;i<participants.length;i++)
{
if(miles[i]>14)
System.out.println(participants[i]);
}
System.out.println("total amount: "+total);
System.out.println("average of amount:"+average);
String[] listdep = new String[20];
int numcsc=0,numat=0,numeng=0;
double amountcsc=0,amountmat=0,amounteng=0;
//calculating number of participants and total amount per department
for(i=0;i<length;i++)
{
if(departments[i].equals("CSC"))
{
numcsc++;
amountcsc = amountcsc + amount[i];
}
else if(departments[i].equals("MAT"))
{
nummat++;
amountmat = amountmat + amount[i];
}
else
{
numeng++;
amounteng = amounteng + amount[i];
}
}
System.out.println("total participant in csc:"+numcsc);
System.out.println("total amount in csc:"+amountcsc);
System.out.println("total participant in mat:"+nummat);
System.out.println("total amount in mat:"+amountmat);
System.out.println("total participant in eng:"+numeng);
System.out.println("total amount in eng:"+amounteng);
double max;
//displaying the prize winner
if(amountcsc>amountmat && amountcsc>amounteng)
System.out.println("csc department gets prize");
else if(amountmat>amountcsc && amountmat>amounteng)
System.out.println("mat department gets prize");
else
System.out.println("eng department gets prize");
br.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.