How do I start this Java: Inheritance problem?
CODE
SOLUTION
//OUTPUT
//COPYABLE CODE
//App.java
//import the random library file
import java.util.Random;
public class App
{
// main method
public static void main(String[] args)
{
// random object
Random ran = new Random();
//declare the student athlete object for size 3
studentathlete stud[] = new studentathlete[3];
// constructor create dynamically
stud[0] = new studentathlete("devi", "Sharmi", 27, "RMD", "11", "opeatingsystem", 9.5, "Basketball", ran.nextInt(100));
stud[1] = new studentathlete("mano", "bharathi", 32, "BBR", "22", "VB.net", 4.2, "Badminton", ran.nextInt(100));
stud[2] = new studentathlete("janani", "sri", 44, "RRL", "33", "C", 5.1, "Volleyball", ran.nextInt(100));
// Loops creation
for(int x1 = 0; x1 < stud.length; x1++)
System.out.println(stud[x1].get_Info());
}
}
//Person.java
//import the random library file
import java.util.Random;
// Creates Person class
class Person
{
// create the variables first and last name
String first_Name;
String last_Name;
int age;
String home_Town;
// Default constructor
Person()
{
first_Name = last_Name = home_Town = "";
age = 0;
}
// Parameterized variables
Person(String fn1, String ln1, int ag1, String ht1)
{
first_Name = fn1;
last_Name = ln1;
home_Town = ht1;
age = ag1;
}
//get the first name
String getfirst_Name()
{
//return first name
return first_Name;
}
//get last name
String getlast_Name()
{
//return last name
return last_Name;
}
//get homw town
String gethome_Town()
{
//return home_Town
return home_Town;
}
//get age function
int getAge()
{
//return age
return age;
}
//get student info
String get_Info()
{
//return result
return "\n Name " + first_Name + " " + last_Name + "\n Home Town: " + home_Town + "\n Age: " + age;
}
}
//Student.java
// Creates a class Student inherit from Person class
class Student extends Person
{
// declare the variables ID
String ID;
//declare the variables major
String major;
//declare the gpa double
double gpa;
// Default constructor
Student()
{
// super class
super();
ID = major = "";
gpa = 0;
}
// Parameterized constructor
Student(String fn1, String ln1, int ag1, String ht1, String id1, String ma1, double gp1)
{
// super class
super(fn1, ln1, ag1, ht1);
ID = id1;
major = ma1;
gpa = gp1;
}
//get ID function
String get_ID()
{
//return ID
return ID;
}
//Get major function
String get_Major()
{
//return major
return major;
}
double get_GPA()
{
return gpa;
}
// Overrides base class
String get_Info()
{
// Concatenates information
return super.get_Info() + "\n ID: " + ID + "\n Major: " + major + "\n GPA: " + gpa;
}
}
//studentathlete.java
// Creates a class Studentathlete inherit from student class
class studentathlete extends Student
{
// declare the variables sports and rankvalue
String sports1;
int rankvalue;
// Default constructor
studentathlete()
{
// super class
super();
sports1 = "";
rankvalue = 0;
}
// Parameterized constructor
studentathlete(String fn1, String ln1, int ag1, String ht1, String id1, String ma1, double gp1, String sp1, int ra1)
{
// super class
super(fn1, ln1, ag1, ht1, id1, ma1, gp1);
sports1 = sp1;
rankvalue = ra1;
}
String get_Sports()
{
return sports1;
}
int getrankvalue()
{
return rankvalue;
}
// Overrides base class
String get_Info()
{
// Concatenates get information
return super.get_Info() + "\n Sports: " + sports1 + "\n rankvalue: " + rankvalue;
}
}
How do I start this Java: Inheritance problem? • person.java • student.java • studentAthlete.java • app.java...
**Using NetBeans** Lesson Using inheritance to reuse classes. Deliverables person.java student.java studentAthlete.java app.java Using inheritance and the classes (below) The person class has first name last name age hometown a method called getInfo() that returns all attributes from person as a String The student class is a person with an id and a major and a GPA student has to call super passing the parameters for the super class constructor a method called getInfo() that returns all attributes from student...
Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to copy your last lab (Lab 03) to a new project called Lab04. Close Lab03. Work on the new Lab04 project then. The Address Class Attributes int number String name String type ZipCode zip String state Constructors one constructor with no input parameters since it doesn't receive any input values, you need to use the default values below: number - 0 name - "N/A" type...
Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....
I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student { private String name; private double gpa; private int idNumber; public Student() { this.name = ""; this.gpa = 0; this.idNumber = 0; } public Student(String name, double gpa, int idNumber) { this.name = name; this.gpa = gpa; this.idNumber = idNumber; } public Student(Student s)...
Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...
QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members: • A private String data field named name for the name of the ship. • A private String data field named yearBuilt for the year that the ship was built. • A constructor that creates a ship with the specified name and the specified year that the ship was built. • Appropriate getter and setter methods. A toString method that overrides the toString method...
This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description: Write a program that uses inheritance features of object-oriented programming, including method overriding and polymorphism. Console Welcome to the Person Tester application Create customer or employee? (c/e): c Enter first name: Frank Enter last name: Jones Enter email address: frank44@ hot mail. com Customer number: M10293 You entered: Name: Frank Jones Email: frank44@hot mail . com Customer number: M10293 Continue? (y/n): y Create customer...
I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...
Part I (20%) [File: Student.java] Create a class called Student that has the following stored properties: • StudentID • First Name • Last Name Class Student should have read/write properties, constructor(s) and should implement the Academic interface. For academic methods, return zero for average, zero for credits and false for graduate. Also implement the toString() method that returns the above information as a String. Part II (5%) [File: Academic.java] Create an interface Academic that declares three methods: 1. average -...
Deliverables app.java, myJFrame.java, myJPanel.java and student.java as requested below. (Use the student.java class that you already have from previous labs) Contents Based on the graphics you learned this week Create an instance (an object, i.e., st1) of student in myJPanel Display his/her basic information Display for 10 times what he/she is up to (using the method whatIsUp() that your student class already has) -------------------------------------------------------------------------------------------------- \\app.java public class app { public static void main(String args[]) { myJFrame mjf = new myJFrame();...