In: Computer Science
JAVA PROGRAMMING
Part 1
Part 2
3. Create an integer attribute to student class, name it as studentScore. No getters and setters are needed for this attribute.
4. When you create the Student object using the constructor, assign a random number to score attribute – random number should be between, 50 and 100.
5. Create a new method in Student object, called getGrade(), that returns a String.
a. The output method should return the following
If the score is >91, the return should be A,
Likewise B for >81 , C > 71, D > 61, and F for all others.
6. Modify the StudentOperationsClient’s main program, to print the following.
First Name: XXXXXX , Last Name: XXXXXXXX Letter Grade: XX
Part 3
Use switch case control statements to return the following,
•&νβσπ;&νβσπ;&νβσπ;&νβσπ;&νβσπ;&νβσπ;&νβσπ;&νβσπ; and any other input as “INVALID”
First Name: XXXXXX , Last Name: XXXXXXXX Class Performance: <GradeDescription>
Thanks for the question. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. There are some invalid text in your question. What are these ??Thanks =========================================================================== public class Student { //Create a class Student, with attributes id, first name, last name. (All the attributes must be String) private String id; private String firstName; private String lastName; //Create an integer attribute to student class, name it as studentScore. private int studentScore; //Create a constructor that accepts first name and last name to create a student object. public Student(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; id = ""; } //Create a new method in student, getGradeDescription() – that returns a string and takes a String as input. public String getGradeDescription(String input) { char grade = input.charAt(0); switch (grade) { case 'A': return "A - Excellent"; case 'B': return "B - Fair"; case 'C': return "C - Average"; case 'D': return "D - Poor"; case 'F': return "F - Fail"; default: return "INVALID"; } } public Student(String firstName, String lastName, int studentScore) { this.firstName = firstName; this.lastName = lastName; this.studentScore = studentScore; } // Create a new method in Student object, called getGrade(), that returns a String. public String getGrade() { if (studentScore > 91) return "A"; else if (studentScore > 81) return "B"; else if (studentScore > 71) return "C"; else if (studentScore > 61) return "D"; else return "F"; } //Create appropriate getters and setters public String getId() { return id; } public String getFirstName() { return firstName; } public String getLastName() { return lastName; } public void setId(String id) { this.id = id; } public void setFirstName(String firstName) { this.firstName = firstName; } public void setLastName(String lastName) { this.lastName = lastName; } }
====================================================================
public class StudentOperationClient { public static void main(String[] args) { Student ce = new Student("Chris","Evans"); Student mk = new Student("Mila","Kunis"); Student as = new Student("Adam","Sandler"); Student ew = new Student("Emma","Watson"); Student jl = new Student("Jennifer","Lawrence"); Student dj = new Student("Dwayne","Johnson"); Student[] students = new Student[6]; students[0]=ce; students[1]=mk; students[2]=as; students[3]=ew; students[4]=jl; students[5]=dj; //Once you create the student objects, use System.out.println, // function to print the values in following format: //First Name: XXXXXX , Last Name: XXXXXXXX for(Student student:students) System.out.println("First Name: "+student.getFirstName()+", Last Name: "+student.getLastName()); ce = new Student("Chris","Evans",91); mk = new Student("Mila","Kunis",81); as = new Student("Adam","Sandler",71); ew = new Student("Emma","Watson",61); jl = new Student("Jennifer","Lawrence",50); dj = new Student("Dwayne","Johnson",92); students[0]=ce; students[1]=mk; students[2]=as; students[3]=ew; students[4]=jl; students[5]=dj; for(Student student:students){ System.out.println("First Name: "+student.getFirstName()+ ", Last Name: "+student.getLastName()+ ", Letter Grade: "+student.getGrade()); } for(Student student:students){ System.out.println("First Name: "+student.getFirstName()+ ", Last Name: "+student.getLastName()+ ", Class Performance: "+student.getGradeDescription(student.getGrade())); } } }
===========================================================================
thank you !
please please a thumbs up : )