[College] Java 2 programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rushyrulz
    Digital Dancing!
    FFR Simfile Author
    FFR Music Producer
    • Feb 2006
    • 12985

    #1

    [College] Java 2 programming

    I'm a tad bit confused by the monster assignment I got for my java class. The assignment is to create 6 classes: Employee (abstract class inherits Object), [HourlyEmployee, SalaryEmployee, CommissionEmployee] all inherit from Employee, EmployeeManager, and EmployeeDriver (contains the main method and menu system).

    Unfortunately, my Java 1 teacher didn't teach us all she was supposed to, and as a result I'm struggling a bit to understand some of the concepts that my current teacher is mentioning that we should have already learned in Java 1. Included in these misunderstood topics are: common classes in Object such as toString and equals, bubble sort, and most of object-oriented programming. So a few questions I have:

    1. How to I implement the toString methods of each employee class from the driver where the information is prompted?

    2. the prompts for first name, last name, middle initial, gender, employee number, and fulltime in the driver are
    Code:
    System.out.print("Enter Last Name: ");
    ln = in.next();
    System.out.print("Enter First Name: ");
    fn = in.next();
    System.out.print("Enter Middle Initial: ");
    mi = in.next().charAt(0);
    System.out.print("Enter Gender: ");
    g = in.next().charAt(0);
    System.out.print("Enter Employee Number: ");
    en = in.nextInt();
    System.out.print("Full Time? (y/n): ");
    f = in.next().charAt(0);
    which was given to me by the instructor. These variables are different than the protected variables listed in the UML diagram for Employee, do I need to set the variables equal to to these shortened versions in Employee's constructor? ie.
    Code:
    lastName = ln;
    firstName = fn;
    middleInitial = mi;
    gender = g;
    employeeNumber = en;
    fulltime = f;
    and is that even legal to do since some of the data members are chars?

    I might have more questions later as I haven't even started on the manager class yet.

    Thanks in advance for any help.


  • YoshL
    Celestial Harbor
    FFR Simfile Author
    FFR Music Producer
    • Aug 2008
    • 6156

    #2
    Re: [College] Java 2 programming

    Originally posted by rushyrulz
    1. How to I implement the toString methods of each employee class from the driver where the information is prompted?

    2. the prompts for first name, last name, middle initial, gender, employee number, and fulltime in the driver are
    Code:
    System.out.print("Enter Last Name: ");
    ln = in.next();
    System.out.print("Enter First Name: ");
    fn = in.next();
    System.out.print("Enter Middle Initial: ");
    mi = in.next().charAt(0);
    System.out.print("Enter Gender: ");
    g = in.next().charAt(0);
    System.out.print("Enter Employee Number: ");
    en = in.nextInt();
    System.out.print("Full Time? (y/n): ");
    f = in.next().charAt(0);
    which was given to me by the instructor. These variables are different than the protected variables listed in the UML diagram for Employee, do I need to set the variables equal to to these shortened versions in Employee's constructor? ie.
    Code:
    lastName = ln;
    firstName = fn;
    middleInitial = mi;
    gender = g;
    employeeNumber = en;
    fulltime = f;
    and is that even legal to do since some of the data members are chars?

    I might have more questions later as I haven't even started on the manager class yet.

    Thanks in advance for any help.
    1. the toString() method is a method that is inherited for every object, because it's a method of the Object class. Because of this behavior, you can rewrite the function in any class with : public String toString(){ etc. etc.
    the String return value is what is to be displayed to the screen.

    the main thing that uses the toString() method is any system.out statements you have. what it's doing when you pass a variable into there is calling its toString() method

    basically, you implement in the classes, not the driver.

    2. yes, that's pretty much what you're supposed to do. Of course, whether setting variables as chars depends on what the variable type in question is. Of course you can set a char as a char. so just data types.


    Originally posted by Charu
    Only yours, for an easy price of $19.99! You too can experience the wonders of full motion rump sticking.

    Comment

    • rushyrulz
      Digital Dancing!
      FFR Simfile Author
      FFR Music Producer
      • Feb 2006
      • 12985

      #3
      Re: [College] Java 2 programming

      Thanks Yoshl, I also don't understand why methods getEmployeeNumber (which returns an int) and setEmployeeNumber(which has an int argument but returns nothing) are necessary in the Employee class when I get all the employee number information from the driver

      UML for Employee:


      is it because employeeNum isn't a protected variable? If so, why doesn't gender need separate get/set methods?
      Last edited by rushyrulz; 02-8-2012, 01:11 PM.


      Comment

      • YoshL
        Celestial Harbor
        FFR Simfile Author
        FFR Music Producer
        • Aug 2008
        • 6156

        #4
        Re: [College] Java 2 programming

        Originally posted by rushyrulz
        Thanks Yoshl, I also don't understand why methods getEmployeeNumber (which returns an int) and setEmployeeNumber(which has an int argument but returns nothing) are necessary in the Employee class when I get all the employee number information from the driver
        basically it's the concept of data hiding. *imagine* a real life scenario where you have written a nice class for people to use. You don't want people writing drivers where they directly access all of your data, you would probably want some means of controlling that, hence all the instance variables in other classes. which is why most classes use get methods and set methods to achieve their purpouses (idk if i explained that correctly :S)

        edit:

        because Employee is also an abstract class and objects are going to extend off of it, the subclasses will never have direct access to the variables, and would need those get and set methods


        Originally posted by Charu
        Only yours, for an easy price of $19.99! You too can experience the wonders of full motion rump sticking.

        Comment

        • rushyrulz
          Digital Dancing!
          FFR Simfile Author
          FFR Music Producer
          • Feb 2006
          • 12985

          #5
          Re: [College] Java 2 programming

          So I wouldn't be using the get/set methods to prompt the user, but just to get the information from the manager class when I get around to coding that?

          edit to your edit: So you're saying that I need get and set methods for all the classes that extend from Employee as well? (sorry I'd never heard of get/set until earlier this semester when I found out another thing that my CS1400 teacher neglected to teach us.)
          Last edited by rushyrulz; 02-8-2012, 01:16 PM.


          Comment

          • YoshL
            Celestial Harbor
            FFR Simfile Author
            FFR Music Producer
            • Aug 2008
            • 6156

            #6
            Re: [College] Java 2 programming

            Originally posted by rushyrulz
            So I wouldn't be using the get/set methods to prompt the user, but just to get the information from the manager class when I get around to coding that?
            well, get the information from the manager, getting the information from the Employee subclasses, yes.


            Originally posted by Charu
            Only yours, for an easy price of $19.99! You too can experience the wonders of full motion rump sticking.

            Comment

            • rushyrulz
              Digital Dancing!
              FFR Simfile Author
              FFR Music Producer
              • Feb 2006
              • 12985

              #7
              Re: [College] Java 2 programming

              Ok so breakdown time on how this thing is gonna run hypothetically:

              Driver contains the main, so that's executed. Neat little menu pops up. User picks "Add Employee" option and is prompted:
              1. hourly
              2. salary
              3. commission

              Lets say they pick hourly, they are prompted
              Enter Last Name:
              Enter First Name:
              Enter Middle Initial:
              Enter Gender:
              Enter Employee Number:
              Full Time (y/n):
              Enter Wage:
              (there's a separate menu for adding hours)

              All this information gets sent to a method in the EmployeeManager class called addEmployee.

              Within this addEmployee class am I supposed to call the toString method of HourlyEmployee or what? Unfortunately, the teacher didn't provide a UML on the EmployeeManager class and kinda just left it up to us to come up with something that works.

              EDIT: I'm dumb, I'm not supposed to output the employee info til the user asks for it.
              Last edited by rushyrulz; 02-8-2012, 01:35 PM.


              Comment

              • YoshL
                Celestial Harbor
                FFR Simfile Author
                FFR Music Producer
                • Aug 2008
                • 6156

                #8
                Re: [College] Java 2 programming

                Originally posted by rushyrulz
                Ok so breakdown time on how this thing is gonna run hypothetically:

                Driver contains the main, so that's executed. Neat little menu pops up. User picks "Add Employee" option and is prompted:
                1. hourly
                2. salary
                3. commission

                Lets say they pick hourly, they are prompted
                Enter Last Name:
                Enter First Name:
                Enter Middle Initial:
                Enter Gender:
                Enter Employee Number:
                Full Time (y/n):
                Enter Wage:
                (there's a separate menu for adding hours)

                All this information gets sent to a method in the EmployeeManager class called addEmployee.

                Within this addEmployee class am I supposed to call the toString method of HourlyEmployee or what? Unfortunately, the teacher didn't provide a UML on the EmployeeManager class and kinda just left it up to us to come up with something that works.
                well, first off, what does addEmployee return? that's a fairly important part.
                and it shouldn't call toString at all. most likely you would create a new instance of the HourlyEmployee, and pass in all the values and things you need to the constructor, to create that.

                also, are you supposed to be printing the info out or...? (lol this might be easier in chat)


                Originally posted by Charu
                Only yours, for an easy price of $19.99! You too can experience the wonders of full motion rump sticking.

                Comment

                • rushyrulz
                  Digital Dancing!
                  FFR Simfile Author
                  FFR Music Producer
                  • Feb 2006
                  • 12985

                  #9
                  Re: [College] Java 2 programming

                  lol I have AIM and skype.















                  <account info over thur


                  Comment

                  Working...