2 Replies - 875 Views - Last Post: 08 July 2012 - 10:34 PM Rate Topic: -----

#1 aldrine  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-July 12

Registration System with the use of Inheritance and Polymorphism

Posted 08 July 2012 - 10:27 PM

Inheritance and Polymorphism

1. Create a Student Registration System.

Program Requirement

List of Classes
1. BSIT
2. BSCS
3. MSIT
4. MSCS
5. Student
6. TestStudent

Student is the base class of BSIT and BSCS
BSIT is the base class of MSIT
BSCS is the base class of MSCS

BSCS Fields
Name - String
Age - Integer
Address - String
Gender - Character
Specialization - String

BSIT Fields
Name - String
Age - Integer
Address - String
Gender - Character
Year Level - Integer

MSIT Fields
Name - String
Age - Integer
Address - String
Gender - Character
Year Level - Integer
Thesis Type - String

MSCS Fields
Name - String
Age - Integer
Address - String
Gender - Character
Specialization - String
Connected Company Type- String

Conditions on Fields
Name - Letters and Spaces only.
Age : 15 - 30 for BSIT and BSCS
25 - 30 for MSIT and MSCS
Address - Special Characters are not allowed.
Gender - m for male
f for female
Specialization: Software Engineering and Game Development for BSCS
Algorithm Design and Game Algorithm for MSCS
YearLevel: 1 - 4 for BSIT
1 - 2 for MSIT
Thesis Type - "Database","Networking",and "MIS"
Connected Company Type - "Software","Call Center",and "Parse"

The Maximum number of Students: 50

Sample Output

Registration System
1. Add Student
2. View Student
3. Exit

No of Student: 0

Choose: 1

Student
1. BSIT
2. BSCS
3. MSCS
4. MSIT
5. Back to the Main Menu

Choose: 1

BSIT
Enter Name : Hanamichi Sakuragi
Enter Age: 12
Invalid Input. Please Enter the Correct Input!!!
Enter Age: 19
Enter Address: Manila
Enter Gender: M
Enter Year Level: 2

Student
1. BSIT
2. BSCS
3. MSCS
4. MSIT
5. Back to the Main Menu

Choose: 5

Registration System
1. Add Student
2. View Student
3. Exit

No of Student: 1

Choose: 2

Name : Hanamichi Sakuragi
Age: 19
Address: Manila
Gender: M
Year Level: 2

Registration System
1. Add Student
2. View Student
3. Exit

No of Student: 1

Choose: 3

Thank You!!!

BSIT class
package mp.classobject;

public class BSIT extends Student
{	
	public String [] address = new  String[50];
	public int [] yearlevel= new int[50];
	
	public BSIT()
	{}
	public void setaddress( String Address)
	{ 
	
		for(int x=0; x<Address.length();x++)
		{
			if ((Address.charAt(x)>='A'&& Address.charAt(x)<='Z')||(Address.charAt(x)>='a'&& Address.charAt(x)<='z')||(Address.charAt(x)==' ')||(Address.charAt(x)>='0'&&Address.charAt(x)<='9'));
		
			address[ctr]= Address;
		}
		
	
	}
	public void setYEARLEVEL(int Yearlevel)
		{
			if (Yearlevel>=1&&Yearlevel<=4)
			yearlevel[ctr]=Yearlevel;
		}
	public String getdetails()
	{
		return "\nAddress:"+address[ctr]+
			"\nYearlevel: "+ yearlevel[ctr];
		}

	
	
}


Student class
package mp.classobject;
import java.util.Scanner;

public class Student
{
	Scanner scan = new Scanner(System.in);
	public String [] name = new String [50] ;
	public int [] age = new  int [50];
	public char []gender= new  char [50];
	public int [] yearlevel= new int[50];
	public int ctr;
	public TestStudent ts= new TestStudent();

	public Student()
	{}
			
	public void menu()
		{
			int index=0;
			Scanner scan = new Scanner(System.in);
			Scanner scan1= new Scanner (System.in);
			Student s = new Student ();
			int echoice;
			System.out.print("\nResgistration System");
			System.out.print("\n1. Add Student");
			System.out.print("\n2. View Student");
			System.out.print("\n3. Exit");
			System.out.print("\n\nNo of Student(s):"+ index);
			System.out.print("\nChoose: ");	
			echoice=scan.nextInt();
			s.menuC(echoice);			
		}
	
	public void setNAME(String Name)
	{
		
		for(int x=0; x<Name.length(); x++)
		{
		
		if ((Name.charAt(x)>='A'&& Name.charAt(x)<='Z')||(Name.charAt(x)>='a'&& Name.charAt(x)<='z')||(Name.charAt(x)==' '));
			name[ctr]=Name;
		}
		ctr++;
		
	}
	public void setAGE (int Age)
	{
		if (Age>=15&&Age<=30)
		{
			age[ctr]=Age;
		}
		//System.out.print("Age:"+ age[ctr]);
	}
	
	public void print()
	{
		System.out.print(ctr);
		for(int x=0; x<=ctr-1;x++)
				System.out.print("NAme:"+ name[x]);
	}
	
	public void menuC (int choice)
	{
				if (choice==1)
				{
					menu2();
				}
				else if(choice==2)
				{	
					print();
					System.out.print(ctr);
				}
				else
				{
					System.out.print("Thank you!");
					System.exit(0);
				}
	}
	public void menu2()
	{
			System.out.print("\nStudent");
			System.out.print("\n1. BSIT");
			System.out.print("\n2. BSCS");
			System.out.print("\n3. MSCS");
			System.out.print("\n4. MSIT");
			System.out.print("\n5. Back to Main Menu");
	}
	public void menu2C (int choice2)
	{
				if (choice2==1)
				{
					ctr++;
					System.out.print(ctr);
					ts.add(ctr);
					menu2();
					
				}
				else if(choice2==5)
				{
					ts.menu();
				}
	}
	
	public int getage()
	{
		return age[ctr];
	}
}


TestStudent class
package mp.classobject;
import mp.classobject.BSIT;
import java.util.Scanner;

public class TestStudent 
{
	
		

	public static void main (String[] args)
	{
		 Scanner scan = new Scanner(System.in);
		 Scanner scan1= new Scanner (System.in);
		 String eaddress;
		
		 int echoice2;
		
		 
		char egender;
		int eyearlevel;
			
			
		Student s = new Student ();
		BSIT it= new BSIT();
		
		
		
		
		
		s.menu();
		System.out.print("\nChoose:");
				echoice2=scan.nextInt();
		s.menu2C(echoice2);
		System.out.print("\nChoose:");
				echoice2=scan.nextInt();
		s.menu2C(echoice2);
		
	}	
	
	public void add( int index)
	{			Scanner scan1= new Scanner (System.in);
				Scanner scan = new Scanner(System.in);
				String [] ename=new String[50];
				int [] eage= new int[50];
				int testAge;
				 Student s = new Student ();
			System.out.print("\nBSIT");
			System.out.print("\nEnter Name :");
			ename[index]=scan1.nextLine();
			s.setNAME(ename[index]);
			do
			{
			System.out.print("\nEnter Age:");
			eage[index]=scan.nextInt();
			s.setAGE(eage[index]);
			testAge=s.getage();
			}
			while(testAge==0);
			
	}
}
	





Is This A Good Question/Topic? 0
  • +

Replies To: Registration System with the use of Inheritance and Polymorphism

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10446
  • View blog
  • Posts: 38,686
  • Joined: 27-December 08

Re: Registration System with the use of Inheritance and Polymorphism

Posted 08 July 2012 - 10:29 PM

What is your question? What specific problems or errors are you encountering?
Was This Post Helpful? 0
  • +
  • -

#3 aldrine  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 08-July 12

Re: Registration System with the use of Inheritance and Polymorphism

Posted 08 July 2012 - 10:34 PM

how can I a count the adding of students...from which class I will put ctr.

it can be compiled but when in runtime... 'cannot override menu() in mp.classobject.Student; overriding method is static public static void main()'
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1