Question



Build a java program that has Student class, use arrays of objects {name, age, gpa} to saves 3 students records. Use printabl
0 0
Add a comment Improve this question Transcribed image text
Answer #1

solution:

public abstract class Person {
   // data member
   protected String name;
   protected int age;
   protected double gpa;
  
   // default constructor
   public Person(){
       this.name="";
       this.age=0;
       this.gpa=0;
   }
  
   // default constructor with argument
   public Person(String nm){
       this.name=nm;
       this.age=0;
       this.gpa=0;
   }
  
   // abstract method
   abstract public void setAge(int age);
  
   // concrete method
   public void setGPA(double gpa){
       this.gpa=gpa;
   }
}

/////////////////////////////////////


public interface Printable {
   public void print();
}

/////////////////////////////////////////////


public class Student extends Person implements Printable{

   // constructor
   public Student(){
       // call super class
       super();
   }
  
   public Student(String s){
       // call super constructor
       super(s);
   }
  
   // implement method
   @Override
   public void print() {
       System.out.println(super.name+" "+super.age+" "+super.gpa);
   }

   // override abstract method
   @Override
   public void setAge(int age) {
       super.age=age;
   }

}

////////////////////////////////


public class Driver {
   public static void main(String [] args){
      
       // three array
       String [] name={"Ahmed","Ali","Islam"};
       int [] age={20,21,19};
       double [] gpa={3.5,3.7,3.9};
      
       Student [] students=new Student[3];
      
       // using three array create three student object
       for(int i=0;i<3;i++){
           students[i]=new Student(name[i]);
           students[i].setAge(age[i]);
           students[i].setGPA(gpa[i]);
       }
      
       // print them
       System.out.println("Students Records VI:");
       for(int i=0;i<3;i++){
           students[i].print();      
       }
      
   }
}
/////////////////////////////////////////////

Students Records VI: Ahmed 20 3.5 Ali 21 3.7 Islam 19 3.9

please give me thumb up

Add a comment
Know the answer?
Add Answer to:
Build a java program that has Student class, use arrays of objects {name, age, gpa} to...
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
  • PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a...

    PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a method that adds all persons Validate all input, not left empty for First Name, Last Name, Gender and numeric for age and throw an exception if it does not validate within the class. Create a Student Class that: Inherits the Person Class Accepts GPA Validate GPA (>= 0 and <= 4.0) and throw exception if it does not validate within the class. Has methods...

  • python code? 1. Create a class called Person that has 4 attributes, the name, the age,...

    python code? 1. Create a class called Person that has 4 attributes, the name, the age, the weight and the height [5 points] 2. Write 3 methods for this class with the following specifications. a. A constructor for the class which initializes the attributes [2.5 points] b. Displays information about the Person (attributes) [2.5 points] c. Takes a parameter Xage and returns true if the age of the person is older than Xage, false otherwise [5 points] 3. Create another...

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • In order to do Program 6, Program 5 should bemodified.Program 6

    In order to do Program 6, Program 5 should be modified.Program 6-----------------------------------Program 4----------------------------------------------- (abstract class exception handling) Modify program4 to meet the following requirements: I. Make Person, Employee classes to abstract classes. Cl0%) 2. Add an interface interface working with a method teach() (5%) interface working void teach(String course) J 3. Modify Faculty class. (20%) a. a private data field and implement existing b. Modify Faculty class as a subclass of addition to the c. toString or print Info) method to...

  • Consider the Tollowing class declaration: class student record public: int age; string name; double gpa; }:...

    Consider the Tollowing class declaration: class student record public: int age; string name; double gpa; }: Implement a void function that initiatizes a dynamic array of student records with the data stored in the file "university body.txt". The function has three formal parameters: the dynamic array "S db, the count, and the capacity. Open and close an ifstream inside the function. Remember, you must allocate memory for the initial size of the dynamic array using "new" inside this function. If...

  • Java Project In Brief... For this Java project, you will create a Java program for a...

    Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....

  • C++ There is a class called Person which has name and age as private variables. Another...

    C++ There is a class called Person which has name and age as private variables. Another class called Student, which is derived from person with gpa and id as variables. name is a string, age and id are integers and gpa is a double... All of them are private variables. age, gpa and id should be generated randomly when the object is created with the following ranges: age 20 to 32 gpa 0.0 to 4.0 // this one is tricky...

  • Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman...

    Implement an abstract class named Person and two subclasses named Student and Staff in Java. A person has a name, address, phone number and e-mail address. A student has a credit hour status (freshman, sophomore, junior, or senior). Define the possible status values using an enum. Staff has an office, salaray, and date-hired. Implement the above classes in Java. Provide Constructors for classes to initialize private variables. Getters and setters should only be provided if needed. Override the toString() method...

  • Language: Java 30 pts. ) - This assignment revisits the student parsing program from earlier in...

    Language: Java 30 pts. ) - This assignment revisits the student parsing program from earlier in the quarter, but challenges you to restructure the component pieces of the program to create a cleaner, more succinct Main(). You will generate a Student class of object and load an Array List with student objects, then report the contents of that Array List. To do so, you must perform the following: A)(10 /30 pts.)- Generate a class file “myStudent.java” (which will generate myStudent.class...

  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. 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