3 Replies - 2041 Views - Last Post: 12 December 2012 - 01:13 PM Rate Topic: -----

#1 Abbas Ali  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 10-March 12

College Class ?

Posted 11 December 2012 - 05:17 AM

Hello ,

i have a problem in this , i tried to write a code for college class but i can't got it :(

Question:-
Design an Abstract class named Person and its two subclasses. A class named

Student and an Abstract class named Employee. Make Administrator and

Staff subclasses of Employee. A person has a name, address, phone number,

and email address. A student has a class status (freshman, sophomore,

junior, or senior). Define the status as a constant. An employee has an office,

salary, and date-hired. Define a class named MyDate that contains the fields

year, month, and day. A faculty member has office hours and a rank. A staff

member has a title. Override the toString method in each class to display the

class name and the person's name.

Design a class called College having a name and group of Students,

Administrators and Staff members. A College will accept Students until a

negative phone number is entered, while the Administrators and the Staff

members are input by the user. However, any College can't accept more

than 1000 Students, 135 Administrators and 200 Staff members.

My Code

public abstract class Person 
{ 
	String name; 
	String Address;
    int PhoneNum; 
    String Email ;
  
    public String toString() 
    {
    	return "Person  name";
     }

}
======================================

public class Student extends Person
{
      String  freshman;
	  String  sophomore;
	  String  junior; 
	 
	  public String toString() 
	  {
	    	return "Student extends Person";
	  }
}
===========================================

public class Employee extends Person
{    int OfficeNum ; 
     int salary ; 
     int DateHired; 
   
     public void SetOfficeNum(int x) 
     {
    	 this.OfficeNum=x;
     }
	  
     public int GetOfficeNum() 
     {
    	 return OfficeNum;
     }
  
     
     public void SetSalary(int x) 
     {
    	 this.salary=x;
     }
	  
     public int Getsalary() 
     {
    	 return salary;
     } 

     public void SetDateHired(int x) 
     {
    	 this.DateHired=x;
     }
	  
     public int GetDateHired() 
     {
    	 return DateHired;
     }  
  
     public String toString() 
	    {
	    	return "Employee extends Person";
	     }
}
================================================

public class Administrator extends Employee
{
   int OfficeHours; 
   String Rank; 

   public void SetOfficeHours(int x) 
   {
  	 this.OfficeHours=x;
   }
	  
   public int GetOfficeHours() 
   {
  	 return OfficeHours;
   } 

   public void SetRank(String x) 
   {
  	 this.Rank=x;
   }
	  
   public String GetRank() 
   {
  	 return Rank;
   }
  
   public String toString() 
   {
   	return "Administrator extends Employee";
    }

}
==================================================

public class Staff extends Employee
{
   
	String title;  
	public void SetTitle(String x) 
	   {
	  	 this.title=x;
	   }
		  
	   public String GetTitle() 
	   {
	  	 return title;
	   }
	   
	   public String toString() 
	   {
	   	return " Staff extends Employee";
	    }

}
========================================================= 
import javax.swing.JOptionPane;
public class College 
{     
        String name;
        Student []A1=new Student[1000]; 
        Administrator []A2=new  Administrator[135]; 
        Staff []A3=new Staff[200];      
       public void Students()
       {  String z=JOptionPane.showInputDialog("please enter student num:    "); 
          int x=Integer.parseInt(z);
    	   while (x<=A1.length)
           {
             	String a=JOptionPane.showInputDialog("please enter student name:      "); 
                this.name=a; 
            }
       }
}  



Is This A Good Question/Topic? 0
  • +

Replies To: College Class ?

#2 ipushmycar  Icon User is offline

  • D.I.C Regular

Reputation: 86
  • View blog
  • Posts: 390
  • Joined: 29-August 10

Re: College Class ?

Posted 11 December 2012 - 06:18 AM

You need to review classes.

http://docs.oracle.c...OO/classes.html

Or these:
http://www.dreaminco..._1&#entry391713

http://www.dreaminco...ing-classes-ii/

This post has been edited by ipushmycar: 11 December 2012 - 06:22 AM

Was This Post Helpful? 0
  • +
  • -

#3 Abbas Ali  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 2
  • Joined: 10-March 12

Re: College Class ?

Posted 12 December 2012 - 11:02 AM

View Postipushmycar, on 11 December 2012 - 06:18 AM, said:



ok that's really good but it's not my problem it's in class college it breaks in the pint that i can't understand ???

 
import javax.swing.JOptionPane;


public class College extends Person {
	
	
	String name;
	Student [] s=new Student [1000];
	Administrator [] a=new Administrator [135];
	Staff [] st=new Staff[200];
	
	
	public void input (){ 
		int i=0;
		int y=0;
		int z=0;
		String check=JOptionPane.showInputDialog("Would you like to input student,administrator or staff");
		if(check == "student" )
		{
		while (i<1000)
		{
		s[i].setName(JOptionPane.showInputDialog("Enter student's name"));
		String status=JOptionPane.showInputDialog("Enter "+s[i].getName()+"'s status"+"\nfreshman,sophomore,junior or senior");
		if(status=="freshman")
			s[i].setclassStatus("Freshman");
		else if (status=="sophomore")
			s[i].setclassStatus("Sophomore");
		else if (status=="senior")
			s[i].setclassStatus("Senior");
		else if (status=="junior")
			s[i].setclassStatus("Junior");
		else 
			s[i].setclassStatus("Wrong status");
		
		
		s[i].setAddress(JOptionPane.showInputDialog("Enter "+s[i].getName()+"'s address"));
		s[i].setEmail(JOptionPane.showInputDialog("Enter "+s[i].getName()+"'s e-mail address"));
		String pho=JOptionPane.showInputDialog("Enter "+s[i].getName()+"'s phone");
		s[i].setPhone(Integer.parseInt(pho));
		i++;
	}
		}
	
	
	else if(check=="staff")
	{
		while (y<200 && st[y].getPhone()>0)
		{
		st[y].setName(JOptionPane.showInputDialog("Enter the name of staff"));
		st[y].setTitle(JOptionPane.showInputDialog("Enter "+st[y].name+"'s"+" title"));
		st[y].address=JOptionPane.showInputDialog("Enter "+st[y].name+"'s"+" address");
		st[y].emailadrress=JOptionPane.showInputDialog("Enter "+st[y].name+"'s"+" e-mail address");
		String pho=JOptionPane.showInputDialog("Enter "+st[y].name+"'s"+" phone");
		st[y].phone=Integer.parseInt(pho); 
		String Office=JOptionPane.showInputDialog("Enter "+st[y].name+"'s"+" office number");
		st[y].officeNum=Integer.parseInt(Office);
		String Sal=JOptionPane.showInputDialog("Enter "+st[y].name+"'s"+"salary");
		st[y].salary=Integer.parseInt(Sal); 
		y++;
	   }
	}
	else if(check=="administrator")
	{
		while (z<135 && a[z].phone>0)
		{
		a[z].name=JOptionPane.showInputDialog("Enter the name of Administrator");
		a[z].address=JOptionPane.showInputDialog("Enter "+a[z].name+"'s"+" address");
		a[z].emailadrress=JOptionPane.showInputDialog("Enter "+a[z].name+"'s"+" e-mail address");
		String pho=JOptionPane.showInputDialog("Enter "+a[z].name+"'s"+" phone");
		a[z].phone=Integer.parseInt(pho); 
		String Office=JOptionPane.showInputDialog("Enter "+a[z].name+"'s"+" office number");
		a[z].officeNum=Integer.parseInt(Office);
		String Ohours=JOptionPane.showInputDialog("Enter "+a[z].name+"'s"+" office hours");
		a[z].officeHours=Integer.parseInt(Ohours); 
		a[z].rank =JOptionPane.showInputDialog("Enter "+a[z].name+"'s"+" rank"); 
		String Sal=JOptionPane.showInputDialog("Enter "+a[z].name+"'s"+"salary");
		a[z].salary=Integer.parseInt(Sal); 
		z++;

	}
	}
	}
	
	
}



Sorry , i forget to mention that break in this line after
 
 		String check=JOptionPane.showInputDialog("Would you like to input student,administrator or staff");



Was This Post Helpful? 1
  • +
  • -

#4 darek9576  Icon User is offline

  • D.I.C Lover

Reputation: 198
  • View blog
  • Posts: 1,693
  • Joined: 13-March 10

Re: College Class ?

Posted 12 December 2012 - 01:13 PM

Since when College IS-A Person? One of the uses of Inheritance is a notion of specialization.
For example:

an Employee is a special kind of Person - it is a Person + other related things. Your design is wrong.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1