Write a program to display information about schools in North Carolina that offe
ID: 3586635 • Letter: W
Question
Write a program to display information about schools in North Carolina that offer a BS in Computer Science. The data file "NCuniversity Data dat" contains the following information on each line: BS in CS Instate cost Out of state cost int int int double fraction of students who return after first year String name of the school 0-no, 1-yes, 2-online only Expected annual cost for an in-state student Expected annual cost for an out of state student retention name You will probably want to read the school name using the nextLine () method. You are to write a program that reads the file and displays the following information for those schools that offer a BS degree in Computer Science. Consider only thosÉ schools that offer a BS in Computer Science on campus. Best and worst retention rates showing the school name and retention rate as a percentage Highest and lowest in-state cost showing the school name and cost Some of the cost and retention data is incomplete. Missing data is given as-9999. Do not consider any data with the value -9999. Sample data 16059 18107 0.975 Alamance Comunity College Appalachian State University Asheville-Buncombe Technical Community College Barton College Beaufort County Community College Beimont Abbey College Bennett College tor Wonen 2160 e304 0.5779 1939 7029 0.6303 24180 24180 0.7149 2272 8416 0.5545 27622 27622 0.6357 16794 16794 0.5759 and more Sample output Best retention rate 97.19 at Uhiveresty ot North Carolina at Chapei Biil Horst retention rate is 39.27% at Shaw University Lowest in-state cost i8 4150 at elizabeth caty stace vasversity Highest in-state cost is 43623 at Duke UnivereiryExplanation / Answer
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
public class fileread{
public class MyClass
{
public int BS;
public double instate_cost, outofstate_cost, retention;
public String name;
}
static Scanner console = new Scanner(System.in);
public static void main(String[] args) throws FileNotFoundException {
Scanner reader = new Scanner(new File("filename.txt"));
MyClass [] array;
array = new MyClass[10];
for(int i=0;i<10;i++)
{
array[i]= new fileread(). new MyClass();
}
int i = 0;
double temp,temp2;
//double instate_cost, outofstate_cost, retention, high_instate_cost, low_instate_cost;
//String instate_cost_name , outofstate_cost_name, retention_name , name;
//int i = 0;
while(reader.hasNext())
{
array[i].BS = reader.nextInt();
array[i].instate_cost = reader.nextDouble();
array[i].outofstate_cost = reader.nextDouble();
array[i].retention = reader.nextDouble();
array[i].name = reader.nextLine();
//System.out.println(array[i].name);
i++;
}
temp = -1.0;
temp2 = 2;
double low_instate = 1000000,high_instate =-1;
String ans=" ",ans2=" ",ans3=" ",ans4=" ";
for(int j=0;j<i;j++) // here i is basically the size of the array of the MyClass
{
if(array[j].BS == 1)
{
if(array[j].retention > temp)
{
temp = array[j].retention;
ans = array[j].name;
}
if(array[j].retention < temp2)
{
temp2 = array[j].retention;
ans2 = array[j].name;
}
if(array[j].instate_cost > high_instate)
{
high_instate = array[j].instate_cost;
ans3 = array[j].name;
}
if(array[j].instate_cost < low_instate)
{
low_instate = array[j].instate_cost;
ans4 = array[j].name;
}
}
}
System.out.print("Best Retention Rate is ");
System.out.print(" " + temp * 100);
System.out.println(" " + ans);
System.out.print("Worst Retention Rate is ");
System.out.print(temp2 * 100);
System.out.println(" " + ans2);
System.out.print("High instate cost is ");
System.out.print(high_instate);
System.out.println(" " + ans3);
System.out.print("Low instate cost is ");
System.out.print(" " + low_instate);
System.out.println(" " + ans4);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.