Super class and sub class assist


Java Forum
I first apologize for this long long post, but i really want assist.
Any body assist me with my homework coding, I am stuck on this one part but before that Here's what the difficulty is: XML Code snippet: Develop a set of classes for a college to use in different student service and personnel
applications. Classes u want to design include the following:
u PersonA Person contains a first name, last name, street address, zip code snippet, and
phone number. The class also includes a method that sets each data field, using a
series of dialog boxes and a show method that shows all of a Persons
information on 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 that override the Person methods to accept and show all
CollegeEmployee data.
u FacultyFaculty descends from CollegeEmployee. This class also includes a
Boolean field that indicates if the Faculty member is tenured, as well as
methods that override the CollegeEmployee methods to accept and 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 point average as
well as methods that override the Person methods to accept and show these
additional facts.
Write a software named CollegeList that declares an array of four regular
CollegeEmployees, three Faculty, and seven Students. Prompt the user to specify
which type of persons data will be entered (C, F, or S), or let the user to quit
(Q). While the user chooses to continue (that is, does not quit), accept data entry
for the appropriate type of Person. If the user attempts to enter data for more than
four CollegeEmployees, three Faculty, or seven Students, show an error.
When the user quits, 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 data for one or more types of Persons during a session, 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.
Difficulty:
Stuck on CollegeList.java
Given below 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 receivephoneNumber()
{
return phoneNumber;
}
public void show()
{
JOptionPane.showMessageDialog(null, firstName + lastName + " lives in " + address + ", " + zipCode + "Tel: " + phoneNumber, "Information", JOptionPane.QUESTION_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 double 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 show()
{
super.show();
JOptionPane.showMessageDialog(null, " nSSN: " + getSSN() + " nAnnual Salary: " + getAnnSalary() + " nDepartment: " + getDepartment(), "Information", JOptionPane.QUESTION_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 show()
{
super.show();
JOptionPane.showMessageDialog(null, "Tenured: " + tenured, "Information", JOptionPane.QUESTION_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 show()
{
super.show();
JOptionPane.showMessageDialog(null, " nMajor: " + getMajor() + " nGPA: " + getGPA(), "Information", JOptionPane.QUESTION_MESSAGE);
}
} mh_sh_highlight_all('java');
And Here's my main class CollegeList.java, I'm stuck at this one part where I'm attempting 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 execute, 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

I am admiring is this the most effective way to use exception handling. I have got a Super class location and 2 subclasss called shop and person.
The location class throws a custom exception called lesson1exception, that is just a string informing the used of t

VIEWS ON THIS POST

3

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

Thread: private data of super class

After removing super.getx1() where i spell 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 double width;
private double height;
MyOval(){
thi

VIEWS ON THIS POST

2

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

Junit3 error message: Implicit super constructor TestCase() isn't visible

The following code snippet has this error message compiled in Eclipse:
Implicit super constructor TestCase() isn't visible. Must explicitly invoke another constructor package com.my.prog;
import junit.framework.*;
import javax.naming.*;
import javax.rmi.Porta

VIEWS ON THIS POST

2

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

Having problem with inheriting constructor from superclass

I'm fairly newbie to inheritance so I'm not really sure what I'm doing wrong. The class I have written "SoldCar" is supposed to represent a car that has been sold (obviously) and extends the "Car" class I have written. At line 18 I receive an error message saying
Sol

VIEWS ON THIS POST

3

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

supernewb nosucka

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

VIEWS ON THIS POST

4

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

calling to superclass/constructors questions.

guys I am doing a lesson on Polymorphism, and I've a introductory question, not really regarding polymorphism, but the introductory of a constructor question.
I've an entire group of java softwares,
Employee.java (abstract) then 4 classes
comm

VIEWS ON THIS POST

8

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

subclass calling superclass method

I am having problem calling superclass method. Here's recent code snippet 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

10

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

super

to everybody. I need to parse some variables from the superclass to subclass i ve tried to use supper in the following example but it doesn t work. Anybody can assist
This is the superclass:
*
* To alter this template select Tools | Templates
*

VIEWS ON THIS POST

5

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

Use super. or this.

Say I've two classes: Java Code snippet: public class A {
protected String name;
}
public class B extends A {
here i need to use the name defined in the parent how should i reference it
should i use super:
super.name;
or should i use this

VIEWS ON THIS POST

3

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

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

Hello
I have a question about the word "super " and the constructor. I have read about super and the constructor but there is somethong that I do not understand.
In the example that I'm studying there is a constructor calles " public MultiListener()" and there u can view

VIEWS ON THIS POST

5

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
thank u for reading this post
Let me use a specific example to ask my question.
public class BankAccount {
private double accountBalance;
public double getBalance() {
return this.acc

VIEWS ON THIS POST

5

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

Thread: private data of super class

if We're using the private 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 message is coming as x1 has private access in the super class how can i fetch the error in this Program.

VIEWS ON THIS POST

4

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

pls assist super newbie to Java

I am newbie to Java and to be honest I am kind of lost pls assist me figure out what is wrong with my code snippet.
I've to write a code that prompts the user for a password using 6 to 10 characters using a letter.
My apologies if I am posting this in the w

VIEWS ON THIS POST

2

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

Referring to a super class

Hey I was just asked a question out of a text book I'm reading and I can't remember for the life of me how can i refer to a super class when you're writing within a static method.
I know the first thought is super.methodName(), but that does not seem to work f

VIEWS ON THIS POST

3

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

Private or Protected access for super class variables

What is the best practice...
Assume there is a class hierachy like
Person (Super class) StaffMember Professor (Sub class)
1) The best way is to keep all the instance variables of each and every class private and access the private variables of super classes by subclass construc

VIEWS ON THIS POST

4

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

Inheritance and (super)

guys. 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 this
public derivedClass(String name int number , double some thing){
Super(name)
----- rest of pro

VIEWS ON THIS POST

7

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

super newcomer executing from terminal

Is it an applet
if not u could try typing "dir" and check if the file is actually in the directory you're in

Remove the package statement from ur software
Did you try what I suggested above
I do not like IDEs for beginners because of this di

VIEWS ON THIS POST

2

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

Can u copy derived classes of the same superclass?

Wordy version: One superclass has 2 various 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 that neither
share. To

VIEWS ON THIS POST

4

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

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

hello hi..... i do not know computer in past 5 year that time i don't
like in the computer but now i konw in computer some software i like
very much............ every day 12 hr now I'm siting in computer this
is a wonderful software in the world............. http:

VIEWS ON THIS POST

1

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

can not call super from method but I want to??

View given below How do I call animals growl while within a method of my
interface (I want that - can not receive rid of it).
public class animal {
public void growl() {
System.out.println("growl");
}
}
public class dog extends

VIEWS ON THIS POST

4

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