Question

Input hello, I need help completing my assignment for java,Use the following test data for input...

Input

hello, I need help completing my assignment for java,Use the following test data for input and fill in missing code, and please screenshot output.

1, John Adam, 3, 93, 91, 100, Letter

2, Raymond Woo, 3, 65, 68, 63, Letter

3, Rick Smith, 3, 50, 58, 53, Letter

4, Ray Bartlett, 3, 62, 64, 69, Letter

5, Mary Russell, 3, 93, 90, 98, Letter

6, Andy Wong, 3, 89,88,84, Letter

7, Jay Russell, 3, 71,73,78, Letter

8, Jimmie Wong, 3, 70,77,72, Letter

9, Jackie Chan, 3, 85,89,84, Letter

10, Susan Wu, 3, 80,88,84, Letter

11, Bruce Lee, 4, 74, 79, 72, 75, Credit

12, Chuck Norris, 5, 63, 64, 62, 60, 68, Credit

13, Jet Li, 3, 85, 83, 89, Credit

14, Jessica Lauser, 3, 82, 84, 87, Letter

15, Mahnoosh Nik-Ahd, 2, 98, 99, Letter

Output

1 John Adam (A)

5 Mary Russell (A)

15 Mahnoosh Nik-Ahd (A)

6 Andy Wong (B)

9 Jackie Chan (B)

10 Susan Wu (B)

14 Jessica Lauser (B)

7 Jay Russell (C)

8 Jimmie Wong (C)

2 Raymond Woo (D)

4 Ray Bartlett (D)

3 Rick Smith (F)

11 Bruce Lee (CR)

13 Jet Li (CR)

12 Chuck Norris (NCR)

Submit

Copy the following in a file and submit that file:

Final output dialog box containing the complete output in a single dialog box

The source code from all the source java file.

Note that the method findGrade in class StudentExt over-rides the parent method findGrade in the parent class Student. Notice also that this method calls the parent method findGrade for determining the student’s letter grade. On return from the parent method, it changes the grade to “CR” or “NCR” in the case when a student's grade type is "Credit" as described below.

When a student's gradeType is “Credit” and the parent findGrade method returns a letter grade of "A", "B", or "C", the grade is changed to “CR”. Otherwise (for a letter grade of “D” or “F”), it is changed to “NCR”.

//class Student

//File Student.java

public class Student

{

private int id;

private String name;

private double [] scores;

public Student(int id, String n, int [] s)

{

    //Below id refers to local variable.

] this.id = id;

    name = n;

    //create scores array of same length as s array

   scores = new double [s.length];

    System.arraycopy(s, 0, scores, 0, s.length);

}

public String findGrade()

{

     //write missing code below

    String grade="";

    double sum=0;

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

    {

         sum=sum+scores[i];

    }

    double average=sum/scores.length;

    if (average>=90.0)

         grade="A";

    else if (average>=80.0)

         grade="B";

else if (average>=70.0)
       grade="C";
       else if (average>=60.0)
       grade="D";
       else
       grade="F";
       return grade;
       }
      
       public int getId ( ){
       return id;
       }
      
       public String getName ( ){
       return name;
       }

}

//class StudentExt

//File StudentExt.java

//write the missing code

public class StudentExt

{

private String gradeType;

public StudentExt(int id, String n, int [] s, String gType)

{

    //Call the constructor to initialize 'id, name and scores

    super(id,n,s);

    //initialize gradeType here

    gradeType=gType;

}

   public String getGradeType ( )

{

     return gradeType;

}

//This method over-rides the same method in the parent class

public String findGrade ( )

{

    //call the parent method findGrade for determine letter grade

    String grade = super.findGrade ( );

    //if the gradeType is Credit, change the grade

    if (gradeType.equalsIgnoreCase ("Credit"))

    {

      if ( (grade.equalsIgnoreCase ("A")) ||

            (grade.equalsIgnoreCase ("B")) ||

            (grade.equalsIgnoreCase ("C")))

            grade = "CR";

      else

            grade = "NCR";

    }

    return grade;

}

}

//class TestStudentExt

//file: TestStudentExt.java

//Changes from TestStudent to TestStudentExt are in bol

import javax.swing.*;

import java.util.*;

public class TestStudentExt

{

public static void main(String[] args)

{

    String in;

    int nStudents, nExams;

   

    in = JOptionPane.showInputDialog("Enter number of students");

    nStudents = Integer.parseInt(in);

    // Create an array of StudentExt references

    StudentExt [] st = new StudentExt [nStudents];

    // Create StudentExt objects using loop

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

    {

      in = JOptionPane.showInputDialog

             ("Enter one student data with items separated by comma");

      // Tokenize student data using StringTokenizer

      String delim = ",";

      String token;

StringTokenizer st = new StringTokenizer (in, delim);

      token = st.nextToken ().trim();

      int id=Integer.parseInt(token);

      String name = st.nextToken ().trim();

      token = st.nextToken ().trim();

      nExams=Integer.parseInt(token);

double[] scores;=new double[nExams];

for (int j=0;j<nExams;j++)

     {

         token = st.nextToken().trim();

         scores[j]=Double.parseDouble(token);

     }

      String gradeType= st.nextToken().trim();

      st [i] = new StudentExt (id, name, scores, gradeType);

    }

    //Create an empty output String for each type of grade

    String outA="", outB="", outC="", outD="", outF="", outCr="", outNcr="";

    //find student grades and accumulate output for each type of student.

    String grade="";

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

    {

grade = st1[i].findGrade();
   if (grade.equalsIgnoreCase("A")) {
   //accumulate output in outA for A students.
   outA=outA+ st1[i].getId()+" "+st1[i].getName()+" ("+grade+")\n";
   }
   else if (grade.equalsIgnoreCase("B")){
   //accumulate output in outB for B students.
   outB=outB+ st1[i].getId()+" "+st1[i].getName()+" ("+grade+")\n";
   }

   else if (grade.equalsIgnoreCase("C")){
   //accumulate output in outC for C students.
   outC=outC+ st1[i].getId()+" "+st1[i].getName()+" ("+grade+")\n";
   }
  
   else if (grade.equalsIgnoreCase("D")){
   //accumulate output in outD for D students.
   outD=outD+ st1[i].getId()+" "+st1[i].getName()+" ("+grade+")\n";
   }
   else if (grade.equalsIgnoreCase("F")){
   //accumulate output in outD for D students.
   outF=outF+ st1[i].getId()+" "+st1[i].getName()+" ("+grade+")\n";
   }
   else if (grade.equalsIgnoreCase("CR")){

   //accumulate output in outCr for CR students.

       outCr=outCr+ st1[i].getId()+" "+st1[i].getName()+" ("+grade+")\n";  

}

   else if (grade.equalsIgnoreCase("NCR")){
       outNcr=outNcr+ st1[i].getId()+" "+st1[i].getName()+" ("+grade+")\n";
}

}

    String outAll=outA+outB+outC+outD+outF+ outCr+outNcr;

    // display output

    JOptionPane.showMessageDialog(null, outAll);

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the codes below.Most of changes in student and studentExt java..There were few typo mistake in TestStudentExt.java as well

Student.java

public class Student {
private int id;
private String name;
private double[] scores;
public Student(int id, String n, double[] s)
{
this.id = id;
name = n;
// create scores array of same length as s array
scores = new double[s.length];
System.arraycopy(s, 0, scores, 0, s.length);
}
public String findGrade()
{
// write missing code below
String grade = "";
double sum = 0;
for (int i = 0; i < scores.length; i++)
{
sum = sum + scores[i];
}
double average = sum / scores.length;
if (average >= 90.0)
grade = "A";
else if (average >= 80.0)
grade = "B";
else if (average >= 70.0)
grade = "C";
else if (average >= 60.0)
grade = "D";
else
grade = "F";
return grade;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}

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

StudentExt.java

public class StudentExt extends Student {
private String gradeType;

public StudentExt(int id, String n, double[] s, String gType) {
// Call the constructor to initialize 'id, name and scores
super(id, n, s);
// initialize gradeType here
gradeType = gType;
}

public String getGradeType() {
return gradeType;
}

// This method over-rides the same method in the parent class
public String findGrade() {
// call the parent method findGrade for determine letter grade
String grade = super.findGrade();
// if the gradeType is Credit, change the grade
if (gradeType.equalsIgnoreCase("Credit")) {
if ((grade.equalsIgnoreCase("A")) || (grade.equalsIgnoreCase("B")) || (grade.equalsIgnoreCase("C")))
grade = "CR";
else
grade = "NCR";
}
return grade;
}
}

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

TestStudentExt.java

import javax.swing.*;
import java.util.*;
public class TestStudentExt
{
public static void main(String[] args)
{
String in;
int nStudents, nExams;
in = JOptionPane.showInputDialog("Enter number of students");
nStudents = Integer.parseInt(in);
// Create an array of StudentExt references
StudentExt[] st1 = new StudentExt[nStudents];
// Create StudentExt objects using loop
for (int i = 0; i < st1.length; i++)
{
in = JOptionPane.showInputDialog
("Enter one student data with items separated by comma");
// Tokenize student data using StringTokenizer
String delim = ",";
String token;
StringTokenizer st = new StringTokenizer(in, delim);
token = st.nextToken().trim();
int id = Integer.parseInt(token);
String name = st.nextToken().trim();
token = st.nextToken().trim();
nExams = Integer.parseInt(token);
double[] scores = new double[nExams];
for (int j = 0; j < nExams; j++)
{
token = st.nextToken().trim();
scores[j] =(double) Double.parseDouble(token);
}
String gradeType = st.nextToken().trim();
st1[i] = new StudentExt(id, name, scores, gradeType);
}
for(Student s:st1)
System.out.println(s.getId());
// Create an empty output String for each type of grade
String outA = "", outB = "", outC = "", outD = "", outF = "", outCr = "", outNcr = "";
// find student grades and accumulate output for each type of student.
String grade = "";
for (int i = 0; i < st1.length; i++)
{
grade = st1[i].findGrade();
if (grade.equalsIgnoreCase("A")) {
// accumulate output in outA for A students.
outA = outA + st1[i].getId() + " " + st1[i].getName() + " (" + grade + ")\n";
} else if (grade.equalsIgnoreCase("B")) {
// accumulate output in outB for B students.
outB = outB + st1[i].getId() + " " + st1[i].getName() + " (" + grade + ")\n";
}
else if (grade.equalsIgnoreCase("C")) {
// accumulate output in outC for C students.
outC = outC + st1[i].getId() + " " + st1[i].getName() + " (" + grade + ")\n";
}
else if (grade.equalsIgnoreCase("D")) {
// accumulate output in outD for D students.
outD = outD + st1[i].getId() + " " + st1[i].getName() + " (" + grade + ")\n";
} else if (grade.equalsIgnoreCase("F")) {
// accumulate output in outD for D students.
outF = outF + st1[i].getId() + " " + st1[i].getName() + " (" + grade + ")\n";
} else if (grade.equalsIgnoreCase("CR")) {
// accumulate output in outCr for CR students.
outCr = outCr + st1[i].getId() + " " + st1[i].getName() + " (" + grade + ")\n";
}
else if (grade.equalsIgnoreCase("NCR")) {
outNcr = outNcr + st1[i].getId() + " " + st1[i].getName() + " (" + grade + ")\n";
}
}
String outAll = outA + outB + outC + outD + outF + outCr + outNcr;
// display output
JOptionPane.showMessageDialog(null, outAll);
}
}

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

Add a comment
Know the answer?
Add Answer to:
Input hello, I need help completing my assignment for java,Use the following test data for input...
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
  • Hi, I am writing Java code and I am having a trouble working it out. The...

    Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...

  • Hello, How can I make the program print out "Invalid data!!" and nothing else if the...

    Hello, How can I make the program print out "Invalid data!!" and nothing else if the file has a grade that is not an A, B, C, D, E, or F or a percentage below zero? I need this done by tomorrow if possible please. The program should sort a file containing data about students like this for five columns: one for last name, one for first name, one for student ID, one for student grade percentage, one for student...

  • This is a java homework for my java class. Write a program to perform statistical analysis...

    This is a java homework for my java class. Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit student ID number. The program is to print the student scores and calculate and print the statistics for each quiz. The output is in the same order as the input; no sorting is needed. The input is...

  • I need help displaying two zeroes in hours:minutes:seconds. In Java. I need some help for the...

    I need help displaying two zeroes in hours:minutes:seconds. In Java. I need some help for the time to display correctly. I want it to display double zeroes. 06:00:00 and 12:00:00. public class Clock { String name; static int uid=100; int id; int hr; int min; int sec; public Clock() {   this.name="Default";   this.id=uid;   this.hr=00; this.min=00; this.sec=00; uid++; } public Clock(String name, int hr, int min, int sec) { if (hr<=24 && min <=60 && sec <=60) {   this.hr = hr; this.min...

  • Java programming help My program wont run. could someone tell me why. everything seems correct to...

    Java programming help My program wont run. could someone tell me why. everything seems correct to me... giving me the error: Exception in thread "main" java.lang.NumberFormatException: For input string: "Stud" at java.base/java.lang.NumberFormatException.forInputString(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at Util.readFile(Util.java:35) at Driver.main(Driver.java:8) _________________________________________________________________________________________________________________________ Program Prompt: Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit...

  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In...

    Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and cannot figure it out. Thank you. Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and...

  • I have a little problem about my code. when i'm working on "toString method" in "Course"...

    I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student {    private String firstName;    private String lastName;    private String id;    private boolean tuitionPaid;       public Student(String firstName, String lastName, String id, boolean tuitionPaid)    {        this.firstName=firstName;        this.lastName=lastName;        this.id=id;        this.tuitionPaid=tuitionPaid;    }   ...

  • I need help converting the following two classes into one sql table package Practice.model; impor...

    I need help converting the following two classes into one sql table package Practice.model; import java.util.ArrayList; import java.util.List; import Practice.model.Comment; public class Students {          private Integer id;    private String name;    private String specialties;    private String presentation;    List<Comment> comment;       public Students() {}       public Students(Integer id,String name, String specialties, String presentation)    {        this.id= id;        this.name = name;        this.specialties = specialties;        this.presentation = presentation;        this.comment = new ArrayList<Commment>();                  }       public Students(Integer id,String name, String specialties, String presentation, List<Comment> comment)    {        this.id= id;        this.name...

  • Hello, Can you please error check my javascript? It should do the following: Write a program...

    Hello, Can you please error check my javascript? It should do the following: Write a program that uses a class for storing student data. Build the class using the given information. The data should include the student’s ID number; grades on exams 1, 2, and 3; and average grade. Use appropriate assessor and mutator methods for the grades (new grades should be passed as parameters). Use a mutator method for changing the student ID. Use another method to calculate the...

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