SlideShare a Scribd company logo
1 of 3
Download to read offline
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.docxajoy21
 
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.docxnoreendchesterton753
 
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 .pdfudit652068
 
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.docxalfred4lewis58146
 
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 .pdfatulkapoor33
 
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.pdfmanojmozy
 
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.pdfpratyushraj61
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECSreedhar Chowdam
 
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/OWebStackAcademy
 
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.docxmichael1810
 
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.pdff3apparelsonline
 
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 .pdfsecunderbadtirumalgi
 

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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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 .pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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.pdffashiionbeutycare
 
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).pdffashiionbeutycare
 

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

Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MysoreMuleSoftMeetup
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 

Recently uploaded (20)

Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 

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