SlideShare a Scribd company logo
Write a Java program that opens the file, reads all the Grade from the file, and using a method
calculates and displays the following A) Displays the grades with their letter values (80 - B) B)
the sum of the Grades in the file C) the average of the Grades in the file
Solution
GradeRead.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class GradeRead {
public static void main(String[] args) throws FileNotFoundException {
Scanner scan1 = new Scanner(System.in);
System.out.print("Enter the file name: ");
String fileName = scan1.next();
File file = new File(fileName);
if(file.exists()){
Scanner scan = new Scanner(file);
calculateGradeDetail(scan);
}
else{
System.out.println("Input does not exist");
}
}
public static void calculateGradeDetail(Scanner scan){
int sum = 0;
int count = 0;
char gradeLetter = '0';
while(scan.hasNextInt()){
count++;
int n = scan.nextInt();
sum = sum + n;
if(n >=90 && n<=100){
gradeLetter = 'A';
}
else if(n >=80 && n<90){
gradeLetter = 'B';
}
else if(n >=70 && n<80){
gradeLetter = 'C';
}
else if(n >=60 && n<=70){
gradeLetter = 'D';
}
else {
gradeLetter = 'E';
}
System.out.println("Grade: "+gradeLetter+" - "+n);
}
System.out.println("The sum of the Grades in the file: "+sum);
double average = sum/(double)count;
System.out.println("the average of the Grades in the file: "+average);
System.out.println();
}
}
Output:
Enter the file name: D:grade.txt
Grade: D - 60
Grade: C - 70
Grade: B - 80
Grade: A - 90
Grade: A - 100
Grade: E - 40
Grade: E - 50
Grade: D - 60
The sum of the Grades in the file: 550
the average of the Grades in the file: 68.75
Grade.txt
60
70
80
90
100
40
50
60

More Related Content

Similar to Write a Java program that opens the file, reads all the Grade from t.pdf

Object oriented programming la bmanual jntu
Object oriented programming la bmanual jntuObject oriented programming la bmanual jntu
Object oriented programming la bmanual jntuKhurshid Asghar
 
Write a java program that allows the user to input the name of a fil.docx
 Write a java program that allows the user to input  the name of a fil.docx Write a java program that allows the user to input  the name of a fil.docx
Write a java program that allows the user to input the name of a fil.docx
ajoy21
 
Write a java program that allows the user to input the name of a file.docx
Write a java program that allows the user to input  the name of a file.docxWrite a java program that allows the user to input  the name of a file.docx
Write a java program that allows the user to input the name of a file.docx
noreendchesterton753
 
Write a java program that would ask the user to enter an input file .pdf
Write a java program that would ask the user to enter an input file .pdfWrite a java program that would ask the user to enter an input file .pdf
Write a java program that would ask the user to enter an input file .pdf
udit652068
 
PAGE 1Input output for a file tutorialStreams and File IOI.docx
PAGE  1Input output for a file tutorialStreams and File IOI.docxPAGE  1Input output for a file tutorialStreams and File IOI.docx
PAGE 1Input output for a file tutorialStreams and File IOI.docx
alfred4lewis58146
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
PragatiSutar4
 
Write a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfWrite a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdf
atulkapoor33
 
Java 3 Computer Science.pptx
Java 3 Computer Science.pptxJava 3 Computer Science.pptx
Java 3 Computer Science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
import java.io.BufferedReader;import java.io.File;import java.io.pdf
import java.io.BufferedReader;import java.io.File;import java.io.pdfimport java.io.BufferedReader;import java.io.File;import java.io.pdf
import java.io.BufferedReader;import java.io.File;import java.io.pdf
manojmozy
 
Here is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdfHere is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdf
pratyushraj61
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
 
Java Notes
Java Notes Java Notes
Java Notes
Sreedhar Chowdam
 
Java practical
Java practicalJava practical
Java practical
william otto
 
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/OCore Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
WebStackAcademy
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docx
michael1810
 
Use Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdfUse Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdf
f3apparelsonline
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdf
secunderbadtirumalgi
 
Lab4
Lab4Lab4
Code red SUM
Code red SUMCode red SUM
Code red SUM
Shumail Haider
 

Similar to Write a Java program that opens the file, reads all the Grade from t.pdf (20)

Object oriented programming la bmanual jntu
Object oriented programming la bmanual jntuObject oriented programming la bmanual jntu
Object oriented programming la bmanual jntu
 
Write a java program that allows the user to input the name of a fil.docx
 Write a java program that allows the user to input  the name of a fil.docx Write a java program that allows the user to input  the name of a fil.docx
Write a java program that allows the user to input the name of a fil.docx
 
Write a java program that allows the user to input the name of a file.docx
Write a java program that allows the user to input  the name of a file.docxWrite a java program that allows the user to input  the name of a file.docx
Write a java program that allows the user to input the name of a file.docx
 
Write a java program that would ask the user to enter an input file .pdf
Write a java program that would ask the user to enter an input file .pdfWrite a java program that would ask the user to enter an input file .pdf
Write a java program that would ask the user to enter an input file .pdf
 
PAGE 1Input output for a file tutorialStreams and File IOI.docx
PAGE  1Input output for a file tutorialStreams and File IOI.docxPAGE  1Input output for a file tutorialStreams and File IOI.docx
PAGE 1Input output for a file tutorialStreams and File IOI.docx
 
File Handling.pptx
File Handling.pptxFile Handling.pptx
File Handling.pptx
 
Write a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfWrite a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdf
 
Java 3 Computer Science.pptx
Java 3 Computer Science.pptxJava 3 Computer Science.pptx
Java 3 Computer Science.pptx
 
IO and threads Java
IO and threads JavaIO and threads Java
IO and threads Java
 
import java.io.BufferedReader;import java.io.File;import java.io.pdf
import java.io.BufferedReader;import java.io.File;import java.io.pdfimport java.io.BufferedReader;import java.io.File;import java.io.pdf
import java.io.BufferedReader;import java.io.File;import java.io.pdf
 
Here is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdfHere is my code for a linefile editor import java.io.BufferedRea.pdf
Here is my code for a linefile editor import java.io.BufferedRea.pdf
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
 
Java Notes
Java Notes Java Notes
Java Notes
 
Java practical
Java practicalJava practical
Java practical
 
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/OCore Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docx
 
Use Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdfUse Java to program the following.1. Create public java class name.pdf
Use Java to program the following.1. Create public java class name.pdf
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdf
 
Lab4
Lab4Lab4
Lab4
 
Code red SUM
Code red SUMCode red SUM
Code red SUM
 

More from fashiionbeutycare

________ are characterized by small incisors and large premolars wit.pdf
________ are characterized by small incisors and large premolars wit.pdf________ are characterized by small incisors and large premolars wit.pdf
________ are characterized by small incisors and large premolars wit.pdf
fashiionbeutycare
 
why do Private offices have a high sensible heat ratioSolution.pdf
why do Private offices have a high sensible heat ratioSolution.pdfwhy do Private offices have a high sensible heat ratioSolution.pdf
why do Private offices have a high sensible heat ratioSolution.pdf
fashiionbeutycare
 
Why is payback and IRR more frequently used than NPV when it comes t.pdf
Why is payback and IRR more frequently used than NPV when it comes t.pdfWhy is payback and IRR more frequently used than NPV when it comes t.pdf
Why is payback and IRR more frequently used than NPV when it comes t.pdf
fashiionbeutycare
 
What general environmental condition is represented by this assemblag.pdf
What general environmental condition is represented by this assemblag.pdfWhat general environmental condition is represented by this assemblag.pdf
What general environmental condition is represented by this assemblag.pdf
fashiionbeutycare
 
What are some of the basic features of Excavates Discuss the differe.pdf
What are some of the basic features of Excavates Discuss the differe.pdfWhat are some of the basic features of Excavates Discuss the differe.pdf
What are some of the basic features of Excavates Discuss the differe.pdf
fashiionbeutycare
 
True or False Disulfides are essential for cone-snail venoms acti.pdf
True or False Disulfides are essential for cone-snail venoms acti.pdfTrue or False Disulfides are essential for cone-snail venoms acti.pdf
True or False Disulfides are essential for cone-snail venoms acti.pdf
fashiionbeutycare
 
To what extent do GUI editors generally allow developers to modify H.pdf
To what extent do GUI editors generally allow developers to modify H.pdfTo what extent do GUI editors generally allow developers to modify H.pdf
To what extent do GUI editors generally allow developers to modify H.pdf
fashiionbeutycare
 
The diagram shows a cell during the anaphase stage of mitosis. How wo.pdf
The diagram shows a cell during the anaphase stage of mitosis. How wo.pdfThe diagram shows a cell during the anaphase stage of mitosis. How wo.pdf
The diagram shows a cell during the anaphase stage of mitosis. How wo.pdf
fashiionbeutycare
 
Thank you for your helpful answer! Consider the following meth.pdf
Thank you for your helpful answer! Consider the following meth.pdfThank you for your helpful answer! Consider the following meth.pdf
Thank you for your helpful answer! Consider the following meth.pdf
fashiionbeutycare
 
State whether the following statement is true or false The graph of t.pdf
State whether the following statement is true or false The graph of t.pdfState whether the following statement is true or false The graph of t.pdf
State whether the following statement is true or false The graph of t.pdf
fashiionbeutycare
 
Should Maria’s ethical responsibility to Linda lead her to keep thes.pdf
Should Maria’s ethical responsibility to Linda lead her to keep thes.pdfShould Maria’s ethical responsibility to Linda lead her to keep thes.pdf
Should Maria’s ethical responsibility to Linda lead her to keep thes.pdf
fashiionbeutycare
 
Revolution in Egypt With 83 million people, Egypt is the most populou.pdf
Revolution in Egypt With 83 million people, Egypt is the most populou.pdfRevolution in Egypt With 83 million people, Egypt is the most populou.pdf
Revolution in Egypt With 83 million people, Egypt is the most populou.pdf
fashiionbeutycare
 
Question No. 1What updates have been brought by snmpv2 to SNMPv1 c.pdf
Question No. 1What updates have been brought by snmpv2 to SNMPv1 c.pdfQuestion No. 1What updates have been brought by snmpv2 to SNMPv1 c.pdf
Question No. 1What updates have been brought by snmpv2 to SNMPv1 c.pdf
fashiionbeutycare
 
President Truman belleved that an increase in a na development, which.pdf
President Truman belleved that an increase in a na development, which.pdfPresident Truman belleved that an increase in a na development, which.pdf
President Truman belleved that an increase in a na development, which.pdf
fashiionbeutycare
 
Pretend you have been asked by the president of the united statesto .pdf
Pretend you have been asked by the president of the united statesto .pdfPretend you have been asked by the president of the united statesto .pdf
Pretend you have been asked by the president of the united statesto .pdf
fashiionbeutycare
 
Please explain in detail. Why cant Salmonella be infected by lambd.pdf
Please explain in detail. Why cant Salmonella be infected by lambd.pdfPlease explain in detail. Why cant Salmonella be infected by lambd.pdf
Please explain in detail. Why cant Salmonella be infected by lambd.pdf
fashiionbeutycare
 
Part A Tnsomy 21, or Down syndrome, occurs when there is anormal dplo.pdf
Part A Tnsomy 21, or Down syndrome, occurs when there is anormal dplo.pdfPart A Tnsomy 21, or Down syndrome, occurs when there is anormal dplo.pdf
Part A Tnsomy 21, or Down syndrome, occurs when there is anormal dplo.pdf
fashiionbeutycare
 
Part 1 List the basic steps in securing an operating system. Assume.pdf
Part 1 List the basic steps in securing an operating system. Assume.pdfPart 1 List the basic steps in securing an operating system. Assume.pdf
Part 1 List the basic steps in securing an operating system. Assume.pdf
fashiionbeutycare
 
John is 35 years old and recently married with Eva. After they got m.pdf
John is 35 years old and recently married with Eva. After they got m.pdfJohn is 35 years old and recently married with Eva. After they got m.pdf
John is 35 years old and recently married with Eva. After they got m.pdf
fashiionbeutycare
 
List three characteristics that an Intrusion Prevention System (IPS).pdf
List three characteristics that an Intrusion Prevention System (IPS).pdfList three characteristics that an Intrusion Prevention System (IPS).pdf
List three characteristics that an Intrusion Prevention System (IPS).pdf
fashiionbeutycare
 

More from fashiionbeutycare (20)

________ are characterized by small incisors and large premolars wit.pdf
________ are characterized by small incisors and large premolars wit.pdf________ are characterized by small incisors and large premolars wit.pdf
________ are characterized by small incisors and large premolars wit.pdf
 
why do Private offices have a high sensible heat ratioSolution.pdf
why do Private offices have a high sensible heat ratioSolution.pdfwhy do Private offices have a high sensible heat ratioSolution.pdf
why do Private offices have a high sensible heat ratioSolution.pdf
 
Why is payback and IRR more frequently used than NPV when it comes t.pdf
Why is payback and IRR more frequently used than NPV when it comes t.pdfWhy is payback and IRR more frequently used than NPV when it comes t.pdf
Why is payback and IRR more frequently used than NPV when it comes t.pdf
 
What general environmental condition is represented by this assemblag.pdf
What general environmental condition is represented by this assemblag.pdfWhat general environmental condition is represented by this assemblag.pdf
What general environmental condition is represented by this assemblag.pdf
 
What are some of the basic features of Excavates Discuss the differe.pdf
What are some of the basic features of Excavates Discuss the differe.pdfWhat are some of the basic features of Excavates Discuss the differe.pdf
What are some of the basic features of Excavates Discuss the differe.pdf
 
True or False Disulfides are essential for cone-snail venoms acti.pdf
True or False Disulfides are essential for cone-snail venoms acti.pdfTrue or False Disulfides are essential for cone-snail venoms acti.pdf
True or False Disulfides are essential for cone-snail venoms acti.pdf
 
To what extent do GUI editors generally allow developers to modify H.pdf
To what extent do GUI editors generally allow developers to modify H.pdfTo what extent do GUI editors generally allow developers to modify H.pdf
To what extent do GUI editors generally allow developers to modify H.pdf
 
The diagram shows a cell during the anaphase stage of mitosis. How wo.pdf
The diagram shows a cell during the anaphase stage of mitosis. How wo.pdfThe diagram shows a cell during the anaphase stage of mitosis. How wo.pdf
The diagram shows a cell during the anaphase stage of mitosis. How wo.pdf
 
Thank you for your helpful answer! Consider the following meth.pdf
Thank you for your helpful answer! Consider the following meth.pdfThank you for your helpful answer! Consider the following meth.pdf
Thank you for your helpful answer! Consider the following meth.pdf
 
State whether the following statement is true or false The graph of t.pdf
State whether the following statement is true or false The graph of t.pdfState whether the following statement is true or false The graph of t.pdf
State whether the following statement is true or false The graph of t.pdf
 
Should Maria’s ethical responsibility to Linda lead her to keep thes.pdf
Should Maria’s ethical responsibility to Linda lead her to keep thes.pdfShould Maria’s ethical responsibility to Linda lead her to keep thes.pdf
Should Maria’s ethical responsibility to Linda lead her to keep thes.pdf
 
Revolution in Egypt With 83 million people, Egypt is the most populou.pdf
Revolution in Egypt With 83 million people, Egypt is the most populou.pdfRevolution in Egypt With 83 million people, Egypt is the most populou.pdf
Revolution in Egypt With 83 million people, Egypt is the most populou.pdf
 
Question No. 1What updates have been brought by snmpv2 to SNMPv1 c.pdf
Question No. 1What updates have been brought by snmpv2 to SNMPv1 c.pdfQuestion No. 1What updates have been brought by snmpv2 to SNMPv1 c.pdf
Question No. 1What updates have been brought by snmpv2 to SNMPv1 c.pdf
 
President Truman belleved that an increase in a na development, which.pdf
President Truman belleved that an increase in a na development, which.pdfPresident Truman belleved that an increase in a na development, which.pdf
President Truman belleved that an increase in a na development, which.pdf
 
Pretend you have been asked by the president of the united statesto .pdf
Pretend you have been asked by the president of the united statesto .pdfPretend you have been asked by the president of the united statesto .pdf
Pretend you have been asked by the president of the united statesto .pdf
 
Please explain in detail. Why cant Salmonella be infected by lambd.pdf
Please explain in detail. Why cant Salmonella be infected by lambd.pdfPlease explain in detail. Why cant Salmonella be infected by lambd.pdf
Please explain in detail. Why cant Salmonella be infected by lambd.pdf
 
Part A Tnsomy 21, or Down syndrome, occurs when there is anormal dplo.pdf
Part A Tnsomy 21, or Down syndrome, occurs when there is anormal dplo.pdfPart A Tnsomy 21, or Down syndrome, occurs when there is anormal dplo.pdf
Part A Tnsomy 21, or Down syndrome, occurs when there is anormal dplo.pdf
 
Part 1 List the basic steps in securing an operating system. Assume.pdf
Part 1 List the basic steps in securing an operating system. Assume.pdfPart 1 List the basic steps in securing an operating system. Assume.pdf
Part 1 List the basic steps in securing an operating system. Assume.pdf
 
John is 35 years old and recently married with Eva. After they got m.pdf
John is 35 years old and recently married with Eva. After they got m.pdfJohn is 35 years old and recently married with Eva. After they got m.pdf
John is 35 years old and recently married with Eva. After they got m.pdf
 
List three characteristics that an Intrusion Prevention System (IPS).pdf
List three characteristics that an Intrusion Prevention System (IPS).pdfList three characteristics that an Intrusion Prevention System (IPS).pdf
List three characteristics that an Intrusion Prevention System (IPS).pdf
 

Recently uploaded

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 

Recently uploaded (20)

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 

Write a Java program that opens the file, reads all the Grade from t.pdf

  • 1. Write a Java program that opens the file, reads all the Grade from the file, and using a method calculates and displays the following A) Displays the grades with their letter values (80 - B) B) the sum of the Grades in the file C) the average of the Grades in the file Solution GradeRead.java import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class GradeRead { public static void main(String[] args) throws FileNotFoundException { Scanner scan1 = new Scanner(System.in); System.out.print("Enter the file name: "); String fileName = scan1.next(); File file = new File(fileName); if(file.exists()){ Scanner scan = new Scanner(file); calculateGradeDetail(scan); } else{ System.out.println("Input does not exist"); } } public static void calculateGradeDetail(Scanner scan){ int sum = 0; int count = 0; char gradeLetter = '0'; while(scan.hasNextInt()){ count++; int n = scan.nextInt(); sum = sum + n; if(n >=90 && n<=100){ gradeLetter = 'A';
  • 2. } else if(n >=80 && n<90){ gradeLetter = 'B'; } else if(n >=70 && n<80){ gradeLetter = 'C'; } else if(n >=60 && n<=70){ gradeLetter = 'D'; } else { gradeLetter = 'E'; } System.out.println("Grade: "+gradeLetter+" - "+n); } System.out.println("The sum of the Grades in the file: "+sum); double average = sum/(double)count; System.out.println("the average of the Grades in the file: "+average); System.out.println(); } } Output: Enter the file name: D:grade.txt Grade: D - 60 Grade: C - 70 Grade: B - 80 Grade: A - 90 Grade: A - 100 Grade: E - 40 Grade: E - 50 Grade: D - 60 The sum of the Grades in the file: 550 the average of the Grades in the file: 68.75 Grade.txt 60 70