why does this code print out results in numbers not the actual names of the students?? from the following data from the txt file:

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 27SA
icon
Related questions
Question
100%

why does this code print out results in numbers not the actual names of the students?? from the following data from the txt file:

om

IT 500 Business Analytics:94.6;

IT 512 Project Management:88;

IT 513 Information Security:91.2;

-------------------------------------------

Tim

MBA 503 Foundations of Business Statistics:85;

IT 501 Fundamentals of Java Programming:70;

IT 500 Business Analytics:64;

IT 516 Social Media Analytics:77;

IT 515 Organizational Behavior:50;

-------------------------------------------

Smith

MBA 503 Foundations of Business Statistics:20;

IT 509 Data Management:89;

IT 512 Project Management:90;

-------------------------------------------

Davis

MBA 503 Foundations of Business Statistics:77;

IT 501 Fundamentals of Java Programming:89;

IT 510 Information Technology Management:88;

IT 517 Big Data Analytics:90;

-------------------------------------------

Judge

MBA 503 Foundations of Business Statistics:95;

IT 501 Fundamentals of Java Programming:88;

 

// Code

import java.io.*;

 

public class classgpa {

 

public static void main(String[] args) {

 

//Read the file

File file = new File("/Users/Desktop/1.txt");

 

//Declare a temporary variable

String temp="";

 

//Decalre variable to store the record

 

int r =0;

//Declare variable to store the n umber of lines

 

int line=0;

//Declare variable to store the total

double total = 0.0;

//Declare the variable to store the gpa

double gpa=0;

 

try{

//Declare a buffer reader

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

 

 

//Read line and store in the variable str

String str=br.readLine();

 

//Check if the string is not null

while ((str!= null))

    {

//Read a line

str = br.readLine();

 

    //Check if the line contains -- to indicate the next record

if (str.contains("--"))

                {

           

//Increase the number of records

r++;

 

    //Calculate gpa

gpa = total / line ;

 

//Initialize line to 0

line=0;

//Display the gpa

System.out.println("Gpa of Student "+r+": "+ String.format("%.2f", gpa));

//Initialize total to 0

total=0;

 

 

          }

            else

 

                {

 

            //Decalre a loop till the end of string

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

                    {

                    //Check if the character is : to retreive total marks

                    if( str.charAt(i) == ':')

 

                                  {

//Increament i

  i++;

//Check if end of line is reached

while(str.charAt(i)!=';')

                                        {

//Store the character in variable temp

temp=temp+(str.charAt(i));

 

 

//Increment i

i++;

 

                  }

//Increment the number of lines

line++;

 

//Calculate the total

total = total + Double.parseDouble(temp);

 

//Initialize temp to empty space

  temp="";

 

 

            }

 

            }

 

            }

 

    }

 

            }

//Declare catch

catch(IOException e){

 

e.printStackTrace();

 

 

}

 

//Catch statement for contains method

catch (Exception other) {

 

//Calculate the gpa for the last student

  gpa = total / line ;

 

    System.out.println("Gpa of Student "+ ++r + ": "+String.format("%.2f", gpa));

    //System.out.println("File ended");

                }

}

 

}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
LINUX+ AND LPIC-1 GDE.TO LINUX CERTIF.
LINUX+ AND LPIC-1 GDE.TO LINUX CERTIF.
Computer Science
ISBN:
9781337569798
Author:
ECKERT
Publisher:
CENGAGE L
Oracle 12c: SQL
Oracle 12c: SQL
Computer Science
ISBN:
9781305251038
Author:
Joan Casteel
Publisher:
Cengage Learning
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781285196145
Author:
Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos Coronel
Publisher:
Cengage Learning