Question

In: Computer Science

***IN JAVA*** Write a program contained a class Student which has firstName, lastName, mark, grade. The...

***IN JAVA***

Write a program contained a class Student which has firstName, lastName, mark, grade. The program should allow creation an array of object instances to assign firstName, lastName and mark from input user and perform and assign grade based on mark’s criteria displayed below.

MARKS

INTERVAL

95 - 100

90 - <95

85 - <90

80 - <85

75 - <80

70 - <75

65 - <70

60 - <65

0 - <60

LETTER GRADE

A+

A

B+

B

C+

C

D+

D

F

SAMPLE OF OUTPUT:

Enter section #: 1

How many students: 3

Enter student details:

First Name: John

Last Name: Kendall

Marks      : 96

Enter student details:

First Name: Mary

Last Name: Kendall

Marks      : 76

Enter student details:

First Name: Lucy

Last Name: Kendall

Marks      : 76

Result for Section 1

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

FirstName               Last Name         Grade

John                    Kendall           A+

Mary                    Kendall           C+

Lucy                    Kendall           C+

Total students: 3

Average marks: 82.2     Average Grade: B

Highest: 96, by John Kendall

Location: 0

Another batch? (Yes – 1, No - 0) :> 1

Enter section #: 2

How many students: 6

Enter student details:

1)

First Name: John

Last Name: Kendall

Marks      : 96

2)

First Name: Mary

Last Name: Kendall

Marks      : 76

3)

First Name: Lucy

Last Name: Kendall

Marks      : 76

4)

First Name: Martin

Last Name: Kendall

Marks      : 86

5)

First Name: Mary

Last Name: Kendall

Marks      : 76

6)

First Name: Lucy

Last Name: Kendall

Marks      : 98

Result for Section 2

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

FirstName               Last Name         Grade

John                    Kendall           A+

Mary                    Kendall           C+

Lucy                    Kendall           C+

Martin                  Kendall           B+

Mary                    Kendall           C+

Lucy                    Kendall           A+

Total students: 6

Average marks : 80.7    Average Grade: B

Highest: 98, by Lucy Kendall

Location: 6

           

Another batch? (Yes – 1, No - 0) :> 0

     

PROBLEM SOLVING TIPS:

Num

Tips

Grade

a)

Use class Student to create another class Students that will be built in the class implementing a Comparator.

/1m

b)

Use for enhanced method to display the grade of student by each batches

/1m

c)

In the main program, create sections of studlist, receive section number and number of students for each section. Use loop control structure to display output as shown in above and to assign input utilizing the studList structure.

/3m

d)

For each section, program will control input firstname, lastname and marks received from user and add into StudList.

/2m

e)

Use appropriate control structure to control input and program execution.

/4m

f)

In main, use Arrays sort() method, to help find the maximum grade achieved by each class and display the name of the student.

/3m

g)

In main, find the average performance (average section, mark and grade) of every batch and include in the output display.

Formula :

Average_mark = total/number of students;

/2m

h)

Use solution for practical provided to extend the program to capable to process more than one sections of students to process.

/ 4m

TOTAL:

/20m

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

// Student.java

import java.util.Comparator;

public class Student implements Comparator<Student> {
   private String firstName;
   private String lastName;
   private double mark;

   public Student() {
  
   }
   /**
   * @param firstName
   * @param lastName
   * @param mark
   */
   public Student(String firstName, String lastName, double mark) {
       this.firstName = firstName;
       this.lastName = lastName;
       this.mark = mark;
   }

   /**
   * @return the firstName
   */
   public String getFirstName() {
       return firstName;
   }

   /**
   * @param firstName
   * the firstName to set
   */
   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }

   /**
   * @return the lastName
   */
   public String getLastName() {
       return lastName;
   }

   /**
   * @param lastName
   * the lastName to set
   */
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

   /**
   * @return the mark
   */
   public double getMark() {
       return mark;
   }

   /**
   * @param mark
   * the mark to set
   */
   public void setMark(double mark) {
       this.mark = mark;
   }

   public String gradeLetter(double mark) {
       String letter = "";

       if (mark >= 95 && mark <= 100)
           letter = "A+";
       else if (mark >= 90 && mark <95)
           letter = "A-";
       else if (mark >= 85 && mark <90)
           letter = "B+";
       else if (mark >= 80 && mark <85)
           letter = "B";
       else if (mark >= 75 && mark < 80)
           letter = "C+";
       else if (mark >= 70 && mark < 75)
           letter = "C";
       else if (mark >= 65 && mark < 70)
           letter = "D+";
       else if (mark >= 60 && mark <65)
           letter = "D";
       else if (mark <60)
           letter = "F";
       return letter;
   }

   @Override
   public int compare(Student s1, Student s2) {
       if (s1.getMark() < s2.getMark())
           return 1;
       else if (s1.getMark() > s2.getMark())
           return -1;
       else
           return 0;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       String s = new String().format("%-15s%-15s%-15s", firstName, lastName,gradeLetter(mark));
       return s;
   }

}

=========================================

// Students.java

import java.util.Arrays;
import java.util.Scanner;

public class Students {
   public static void main(String[] args) {
       int size, count = 0, maxIndex =0;
       String firstName, lastName;
       double sum = 0.0, avg = 0.0;
       Student s=null;
       double max,mark;
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);

       while (true) {
           count++;
           // Getting the input entered by the user
           System.out.println("Enter section #:" + (count));
           System.out.print("How many students: ");
           size = sc.nextInt();

           Student studList[] = new Student[size];
           for (int i = 0; i < studList.length; i++) {
               System.out.println("Enter student details:");
               System.out.print("First Name:");
               firstName = sc.next();
               System.out.print("Last Name :");
               lastName = sc.next();
               System.out.print("Marks :");
               mark = sc.nextInt();
               s = new Student(firstName, lastName, mark);
               studList[i] = s;
           }
           Arrays.sort(studList,new Student());
          
          
           System.out.println("Result for Section " + (count));
           System.out.println("-----------------------------------------");
           System.out.printf("%-15s%-15s%-15s\n", "FirstName", "LastName","Grade");
           max = studList[0].getMark();
           for (int i=0;i<studList.length;i++)
           {
              
               sum += studList[i].getMark();
               System.out.println(studList[i]);
               if (max < studList[i].getMark())
               {
                   max = studList[i].getMark();
                   maxIndex = i;
               }
           }
           avg=((double)sum/size);
           System.out.println("Total Students:" + size);
           System.out.printf("Average marks:%.1f\n" ,avg);
           System.out.println("Average Grade:" +s.gradeLetter(avg));
           System.out.println("Highest:" +max+", by "+studList[maxIndex].getFirstName()+" "+studList[maxIndex].getLastName()+" Location: "+maxIndex);
           System.out.print("Another batch? (Yes - 1, No - 0):>");
           int choice=sc.nextInt();
           if(choice==0)
               break;
       }

   }

}

==========================================

Output:

==================================Thank You


Related Solutions

JAVA - I am asking for the user to input their firstName and lastName but I...
JAVA - I am asking for the user to input their firstName and lastName but I want the method myMethod() to be able to print it when it is called. Is that possible? I'm new to Java and i'm not too sure what I should do to fix this. Also if I were to create a IF statement would I have to declare int amountDeposited; , int accountBalance; , int newBalance; in the new if statement. import java.util.Scanner; import java.util.Arrays;...
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
How would I setup this dictionary for Python 3? class Student(object): def __init__(self, id, firstName, lastName,...
How would I setup this dictionary for Python 3? class Student(object): def __init__(self, id, firstName, lastName, courses = None): The “id”, “firstName” and “lastName” parameters are to be directly assigned to member variables (ie: self.id = id) The “courses” parameter is handled differently. If it is None, assign dict() to self.courses, otherwise assign courses directly to the member variable. Note: The “courses” dictionary contains key/value pairs where the key is a string that is the course number (like “course1”) and...
java programing Q: Given the following class: public class Student { private String firstName; private String...
java programing Q: Given the following class: public class Student { private String firstName; private String lastName; private int age; private University university; public Student(String firstName, String lastName, int age, University university) { this.firstName = fisrtName; this.lastName = lastName; this.age = age; this.university = university; } public String getFirstName(){ return firstName; } public String getLastName(){ return lastName; } public int getAge(){ return age; } public University getUniversity(){ return university; } public String toString() { return "\nFirst name:" + firstName +...
A person has a firstname, lastname, ID, and email. A phone number is of the form...
A person has a firstname, lastname, ID, and email. A phone number is of the form countrycode, number. A person may have several related telephone numbers, and a telephone number may be associated with multiple people. The possible relationships are: home, work, and mobile. A person may have at most one phone number for each type of relationship. Draw schema diagram and define and create the tables that implement the model and enforce the given constraints.
Design a database/mysql that has 3 tables: TABLE 1 student: StudID (int), LastName (varchar), FirstName (varchar),...
Design a database/mysql that has 3 tables: TABLE 1 student: StudID (int), LastName (varchar), FirstName (varchar), MiddleName(varchar) TABLE 2 Course: StudID, CourseID TABLE 3 study course: CourseID(int), CourseTitle(varchar), Units(int), PreqCourse(varchar) ** Insert at least 5 records. ** Use the "select" command to view the content of the tables. ** POST THE SCREENSHOT
Using files, Write a Java program to read 2 tutorials group of student id, assignment mark...
Using files, Write a Java program to read 2 tutorials group of student id, assignment mark (30), lab test mark(20) from 2 input files namely group1.txt and group 2.txt. Your program will calculate the total course work marks and write in to 3 output files with the following conditions: if the total course work marks are more than 40 out 50 write in to LIST1.TXT if the total course work marks are between 30 to 40 then write in to...
write a Java program Write a program to assign a letter grade according to the following...
write a Java program Write a program to assign a letter grade according to the following scheme: A: total score >= 90 B: 80 <= total score < 90 C: 70 <= total score < 80 D: 60 <= total score < 70 F: total score < 60 Output - the student's total score (float, 2 decimals) and letter grade Testing - test your program with the following input data: test1 = 95; test2 = 80; final = 90; assignments...
Code in Java Write a Student class which has two instance variables, ID and name. This...
Code in Java Write a Student class which has two instance variables, ID and name. This class should have a two-parameter constructor that will set the value of ID and name variables. Write setters and getters for both instance variables. The setter for ID should check if the length of ID lies between 6 to 8 and setter for name should check that the length of name should lie between 0 to 20. If the value could not be set,...
1. ​ a)​Write a Matlab program to define student grade program and student number with if-else...
1. ​ a)​Write a Matlab program to define student grade program and student number with if-else statement logic​​​​​​​​​ b)​Write a Matlab program for sensor selection of temperature, pressure, flow sensor with if-else statement logic​​​​​​​​​ ​ 2.​Assume there are four letters from an information source with probabilities as A1 0.5 A2 0.3 A3 0.1 A4 0.1 Generate the tag and find the corresponding gaps and binary values for each stage and the sequence of the symbols which are coded are a1a3a2a4a1.​​​...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT