Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.Map; import java.util.Scanner; import java.util.Set; import java.util.TreeMap; public class StudentGrades { public static void main(String[] args)

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class StudentGrades
{
public static void main(String[] args)
{
//-----------Start below here. To do: approximate lines of code = 1
// Create a map called students with key of type String (student id) and value of type Student
TreeMap students= new TreeMap<>();
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

try
{
File studentData = new File("students.txt");
Scanner in = new Scanner(studentData);
Scanner inputLine;

while (in.hasNextLine())
{
String line = in.nextLine();
inputLine = new Scanner(line);
String name = inputLine.next();
String id   = inputLine.next();
Student student = new Student(name,id);
while (inputLine.hasNext())
{
 String course = inputLine.next();
 String grade = inputLine.next();
 student.addCourseAndGrade(course, grade);
}
//-----------Start below here. To do: approximate lines of code = 1
// Add the student to the students map
students.put(id,student);
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

}
catch (IOException exception)
{
System.out.println("Error processing file: " + exception);
System.exit(0);
}

//-----------Start below here. To do: approximate lines of code = 3
// Print all the info for all students in the map
 for(Map.Entry m:students.entrySet()){

System.out.println(m.getValue().toString());

}
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

//-----------Start below here. To do: approximate lines of code = 8
// Update the course grade of a student with given id
//ID: "DD1234" CPS209 update grade to B+
//ID: "JJ2345" CPS209 update grade to A-
//ID: "HH2123" CPS209 update grade to B+
students.get("DD1234").updateGrade("CPS209","B+");

students.get("JJ2345").updateGrade("CPS209","A-");

students.get("HH2123").updateGrade("CPS209","B+");





// Print all the info for all students in the map
for(Map.Entry m:students.entrySet()){

System.out.println(m.getValue().toString());

}
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

System.out.println("Expected:Joe DD1234 CPS209 B- CPS109 A-");
System.out.println("Adam HH2123 CPS209 B CPS109 D+");
System.out.println("James JJ2345 CPS209 B+ CPS109 C+");
System.out.println("Miriam MM3456 CPS209 A+ CPS109 A+");
System.out.println("Joe DD1234 CPS209 B+ CPS109 A-");
System.out.println("Adam HH2123 CPS209 B+ CPS109 D+");
System.out.println("James JJ2345 CPS209 A- CPS109 C+");
System.out.println("Miriam MM3456 CPS209 A+ CPS109 A+");
}
}



Why am i getting this error:

Please help me fix the code and get expected output

Please recheck your code. StudentGrades.java:53: error: incompatible types: Object cannot be converted for (Map. Entry m:students.entrySet () ) { StudentGrades.java:65: error: cannot find symbol students.get ("DD1234"). updateGrade ("CPS209", "B+"); symbol: method updateGrade (String, String) location: class Object StudentGrades.java:67: error: cannot find symbol students.get ("JJ2345") .updateGrade ("CPS209", "A-"); symbol: method updateGrade (String, String) location: class Object StudentGrades.java:69: error: cannot find symbol students.get ("HH2123").updateGrade ("CPS209","B+"); symbol: method updateGrade (String, String) location: class Object StudentGrades.java:76: error: incompatible types: Object cannot be converted for (Map.Entry m:students.entrySet ()) { Note: StudentGrades.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 5 errors

Step by Step Solution

There are 3 Steps involved in it

Step: 1

import javaioFile import javaioIOException import javautilMap import javautilScanner import javautil... 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

Cost Accounting A Managerial Emphasis

Authors: Charles T. Horngren, Srikant M.Dater, George Foster, Madhav

13th Edition

8120335643, 136126634, 978-0136126638

More Books

Students also viewed these Programming questions

Question

Distinguish between a joint product and a byproduct?

Answered: 1 week ago