Question

In: Computer Science

Please finish the following JAVA Codes: 1. The class Person includes information of a person’s first...

Please finish the following JAVA Codes:

1. The class Person includes information of a person’s first name, last name, phone number, and email. Implement the class with appropriate constructors, getters and setters.

2. Derive a Student class that extends Person. In addition to a person’s information, a student has major, year, GPA, and a list of enrolled courses. In addition to appropriate constructors, getters and setters, make two methods addCourse and dropCourse.

3. Design and implement a program, either in main() or in another class, that calculates the GPA of a student. The student’s courses should be displayed in console, one at a time, and the grade of the course will be input to console by user. After all grades were input, the GPA should be displayed and be recorded in the student object.

Solutions

Expert Solution

hey i am done with the code .. here is the code ...

i had face a problem with major variable .. i dont know what the role of the major variable .. so i not include major variable in any calculation in the GPA .. you can change it on your own ..

here is the final code ---

Person.java


package studentgpa;

/**
*
* @author Aditya kumar
*/
public class Person {
String firstname , lastname ,email;
long mobileno ;

public Person(String firstname, String lastname, String email, long mobileno) {
this.firstname = firstname;
this.lastname = lastname;
this.email = email;
this.mobileno = mobileno;
}

public Person() {
}
//setters and getters
public String getFirstname() {
return firstname;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public String getLastname() {
return lastname;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public long getMobileno() {
return mobileno;
}

public void setMobileno(long mobileno) {
this.mobileno = mobileno;
}
  

  
  
}

StudentGPA.java

package studentgpa;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class StudentGpa extends Person{
int major ;
int year ;
List<String> course=new ArrayList<>(); //holds the course
List<String> grade=new ArrayList<>(); //holds the grade

public StudentGpa() {
}
//contructor with super constructor of Person Class
public StudentGpa(int major, int year, List<String> course, String firstname, String lastname, String email, long mobileno) {
super(firstname, lastname, email, mobileno);
this.major = major;
this.year = year;
this.course = course;
}
//setter and getters
public int getMajor() {
return major;
}

public void setMajor(int major) {
this.major = major;
}

public int getYear() {
return year;
}

public void setYear(int year) {
this.year = year;
}

public List<String> getCourse() {
return course;
}
public List<String> getGrade() {
return grade;
}
//add course method .... we also add the grade along with course
public void addCourse(String coursename) {
course.add(coursename);
System.out.println("Add Grade of the course : ");
Scanner sc=new Scanner(System.in);
grade.add(sc.next());
}
public void dropCourse(String position)
{//for this first get the index of the subject from course and if subject succefully removed
// we can put the index value into grade list to remove the related grade
int index=course.indexOf(position);
boolean b=course.remove(position);
if(b)
{
  
grade.remove(index);
System.out.println("Successfully deleted ");
}
}

/**
* @param args the command line arguments
*/
  
  
  
public static void main(String[] args) {
// TODO code application logic here
  
StudentGpa studentGpa=new StudentGpa();
System.out.println("Enter Person's Details : ");
System.out.println("Enter First Name of Person : ");
Scanner sc=new Scanner(System.in);
studentGpa.setFirstname(studentGpa.firstname=sc.next());
System.out.println("Enter Person's Last Name ");
studentGpa.setLastname(studentGpa.lastname=sc.next());
System.out.println("Enter Person's phone number : ");
studentGpa.setMobileno(studentGpa.mobileno=sc.nextLong());
System.out.println("Enter Person's Email : ");
studentGpa.setEmail(studentGpa.email=sc.next());
System.out.println("Enter Person's major "); //here we assume major as credit of the subject
studentGpa.setMajor(studentGpa.major=sc.nextInt());
System.out.println("Enter year : ");
studentGpa.setYear(studentGpa.year=sc.nextInt());
System.out.println("Enter the total number of course : ");
  
int coursenumber=sc.nextInt();
for (int i=1;i<=coursenumber;i++)
{
System.out.println("Enter "+i+" Course : ");
String coursename=sc.next();
studentGpa.addCourse(coursename);
}
  
// to drop the course
/*
System.out.println("Enter the subject");
String remove=sc.next();
studentGpa.dropCourse(remove);
  
  
  
*/
  
//print information
  
System.out.println( studentGpa.getFirstname());//first name
System.out.println(studentGpa.getLastname());//last name
System.out.println(studentGpa.getMobileno());//mobile no
System.out.println(studentGpa.getEmail());//email
System.out.println(studentGpa.getMajor());//major
System.out.println(studentGpa.getYear());//year
System.out.println(studentGpa.getCourse());//total subject
System.out.println(studentGpa.getGrade()); //all grades
  
float total =0;
int count=0;
String gradename="";
Iterator iterator = studentGpa.grade.iterator();
while(iterator.hasNext()) {
gradename=(String) iterator.next();
count++;
//calculate total gradepoints
switch(gradename)
{
case "A" : total=total+3*4; //3 is credit and 4 is Grade value
break;
case "B" : total=(float) (total+3*3.3); //we assume 3 is the credit and 3.3 is grade value
break;
case "C" : total=(float) (total+3*2.7); //we assume 3 is credit and 2.7 is grade value

default: System.out.println("No Such Grade ");
}
}
float OverallGPA=total/count;
  
  
System.out.println("Overall Grade is :"+OverallGPA);
//print overall GPA
  
}
  
  
}

  

and here is the snapshot of the output ---

i hope it was helpful for you ,. Please give me a like to appreciate my effort and work .. and feel free to comment regarding this question .. I am happy to help you . Thank YOu !


Related Solutions

(Java) Design a class named Person with fields for holding a person’s name, address, and telephone...
(Java) Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator and...
JAVA PROGRAM: FINISH THE FOLLOWING METHOD IN THE CLASS BasicBioinformatics. public class BasicBioinformatics { /** *...
JAVA PROGRAM: FINISH THE FOLLOWING METHOD IN THE CLASS BasicBioinformatics. public class BasicBioinformatics { /** * Calculates and returns the reverse complement of a DNA sequence. In DNA sequences, 'A' and 'T' * are complements of each other, as are 'C' and 'G'. The reverse complement is formed by * reversing the symbols of a sequence, then taking the complement of each symbol (e.g., the * reverse complement of "GTCA" is "TGAC"). * * @param dna a char array representing...
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user...
Java Codes: 1. Create a class named Proficiency1Practice In the main method, first ask the user to enter a short sentence which ends in a period. Use Java String class methods to determine the following about the sentence and display in the console: • How many total characters are in the sentence? • What is the first word of the sentence? Assume the words are separated by a space. • How many characters are in the first word of the...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone...
JAVA/Netbeans •Design a class named Person with fields for holding a person’s name, address and phone number (all Strings) –Write a constructor that takes all the required information. –Write a constructor that only takes the name of the person and uses this to call the first constructor you wrote. –Implement the accessor and mutator methods. Make them final so subclasses cannot override them –Implement the toString() method •Design a class named Customer, which extends the Person class. It should have...
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
In C# thanks please, Design a class named Person with properties for holding a person’s name,...
In C# thanks please, Design a class named Person with properties for holding a person’s name, address, and telephone number. Design a class named Customer, which is derived from the Person class. The Customer class should have the variables and properties for the customer number, customer email, a spentAmount of the customer’s purchases, and a Boolean variable indicating whether the customer wishes to be on a mailing list. It also includes a function named calcAmount that calculates the spentAmount. All...
to be done in java Your task is to finish the StockItem class so that it...
to be done in java Your task is to finish the StockItem class so that it meets the following criteria • The StockItem class will have 4 attributes: a stock number; a name; the price of the item; the total number of items currently in stock • The first three of the above characteristics will need to be set at the time a StockItem object is created, with the total number of items set to 0 at this time. The...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name...
in Java, Create a class called EMPLOYEE that includes three instance variables – a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test app names EmployeeTest that demonstrates class EMLOYEE’s capabilities. Create two EMPLOYEE objects and display each object’s yearly...
Simple Java class. Create a class Sportscar that inherits from the Car class includes the following:...
Simple Java class. Create a class Sportscar that inherits from the Car class includes the following: a variable roof that holds type of roof (ex: convertible, hard-top,softtop) a variable doors that holds the car's number of doors(ex: 2,4) implement the changespeed method to add 20 to the speed each time its called add exception handling to the changespeed method to keep soeed under 65 implement the sound method to print "brooom" to the screen. create one constructor that accepts the...
Please finish this code (Java) 1. Fill in the compare methods for the CompareByPlayoffsAndSalary and CompareByWinsLossesChamps...
Please finish this code (Java) 1. Fill in the compare methods for the CompareByPlayoffsAndSalary and CompareByWinsLossesChamps classes 2. In the CompareByPlayoffsAndSalary the compare method should list: (a) teams that made the playoffs last year before teams that did not. (b) If this is the same then it should list teams with lower salary first. 3. In the CompareByWinsLossesChamps list: (a) teams with more wins first. (b) If the same then list by teams with fewer losses. (c) If this is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT