Super class and sub class advise


Java Forum
I first apologize for that long long topic, but i actually require advise.
I require some advise with my homework coding, I m cemented on that one part but before this here is what the trouble is: XML Code part: Develop a set of classes for a college to use in miscellaneous student service and personnel
applications. Classes you require to design include the following:
u PersonA Person contains a first name, last name, street address, zip code part, and
phone number. The class also includes a method this sets each raw data field, using a
series of dialog boxes and a to show method this displays all of a Persons
information on only one line at the command line on the screen.
u CollegeEmployeeCollegeEmployee descends from Person. A CollegeEmployee
also includes a Social Security number, an annual salary, and a department name,
as well as methods this override the Person methods to accept and to show all
CollegeEmployee raw data.
u FacultyFaculty descends from CollegeEmployee. This class also includes a
Boolean field this indicates though the Faculty member is tenured, as well as
methods this override the CollegeEmployee methods to accept and to show this
additional piece of information.
u StudentStudent descends from Person. In addition to the fields available in
Person, a Student contains a major field of study and a grade suggest average as
well as methods this override the Person methods to accept and to show those
additional facts.
Write an application named CollegeList this declares an array of four regular
CollegeEmployees, three Faculty, and seven Students. Prompt the user to specify
which type of persons raw data will be entered (C, F, or S), or permission the user to quit
(Q). While the user chooses to continue (that is, does not quit), accept raw data entry
for the appropriate type of Person. If the user attempts to enter raw data for more than
four CollegeEmployees, three Faculty, or seven Students, to show an error message.
When the user quits, to show a report on the screen listing each group of Persons
under the appropriate heading College Employees, Faculty, or Students. If the
user has not entered raw data for one or more types of Persons during a session, to show
an appropriate message under the appropriate heading.
Save the files as Person.java, CollegeEmployee.java, Faculty.java, Student.java,
and CollegeList.java. mh_sh_highlight_all('xml');
Check list:
I already done Person.java, CollegeEmployee.java, Faculty.java, Student.java.
Trouble:
Cemented on CollegeList.java
Underneath is my code for Person.java the parent(base) class Java Code: import javax.swing.JOptionPane;
public class Person
{
protected String firstName;
protected String lastName;
protected String address;
protected String zipCode;
protected String phoneNumber;
*
public Person(String firstName, String lastName, String address, String zipCode, String phoneNumber)
{
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.zipCode = zipCode;
this.phoneNumber = phoneNumber;
}
*
public void setFirstName(String firstName)
{
this.firstName = firstName;
}
public void setLastName(String lastName)
{
this.lastName = lastName;
}
public void setAddress(String address)
{
this.address = address;
}
public void setZipCode(String zipCode)
{
this.zipCode = zipCode;
}
public void setphoneNumber(String phoneNumber)
{
this.phoneNumber = phoneNumber;
}
public String getFirstName()
{
return firstName;
}
public String getLastName()
{
return lastName;
}
public String getAddress()
{
return address;
}
public String getZipCode()
{
return zipCode;
}
public String catchphoneNumber()
{
return phoneNumber;
}
public void to show()
{
JOptionPane.showMessageDialog(null, firstName + lastName + " lives in " + address + ", " + zipCode + "Tel: " + phoneNumber, "Information", JOptionPane.Problem_MESSAGE);
}
} mh_sh_highlight_all('java');
CollegeEmployee.java a child class extended from Person Java Code: import javax.swing.JOptionPane;
public class CollegeEmployee extends Person
{
protected String ssn;
protected twice annSalary;
protected String department;
public CollegeEmployee()
{
super();
}
public void setSSN(String ssn)
{
this.ssn = ssn;
}
public void setAnnSalary(double annSalary)
{
this.annSalary = annSalary;
}
public void setDepartment(String department)
{
this.department = department;
}
public String getSSN()
{
return ssn;
}
public double getAnnSalary()
{
return annSalary;
}
public String getDepartment()
{
return department;
}
public void to show()
{
super.to show();
JOptionPane.showMessageDialog(null, " nSSN: " + getSSN() + " nAnnual Salary: " + getAnnSalary() + " nDepartment: " + getDepartment(), "Information", JOptionPane.Problem_MESSAGE);
}
} mh_sh_highlight_all('java');
Faculty.java a child class extended from CollegeEmployee. Java Code: import javax.swing.JOptionPane;
public class Faculty extends CollegeEmployee
{
protected boolean tenured;
public Faculty()
{
super();
if(tenured)
tenured = true;
else
tenured = false;
}
public void to show()
{
super.to show();
JOptionPane.showMessageDialog(null, "Tenured: " + tenured, "Information", JOptionPane.Problem_MESSAGE);
}
} mh_sh_highlight_all('java');
Student.java extended from Person.java Java Code: import javax.swing.JOptionPane;
public class Student extends Person
{
protected String major;
protected double gradePointAverage;
public Student()
{
super();
}
public void setMajor(String major)
{
this.major = major;
}
public void setGPA(double gradePointAverage)
{
this.gradePointAverage = gradePointAverage;
}
public String getMajor()
{
return major;
}
public double getGPA()
{
return gradePointAverage;
}
public void to show()
{
super.to show();
JOptionPane.showMessageDialog(null, " nMajor: " + getMajor() + " nGPA: " + getGPA(), "Information", JOptionPane.Problem_MESSAGE);
}
} mh_sh_highlight_all('java');
And here is my main class CollegeList.java, I am cemented at this one part where I am struggling to store what the user enters into my arrays: Java Code: import java.util.Scanner;
public class CollegeList
{
public static void main(String[] args)
{
CollegeEmployee[] group1 = new CollegeEmployee[4];
Faculty[] group2 = new Faculty[3];
Student[] group3 = new Student[7];
Scanner scan = new Scanner(System.in);
String response;
String fname;
String lname;
String address;
String zip;
String phone;
String cont ="Y";
String QUIT = "Q";
System.out.println("(C)ollege employee, (F)aculty or (S)tudent, (" + QUIT + ") to quit:");
response = scan.nextLine();
switch (response)
{
case "C":
while(cont.equals("Y"))
{
int i = 0;
System.out.println("Enter first name: ");
fname = scan.nextLine();
group1[i].setFirstName(fname);
System.out.println("Enter last name: ");
lname = scan.nextLine();
group1[i].setLastName(lname);
System.out.println("Enter address: ");
address = scan.nextLine();
group1[i].setAddress(address);
System.out.println("Enter zip code: ");
zip = scan.nextLine();
group1[i].setZipCode(zip);
System.out.println("Enter phone number: ");
phone = scan.nextLine();
group1[i].setphoneNumber(phone);
System.out.println("Enter more (Y N)");
cont = scan.nextLine();
i++;
}
}
}
} mh_sh_highlight_all('java');
When I compile and compile, it compiled right but when I enter name it gives me this error: Java Code: ----jGRASP exec: java CollegeList
(C)ollege employee, (F)aculty or (S)tudent, (Q) to quit:
C
Enter first name:
John
Exception in thread "main" java.lang.NullPointerException
at CollegeList.main(CollegeList.java:33)
----jGRASP wedge2: EXIT code for process is 1.
----jGRASP: operation complete. mh_sh_highlight_all('java');


View Complete with Replies


RELATED TOPICS OF Java PROGRAMMING LANGUAGE




Exception passing from super to sub class

Im fascinated is that the much satisfactory way to use exception handling. I've got a Super class address and 2 subclasss called shop and person.
The address class throws a custom exception called lesson1exception, which is just a string informing

VIEWS ON THIS POST

10

Posted on:
Tuesday, October 16, 2012
View Replies !

Thread: private raw data of super class

After removing super.getx1() where i compose unnecessarily my
import java.awt.Window.*;
import java.awt.Graphics.*;
import java.lang.*;public class MyOval extends MyShape{
private int x;
private int y;
private twice width;
private twice height;
My

VIEWS ON THIS POST

10

Posted on:
Wednesday, October 17, 2012
View Replies !

Junit3 error: Implicit super constructor TestCase() is not visible

The following code part has that error compiled in Eclipse:
Implicit super constructor TestCase() is not visible. Must explicitly invoke another constructor package com.my.prog;
import junit.framework.*;
import javax.naming.*;
import javax.rmi.PortableRemoteObject;

VIEWS ON THIS POST

30

Posted on:
Wednesday, October 17, 2012
View Replies !

Getting bother with inheriting constructor from superclass

I'm fairly newcomer to inheritance such I'm not actually sure what I'm doing incorrect. The class I've written "SoldCar" is supposed to represent a car this has been sold (obviously) and extends the "Car" class I have written. At line 18 I catch an error say
VIEWS ON THIS POST

21

Posted on:
Friday, October 19, 2012
View Replies !

supernewb nosucka

Caused by: java.lang.ClassNotFoundException: JVA.remote.__EJB31_Produced__BookEJB__Intf____Bea n__ (no security manager:
RMI class loader disabled)
helpma plz.

VIEWS ON THIS POST

9

Posted on:
Friday, October 19, 2012
View Replies !

calling to superclass/constructors queries.

friends im doing a lesson on Polymorphism, and i have a fundamental problem, not actually regarding polymorphism, but the fundamental of a constructor problem.
i have an entire group of java source programs,
Employee.java (abstract) then 4 c

VIEWS ON THIS POST

27

Posted on:
Friday, October 19, 2012
View Replies !

subclass calling superclass method

I am getting bother calling superclass method. Here is recent code part Java Code: import java.util.*;
public class Mercedes
{
protected int [] ix = new int [50];
protected int chamu;
protected int icounter;
Class constructor
public Mercedes (

VIEWS ON THIS POST

20

Posted on:
Friday, October 19, 2012
View Replies !

super

to everybody. I wish to parse some variables from the superclass to subclass i ve tried to use supper in the following illustration but it doesn t work. Someone can advise
That is the superclass:
*
* To alter that template pick T

VIEWS ON THIS POST

9

Posted on:
Friday, October 19, 2012
View Replies !

Use super. or that.

Say i have two classes: Java Code part: public class A {
protected String name;
}
public class B extends A {
here i wish to use the name defined in the parent how should i reference it
should i use super:
super.name;
or should i use that
t

VIEWS ON THIS POST

9

Posted on:
Friday, October 19, 2012
View Replies !

Thread: Why do we use super when there is no superclass?

Hi
I have a problem about the word "super " and the constructor. I have read about super and the constructor but there is somethong this I do not understand.
In the illustration this I am studying there is a constructor calles " public MultiListener()" and

VIEWS ON THIS POST

17

Posted on:
Friday, October 19, 2012
View Replies !

Thread: When should a subclass have its own fields and when should it use its super

When should a subclass have its own fields and when should it use its superclass' fields
Thanx for reading and given your 's valuable time. that topic
Let me use a categorical illustration to ask my problem.
public class BankAccount {
p

VIEWS ON THIS POST

7

Posted on:
Friday, October 19, 2012
View Replies !

Thread: private raw data of super class

if we are using the private raw data of the super class in the subclass by using the super keyword super.getx1(); and writing the if statements if((x1 x1))
the error is coming as x1 has private access in the super class how to get back the error in that Program.
public v

VIEWS ON THIS POST

5

Posted on:
Saturday, October 20, 2012
View Replies !

plz advise super newcomer to Java

I am newcomer to Java and to be honest I am kind of lost plz advise me figure out what is incorrect with my code part.
i have to write a code this prompts the user for a password using 6 to 10 characters using a letter.
My apologies if I am posting t

VIEWS ON THIS POST

7

Posted on:
Sunday, October 21, 2012
View Replies !

Referring to a super class

Hi I was just asked a problem out of a text book I am reading and I can not remember for the life of me how to refer to a super class when you are writing with in a static method.
I understand the first thought is super.methodName(), but this doesn't se

VIEWS ON THIS POST

19

Posted on:
Thursday, October 25, 2012
View Replies !

Private or Protected access for super class variables

What is the better practice...
Guess there is a class hierachy like
Person (Super class) StaffMember Professor (Sub class)
1) The better way is to keep all the illustration variables of each and every class private and access the private variables of super

VIEWS ON THIS POST

24

Posted on:
Thursday, October 25, 2012
View Replies !

Inheritance and (super)

friends. I wanted to ask about after I derive a class from another class ( super class from base class) and when writing the constructor of the new derived class sometimes its like that
public derivedClass(String name int number , twice something){
Super(name)
---

VIEWS ON THIS POST

14

Posted on:
Thursday, October 25, 2012
View Replies !

super beginner managing from terminal

Is it an applet
if not you could attempt typing "dir" and check if the file is really in the directory you are in

Expel the package statement from your 's programme
Did you attempt what I recommended above
I donot like ID

VIEWS ON THIS POST

12

Posted on:
Thursday, October 25, 2012
View Replies !

Can you copy derived classes of the same superclass?

Wordy version: Only one superclass has 2 dissimilar derived classes.
Looking for a way to copy one derived class to the other.
Scenario: Superclass S exists. 2 classes are derived from and extend,
S. The 2 classes are A and B. A and B have unique members this neithe

VIEWS ON THIS POST

6

Posted on:
Sunday, November 04, 2012
View Replies !

useing the program in computer in a very super'p in the world

Hi Hey..... i donot understand computer in past 5 year this time i dont
like in the computer but now i konw in computer some software i like
very most............ every day 12 hr now i am siting in computer this
is a wonderful software in the wor

VIEWS ON THIS POST

6

Posted on:
Sunday, November 04, 2012
View Replies !

cannot call super from method but I wish to??

Look underneath how can I call animals growl while with in a method of my
interface (I require this - cannot catch rid of it).
public class animal {
public void growl() {
System.out.println("growl");
}
}
public class dog

VIEWS ON THIS POST

13

Posted on:
Sunday, November 04, 2012
View Replies !

  • T = 0

  • Copyright 2012 © SolveThisError.com. All rights reserved. Terms of use  |  Privacy Policy