Question

In: Computer Science

JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...

JAVA PROGRAMMING

Part 1

  1. Create a class Student, with attributes id, first name, last name. (All the attributes must be String)
    1. Create a constructor that accepts first name and last name to create a student object.
    2. Create appropriate getters and setters
  2. Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed.
  • In the main program, create student objects, with the following first and last names.
  • Chris Evans
  • Mila Kunis
  • Adam Sandler
  • Emma Watson
  • Jennifer Lawrence
  • Dwayne Johnson.
  • Once you create the student objects, use System.out.println, function to print the values in following format:
  • First Name: XXXXXX , Last Name: XXXXXXXX

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

  1. Perform the steps 2, and 6, using arrays in Java. So instead of 6 different objects, you will create an array of 6 student objects and iterate them using a for loop.
  2. Create a new method in student, getGradeDescription() – that returns a string and takes a String as input.

Use switch case control statements to return the following,

  • A – Excellent
  • B – Fair
  • C – Average
  • D – Poor
  • F – Fail,

•&νβσπ;&νβσπ;&νβσπ;&νβσπ;&νβσπ;&νβσπ;&νβσπ;&νβσπ; and any other input as “INVALID”

  • Once you create the student objects in the ARRAY, use System.out.println, function to print the values in following format:

First Name: XXXXXX , Last Name: XXXXXXXX Class Performance: <GradeDescription>

Solutions

Expert Solution

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 : )


Related Solutions

JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games,...
JAVA Program Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If there are...
Please Code Using Java Create a class called SoccerPlayer Create 4 private attributes: First Name, Last...
Please Code Using Java Create a class called SoccerPlayer Create 4 private attributes: First Name, Last Name, Games, and Goals Have two constructors Constructor 1 – default constructor; all values to "NONE" or zero Constructor 2 – accepts input of first name, last name, games and goals. Create get and set methods for each of the four attributes Create a method the returns a double that calculates the average goals per game This method checks for zero games played: If...
Specifications Create an abstract Employee class that provides private attributes for the first name, last name,...
Specifications Create an abstract Employee class that provides private attributes for the first name, last name, email address, and social security number. This class should provide functions that set and return the employee’s first name, last name, email address, and social security number. This class has a function: get_net_income which returns 0. Create a Manager class that inherits the Employee class. This class should add private attributes for years of experience and the annual salary. This class should also provide...
Create a java program with class Customer: Name, Surname, ID (incremental ID by 1 for each...
Create a java program with class Customer: Name, Surname, ID (incremental ID by 1 for each new customer), Email, Phone, Address. The program must create New customer, and Print information for customer with a certain ID.   
object oriented programming java Create a Student class that have two data members id (assign to...
object oriented programming java Create a Student class that have two data members id (assign to your ID) and name (assign to your name). Create the object of the Student class by new keyword and printing the objects value. You may name your object as Student1. The output should be like this: 20170500 Asma Zubaida
create a java class with name ModernArt: For the first part of the assignment, you will...
create a java class with name ModernArt: For the first part of the assignment, you will be extending the JApplet class and creating a work of modern using the Graphics class to draw various shapes to the applet window. As part of your masterpiece, you should incorporate the following elements: At least 1 non-solid rectangle At least 1 non-solid oval At least 1 solid oval At least 1 non-solid Polygon At least 1 solid Polygon At least 3 lines At...
Create a class Employee. Your Employee class should include the following attributes: First name (string) Last...
Create a class Employee. Your Employee class should include the following attributes: First name (string) Last name (string) Employee id (string) Employee home street address (string) Employee home city (string) Employee home state (string) Write a constructor to initialize the above Employee attributes. Create another class HourlyEmployee that inherits from the Employee class.   HourEmployee must use the inherited parent class variables and add in HourlyRate and HoursWorked. Your HourEmployee class should contain a constructor that calls the constructor from the...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A...
THIS IS JAVA PROGRAMMING 1. Create a class named Name that contains the following: • A private String to represent the first name. • A private String to represent the last name. • A public constructor that accepts two values and assigns them to the above properties. • Public methods named getProperty (e.g. getFirstName) to return the value of the property. • Public methods named setProperty ( e.g. setFirstName)to assign values to each property by using a single argument passed...
Write a class named Person with data attributes for a person’s first name, last name, and...
Write a class named Person with data attributes for a person’s first name, last name, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a calling list. Demonstrate an instance of the Customer class in a simple program. Using python
Programming language to be used: Java Exercises Part 1) The Dog Class In the first part...
Programming language to be used: Java Exercises Part 1) The Dog Class In the first part of the lab, we are writing a class to represent a Dog. It should not have a main method. Dog needs fields for price (to purchase the dog), breed, name, and age. Use appropriate data types The class should have the following two kinds of Constructors: Constructor 1: Write a constructor that accepts a value for each of the fields Constructor 2: Write a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT