Question

In: Computer Science

In java Step 1) Assume that you have tracked monthly BSIT inquires for 10 months. Save...

In java

Step 1) Assume that you have tracked monthly BSIT inquires for 10 months. Save the following data into a text file in notepad in the order listed 40 22 17 35 28 17 22 28 25 19

Step 2) Write a java program that reads the monthly BSIT inquires for 10 months from the text file that you created in step 1. Read the monthly inquires from the input file into an array in one execution of the program. Write a sort method to sort the inquiry values lowest to highest. Write a method to calculate the average of the monthly inquiries. Write a method to determine the maximum value. Your program should call the sort, average and maximum methods. Create an output file to which you write the sorted array output, the average value and maximum value.

Solutions

Expert Solution

Please let me know if anything is required

Step1:

Copyable code:

import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.util.*;

class Main
{
public static void main(String[] args) throws IOException
{
  
String filename;
System.out.print("Enter the file name to write the monthly BSIT inquires: ");//filename input from the iser
Scanner sc = new Scanner(System.in);
filename=sc.next();
FileWriter fw=new FileWriter(filename); //to write on the file
  
System.out.println("Enters the BSIT inquires: ");
for (int i = 0; i < 10; i++)
{
int t;
t=sc.nextInt();//taking monthly inquires from the user
fw.write(t+" "); //Writing 10 inquires into the file
}
System.out.println("BSIT inquires written to the file successfully");
//close the file
fw.close();
}
}

Sample output:

Step2:

Copyable code:

import java.io.FileWriter;
import java.io.FileReader;
import java.io.IOException;
import java.io.*;
import java.util.*;

class Main
{
public static void main(String[] args) throws IOException
{
  
String filename;
System.out.print("Enter the file name to write the monthly BSIT inquires: ");//filename input from the iser
Scanner sc = new Scanner(System.in);
filename=sc.next();
FileWriter fw=new FileWriter(filename); //to write on the file
  
System.out.println("Enters the BSIT inquires: ");
for (int i = 0; i < 10; i++)
{
int t;
t=sc.nextInt();//taking monthly inquires from the user
fw.write(t+" "); //Writing 10 inquires into the file
}
System.out.println("BSIT inquires written to the file successfully");
//close the file
fw.close();
  
Main obj = new Main();
int array[] = new int[10];
//method to load data to array
array = obj.readData(filename);
System.out.println("The data loaded from the file: ");
for(int i=0;i<10;i++)
{
System.out.print(array[i]+" ");
}
  
//method to sort array
array = obj.sort(array,10);
System.out.println("\nThe data after sorting: ");
for(int i=0;i<10;i++)
{
System.out.print(array[i]+" ");
}
//method to find the average
float average = obj.average(array,10);
System.out.println("\nThe Average of BSIT inquires is : "+average);
//method to find the maximum
int maximum = obj.max(array,10);
System.out.println("The maximum of BSIT inquires is : "+maximum);
  
  
}
  
//loading the data from the file
int [] readData(String filename)throws IOException
{
int array[] = new int[10];
int number;
Scanner scanner = new Scanner(new File(filename));
  
int i=0;
while(scanner.hasNextInt())
{
array[i++] = scanner.nextInt();
}
  
  
return array;
}
  
//sorting the array
int [] sort(int array[],int size)
{
for(int i=0;i<size;i++)
{
int minimum_index = i;
for (int j = i+1; j < size; j++)
{
if (array[minimum_index] > array[j]) //checking for the minimum value index
{
minimum_index = j;
}
}

//swapping the minimum value to the left side of the array
int temp=array[i];
array[i]=array[minimum_index];
array[minimum_index]=temp;
  
}
return array;
  
}
  
//returning the average
float average(int array[],int size)
{
float avg=0;
for(int i=0;i<size;i++)
{
avg+=array[i];
}
return avg/(size);//returning the average
}
  
//returning the maximum
int max(int array[],int size)
{
return array[size-1];
}
  
}

Sample output:


Related Solutions

1. Estimation of Mean Monthly Rentals a. Assume a sample of 10 monthly rentals from a...
1. Estimation of Mean Monthly Rentals a. Assume a sample of 10 monthly rentals from a large housing complex of 300,000 units is: 980, 1230, 1320, 1440, 1180, 1050, 1520, 1630, 880, 920. Suppose the landlord association claims that the tue average rental of the low income 31/2 room apartment is $1100. The housing authority believes that the average rental is higher. State and test the null hypothesis of the landlord association's claim versus the alternative hypothesis of the housing...
You just borrowed $10,000 from the crooked bank at 10% with monthly payments for 60 months....
You just borrowed $10,000 from the crooked bank at 10% with monthly payments for 60 months. you had to pay an origination fee of $250 at the time you borrowed the money. What is the APR on the loan?
1) Suppose you have $5000 to save within the financial system. How would you save this...
1) Suppose you have $5000 to save within the financial system. How would you save this money? 2) Choose where/how you would save this money within the financial system. 3) Discuss which part of the financial system your selection is included in. 4) Why did you choose to save your money in this way? Refer to factors such as risk, interest rates, inflation, etc. to support your response. You should discuss which part of the financial system you would use...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $8,000 per year with the first investment made one year from now. You think you can earn 5.5​% per year on your investments and you plan to retire in 32 ​years, immediately after making your last $8,000 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $8,000 per​ year, you wanted to...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $ 6,500 per year with the first investment made one year from now. You think you can earn 5.0​% per year on your investments and you plan to retire in 36 ​years, immediately after making your last $ 6,500 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $ 6,500 per​ year,...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $5,000 per year with the first investment made one year from now. You think you can earn 10.0​% per year on your investments and you plan to retire in   43 ​years, immediately after making your last $5,000 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $5,000 per​ year, you wanted to...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $6,000 per year with the first investment made one year from now. You think you can earn ​10.0% per year on your investments and you plan to retire in 34 ​years, immediately after making your last $6,000 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $6,000 per​ year, you wanted to...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $5,000 per year with the first investment made one year from now. You think you can earn 10.5​% per year on your investments and you plan to retire in 31 ​years, immediately after making your last $5,000 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $5,000 per​ year, you wanted to...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $5,000 per year with the first investment made one year from now. You think you can earn 10.5​% per year on your investments and you plan to retire in 31 ​years, immediately after making your last $5,000 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investing $5,000 per​ year, you wanted to...
You are trying to decide how much to save for retirement. Assume you plan to save...
You are trying to decide how much to save for retirement. Assume you plan to save $4,500 per year with the first investment made one year from now. You think you can earn 5.5​% per year on your investments and you plan to retire in 26 ​years, immediately after making your last $4,500 investment. a. How much will you have in your retirement account on the day you​ retire? b.​ If, instead of investingv$4,500 per​ year, you wanted to make...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT