Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I call the loadDataFromFile function in the main method? public static void main ( String [ ] args ) { loadDataFromFile (

How do I call the loadDataFromFile function in the main method? public static void main(String[] args){
loadDataFromFile("");
Scanner scanner = new Scanner(System.in);
int choice;
// Display the menu and process user input until the user chooses to exit.
do {
displayMenu();
System.out.print("Enter your choice: ");
choice = scanner.nextInt();
switch (choice){
case 1:
displayAllRecords();
break;
case 2:
displaySelectedRecord(scanner);
break;
case 3:
displayCumulativeStatistic(scanner);
break;
case 4:
displayHistogram(scanner);
break;
case 5:
System.out.println("Exiting the program. Goodbye!");
break;
default:
System.out.println("Invalid choice. Please try again.");
}
} while (choice !=5);
scanner.close();
}
private static void displayMenu(){
System.out.println("
Menu:");
System.out.println("1. Display all records");
System.out.println("2. Display selected record");
System.out.println("3. Display cumulative statistic");
System.out.println("4. Display histogram");
System.out.println("5. Exit");
}
/**
* Loads data from a file into the program.
*
* @param fileName The name of the data file.
*/
private static int loadDataFromFile(Record[] dataRecords)
{
Scanner scanner = new Scanner(System. in);
try
{
File file = new File("PhoenixSunsData.txt");
Scanner inFile = new Scanner(file);
do
{
dataRecords[numRecords]= new Record();
dataRecords[numRecords]._key = inFile.next();
dataRecords[numRecords]._field1= inFile.next();
dataRecords[numRecords]._field2= inFile.nextDouble();
dataRecords[numRecords]._field3= inFile.nextDouble();
++numRecords;
}
while(!dataRecords[numRecords-1]._key.equals(0));
--numRecords;
}
catch(IOException ioe)
{
System.out.println("File access error");
numRecords =0;
}
return numRecords;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Iv Special Issue On Database Systems For Biomedical Applications Lncs 6990

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Christian Bohm ,Johann Eder ,Claudia Plant

2011th Edition

3642237398, 978-3642237393

More Books

Students also viewed these Databases questions

Question

Upon what three criteria are factors of safety based?

Answered: 1 week ago