Question
in java

H1, H2, H3, Examl, Exam2 , Exam3 100,100,98,98, 70,87 98,70,87,100,100,98 100, 100, 98,70,87,98
Create a program that allows us to: -Print out all column info when given a column -Compare which column is larger from every
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

public class pgm4

{

    public static void main(String[] args) {

        BufferedReader br = null;

        String line = "";

        //reading filename

        Scanner scanner = new Scanner(System.in);

        System.out.println("Enter filename : ");

        String filename = scanner.next();

        String[] headers = new String[100]; // to save header fields

        String[][] data = new String[100][100]; //to save data fields

        int row_len = 0;

        int col_len = 0;

        Boolean isFirstRow = true;

        //reading file and saving to array

        try {

            br = new BufferedReader(new FileReader(filename));

            while ((line = br.readLine()) != null) {

                // use comma as separator

                String[] row = line.split(",");

                if (isFirstRow){

                    //save header fields => first line

                    headers = row;

                    isFirstRow = false;

                    col_len = headers.length;

                }

                else{

                    //rest line is data values

                    data[row_len] = row;

                    row_len++;

                }

            }

        } catch (FileNotFoundException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        } finally {

            //closing file pointer

            if (br != null) {

                try {

                    br.close();

                } catch (IOException e) {

                    e.printStackTrace();

                }

            }

        }


        //reading colum name

        System.out.println("Enter column name : ");

        String column = scanner.next();

        int col_index = 0;

        for(int i=0; i<headers.length; ++i){

            //to find column index of entered column

            if(headers[i].equals(column))

            {

                col_index = i;

                break;

            }

         }

        //print all the data fields in column index

        for(int i=0;i<row_len;++i){

            System.out.println(data[i][col_index]);

        }

        

        for (int i=0; i<row_len; ++i){

            //iterate through each row

            int big_index = 0;

            int big = 0;

            for(int j=0; j<col_len; ++j){

                int val = Integer.parseInt(data[i][j]);

                //find biggest value in each row

                if (val>big){

                    //save the index of the biggest column

                    big = val;

                    big_index = j;

                }

            }

            //display the result

            System.out.println("column "+headers[big_index]+ " is larger : "+big);

        }

    }

}

INPUT AND OUTPUT
Enter filename :
class.txt
Enter column name :
exam1
64
6
34
column h1 is larger : 100
column h3 is larger : 98
column h1 is larger : 98

DATASET(class.txt)

h1,h2,h3,exam1,exam2,exam3
100,100,98,64,87,12
45,36,98,6,21,65
98,78,56,34,67,48

The option for uploading images is not working, so I can't upload screenshots. sorry. But the code will work fine as java doesn't need any indentation. Just copy paste in your pc and run.

Add a comment
Know the answer?
Add Answer to:
in java H1, H2, H3, Examl, Exam2 , Exam3 100,100,98,98, 70,87 98,70,87,100,100,98 100, 100, 98,70,87,98 Create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use Java language to create this program Write a program that allows two players to play...

    Use Java language to create this program Write a program that allows two players to play a game of tic-tac-toe. Using a two-dimensional array with three rows and three columns as the game board. Each element of the array should be initialized with a number from 1 - 9 (like below): 1 2 3 4 5 6 7 8 9 The program should run a loop that Displays the contents of the board array allows player 1 to select the...

  • 7.2 Write a Java program called to create an Excel spreadsheet Create a class called Food...

    7.2 Write a Java program called to create an Excel spreadsheet Create a class called Food to represent a Lunch food item. Fields include name, calories, carbs In a main method (of a different class), ask the user "How many things are you going to eat for lunch?". Loop through each food item and prompt the user to enter the name, calories, and grams of carbs for that food item. Create a Food object with this data, and store each...

  • create a hash table to implement spell checker in java 1. Create a file of 100...

    create a hash table to implement spell checker in java 1. Create a file of 100 words of varying length (max 8 characters). 2. All the words are in lower case. 3. design a hash table. 4. enter each word in the hash table. Once the hash table is created, run it as a spell checker.enter a word (interactive), find the word in the hash table. If not found enter an error message. Then prompt for next word. End the...

  • Row and columns sum Create a java program that: Input: Receive as input in command line...

    Row and columns sum Create a java program that: Input: Receive as input in command line the sizes m and n of a two dimensional array Receive as input in command line the minValue and maxValue between which the random numbers will be generated for your two dimensional array Generate: Generate a two-dimensional with numbers between minValue and maxValue (inclusive) with the given size (m x n) Compute: Compute the sum for each row and store the results in a...

  • Lab Exercise #15 Assignment Overview This lab exercise provides practice with Pandas data analysis library. Data...

    Lab Exercise #15 Assignment Overview This lab exercise provides practice with Pandas data analysis library. Data Files We provide three comma-separated-value file, scores.csv , college_scorecard.csv, and mpg.csv. The first file is list of a few students and their exam grades. The second file includes data from 1996 through 2016 for all undergraduate degree-granting institutions of higher education. The data about the institution will help the students to make decision about the institution for their higher education such as student completion,...

  • write a Java console application that Create a text file called Data.txt. Within the file, use...

    write a Java console application that Create a text file called Data.txt. Within the file, use the first row for the name and data title, and use the second row for column headers. Within the columns, insure that the first column is a label column and other columns contain numeric data. In your application, read file Data.txt into parallel arrays, one for each column in the file. Create method printArrays to print the header row(s) and the (unsorted) data in...

  • Write a Java program that allows the following: 1.Create an array list of 20 integers. The...

    Write a Java program that allows the following: 1.Create an array list of 20 integers. The 20 integers are generated randomly with possible values from 0 to 10. 2.Print the content of the array list. 3.Find how many of these values are multiple of 3. Show a screenshot of the output with your name and Id in the first line (if there is no screenshot of the output, the student shall get a zero mark for this question). Program typical...

  • have to create five different functions above and call it in the main fucntion. Project Exam...

    have to create five different functions above and call it in the main fucntion. Project Exam Statistics A CIS 22A class has two midterm exams with a score between 0 and 100 each. Fractional scores, such as 88.3 are not allowed. The students' ids and midterm exam scores are stored in a text file as shown below // id exam1 exam2 DH232 89 92 Write a program that reads data from an input file named exams.txt, calculates the average of...

  • Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I...

    Please help me write a Pseudocode (please do NOT answer in JAVA or Python - I will not be able to use those). Please ALSO create a flowchart using Flowgarithm program. Thank you so much, if answer is provided in Pseudocode and Flowchart, I will provide good feedback and thumbs up to the resonder. Thank you! Tic-Tac-Toe Game Write a program that allows two players to play a game of tic-tac-toe. Use a two- dimensional char array with three rows...

  • Create a JAVA application which generates 20 random numbers between 1 and 100 and writes them...

    Create a JAVA application which generates 20 random numbers between 1 and 100 and writes them to a text file on separate lines. Then the program should read the numbers from the file, calculate the average of the numbers, and display this to the screen.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT