Results 1 to 2 of 2
  1. #1
    circuspeanuts is offline Member
    Join Date
    Apr 2009
    Posts
    14
    Rep Power
    0

    Default Inheritance problems...quick answers if possible :)

    Just so everyone knows this is for my class :)


    ok so first off here's my code:

    Main Class:
    import java.util.Scanner;

    public class Person
    {
    private
    String UserLast;
    String UserFirst;
    int sYears;
    int iYears;

    public Person()
    {

    }
    public static void main(String[] args)
    {
    Person oPerson = new Person();
    Scanner scanner = new Scanner(System.in);

    System.out.println("Welcome to the Person Creation Program.");
    System.out.println("Would you like to creat a student or instructor? \n 1 - Student \n 2 - Instructor " +
    "\n");
    int UsrChoice = scanner.nextInt();

    if (UsrChoice == 1)
    {

    }
    else if (UsrChoice == 2)
    {
    System.out.println("Welcome to the create an instructor program");
    System.out.println("What is your last name?");
    String LastName = scanner.next();
    System.out.println("What is your first name?");
    String FirstName = scanner.next();
    System.out.println("How many years have you been an instructor?");
    int iYears = scanner.nextInt();
    System.out.println(FirstName + " " + LastName +", you've been an instructor for " + iYears + " years.");

    }
    }


    }
    my student class:

    /import java.util.Scanner;

    public class Student extends Person
    {


    public Student()
    {
    Scanner scanner = new Scanner(System.in);
    System.out.println("You have chosen to create a student.");
    System.out.println("Welcome to the student creation section.");
    System.out.println("What is your last name?");
    String LastName = scanner.next();
    System.out.println("What is your first name?");
    String FirstName = scanner.next();
    System.out.println("How many years have you been a student?");
    int sYears = scanner.nextInt();
    System.out.println("Well, " + FirstName + " " + LastName + ", You've been a student for " + sYears + ".");
    }

    }

    and my instructor class:

    public class Instructor extends Person
    {

    public String GetUsrFstNm(String FirstName)
    {
    return FirstName;
    };

    public String GetUsrLsNm(String LastName)
    {
    return LastName;
    };


    public Instructor()
    {

    }

    }
    eventually I need to move some things over into my instructor class. My question is this.

    If they choose 1 for student. I need to be able to run the student class from the if function that I have in the above code...Any ideas? I've tried many things..
    Last edited by circuspeanuts; 04-13-2009 at 07:33 PM.

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    Can you be more specific:
    -what does the code do?
    -what kind of problems are you having with it?
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

Similar Threads

  1. Inheritance problems
    By PVL268 in forum New To Java
    Replies: 3
    Last Post: 03-23-2009, 02:52 AM
  2. Inheritance example
    By kris4u4ever in forum New To Java
    Replies: 3
    Last Post: 03-21-2009, 02:53 PM
  3. Need help quick!
    By Manikyr in forum New To Java
    Replies: 11
    Last Post: 01-28-2009, 04:08 AM
  4. inheritance
    By itaipee in forum New To Java
    Replies: 6
    Last Post: 01-20-2009, 08:18 PM
  5. Replies: 0
    Last Post: 01-24-2008, 07:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •