Java Question - i am REALLY confused

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sobe4481
    New Member
    • Nov 2007
    • 6

    Java Question - i am REALLY confused

    Hi all,

    I am taking a Java Course in Michigan to get into the flow of things , but i am completely stuck on one of the Labs.

    Here is what the Lab Asks for -

    Create a class called 'Employee' that includes three pieces of information as instance variaveles -- a first name (type String), a last name (type String) and a monthly salary (double). Your class should have a constructor that initializes the three instance variabvles. Provide a set and a get method for each instance variable. If the monthly slaary is not prositive, set it to 0.0. Write a test application named EmployeeTest that demonstrates class Employee's capabilitis. Create two Employee objects and display each object's yearly salary. Then give each Employee a 10% raise and display each Employee's yearly salary again.

    I AM SOOOO LOSTTTT in this.

    please if you can't give me the 'answer' can you maybe break it down for me? Im not quite sure how to even begin this....

    Thanks SOOO much in advance
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by sobe4481
    Hi all,

    I am taking a Java Course in Michigan to get into the flow of things , but i am completely stuck on one of the Labs.

    Here is what the Lab Asks for -

    Create a class called 'Employee' that includes three pieces of information as instance variaveles -- a first name (type String), a last name (type String) and a monthly salary (double). Your class should have a constructor that initializes the three instance variabvles. Provide a set and a get method for each instance variable. If the monthly slaary is not prositive, set it to 0.0. Write a test application named EmployeeTest that demonstrates class Employee's capabilitis. Create two Employee objects and display each object's yearly salary. Then give each Employee a 10% raise and display each Employee's yearly salary again.

    I AM SOOOO LOSTTTT in this.

    please if you can't give me the 'answer' can you maybe break it down for me? Im not quite sure how to even begin this....

    Thanks SOOO much in advance
    Start with the Employee class and write it as specified by your question.
    Last edited by r035198x; Nov 14 '07, 04:52 PM. Reason: typo

    Comment

    • sobe4481
      New Member
      • Nov 2007
      • 6

      #3
      I've really had a tough time

      so is this two separate codes? [i am using NetBeans IDE]

      based on your response --- this is as far as i got without re-confusing myself :)

      public class Employee {


      public Employee() {
      }

      }

      Class was started, but what exactly do i do to create the instance variables [could i get any sample code or something that really breaks this down for me? - i feel worthless :) ]

      i want to understand this - as i know it will pop back up ...but within the class how are all of these instance variables defined, and set and get methods brought up?

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by sobe4481
        I've really had a tough time

        so is this two separate codes? [i am using NetBeans IDE]

        based on your response --- this is as far as i got without re-confusing myself :)

        public class Employee {


        public Employee() {
        }

        }

        Class was started, but what exactly do i do to create the instance variables [could i get any sample code or something that really breaks this down for me? - i feel worthless :) ]

        i want to understand this - as i know it will pop back up ...but within the class how are all of these instance variables defined, and set and get methods brought up?
        Read this.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by sobe4481
          I've really had a tough time

          so is this two separate codes? [i am using NetBeans IDE]

          based on your response --- this is as far as i got without re-confusing myself :)

          public class Employee {


          public Employee() {
          }

          }

          Class was started, but what exactly do i do to create the instance variables
          [could i get any sample code or something that really breaks this down for
          me? - i feel worthless :) ]

          i want to understand this - as i know it will pop back up ...but within the class how are all of these instance variables defined, and set and get methods brought up?
          Here's you own assignment text again. Follow it closely:

          "Create a class called 'Employee' that includes three pieces of information as
          instance variaveles -- a first name (type String), a last name (type String) and a
          monthly salary (double)."


          This can only lead to the following skeleton of a class:

          [code=java]
          public class Employee {

          private String firstName;
          private String lastName;
          private double salary;

          ...
          }
          [/code]

          "Your class should have a constructor that initializes the three instance
          variabvles. Provide a set and a get method for each instance variable."


          Here's the constructor for the above class:

          [code=java]
          ...
          public Employee(String firstName, String lastName, double salary) {
          this.firstName= firstName;
          this.lastName= lastName;
          this.salary= salary;
          }
          [/code]

          Now it's your turn: create methods that get and set those three values that belong
          to an instantiation of an Employee.

          kind regards,

          Jos

          Comment

          • sobe4481
            New Member
            • Nov 2007
            • 6

            #6
            i love you guys, thanks so much it does help a lot !!!

            I will try to write this out, if i get stuck, ill be back :) printing this

            God Bless!

            Comment

            • sobe4481
              New Member
              • Nov 2007
              • 6

              #7
              Here's you own assignment text again. Follow it closely:

              "Create a class called 'Employee' that includes three pieces of information as
              instance variaveles -- a first name (type String), a last name (type String) and a
              monthly salary (double)."

              This can only lead to the following skeleton of a class:


              Code: ( java )
              public class Employee {

              private String firstName;
              private String lastName;
              private double salary;

              ...
              }


              "Your class should have a constructor that initializes the three instance
              variabvles. Provide a set and a get method for each instance variable."

              Here's the constructor for the above class:


              Code: ( java )
              ...
              public Employee(String firstName, String lastName, double salary) {
              this.firstName= firstName;
              this.lastName= lastName;
              this.salary= salary;
              }


              Now it's your turn: create methods that get and set those three values that belong
              to an instantiation of an Employee.

              kind regards,

              Jos
              public class Employee {

              private String firstName;
              private String lastName;
              private double salary;

              public Employee( String firstName, String lastName, double salary);
              }

              i am getting this when compiling::'


              Lab1/Employee.java [7:1] missing method body, or declare abstract
              public Employee( String firstName, String lastName, double salary);
              ^
              1 error
              Errors compiling Employee.



              what did i do wrong? am i supposed to do something else? :P -- man, i am really bad at this ....

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by sobe4481
                public class Employee {

                private String firstName;
                private String lastName;
                private double salary;

                public Employee( String firstName, String lastName, double salary);
                }

                i am getting this when compiling::
                public class Employee {

                private String firstName;
                private String lastName;
                private double salary;

                public Employee( String firstName, String lastName, double salary);
                }


                what did i do wrong? am i supposed to do something else? :P -- man, i am really bad at this ....
                For starters you are putting a semi colon where an opening brace is needed
                [CODE=java] public Employee( String firstName, String lastName, double salary);[/CODE]
                should really be
                [CODE=java] public Employee( String firstName, String lastName, double salary) {[/CODE]

                You'll want to do something with all those values you are taking in the constructors.

                P.S Note my use of [code=java] tags when posting code
                P.P.S Going over a tutorial on constructors wouldn't hurt.

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by sobe4481
                  what did i do wrong? am i supposed to do something else? :P -- man, i am really bad at this ....
                  You sure are because all you had to do was copy/paste or type in what I had
                  written. Programming and sloppyness don't go well together.

                  kind regards,

                  Jos

                  Comment

                  • sobe4481
                    New Member
                    • Nov 2007
                    • 6

                    #10
                    lol, this is cracking me up, @ work right now losing my mind with this.

                    and yea - i felt there was more that needed to be added because i had an extra mark in there which was giving me an error, which is why i added the semi-colon.


                    import java.util.Scann er;

                    public class Employee {
                    private String firstName;
                    private String lastName;
                    private double salary;

                    public Employee( String firstName, String lastName, double salary){
                    Scanner input = new Scanner(System. in);

                    now from here - is there where the public void - setFirstName() and all that comes in?

                    am i on the right path? its an online course - so there is no teacher interaction as well as book is slightly confusing...

                    Thanks - and sorry for seeming like such an idiot, you guys have been more than wonderful!

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      Originally posted by sobe4481
                      lol, this is cracking me up, @ work right now losing my mind with this.

                      and yea - i felt there was more that needed to be added because i had an extra mark in there which was giving me an error, which is why i added the semi-colon.


                      import java.util.Scann er;

                      public class Employee {
                      private String firstName;
                      private String lastName;
                      private double salary;

                      public Employee( String firstName, String lastName, double salary){
                      Scanner input = new Scanner(System. in);

                      now from here - is there where the public void - setFirstName() and all that comes in?

                      am i on the right path? its an online course - so there is no teacher interaction as well as book is slightly confusing...

                      Thanks - and sorry for seeming like such an idiot, you guys have been more than wonderful!
                      ... and now I really insist that you read some tutorial/book first.

                      Comment

                      • sobe4481
                        New Member
                        • Nov 2007
                        • 6

                        #12
                        Originally posted by r035198x
                        ... and now I really insist that you read some tutorial/book first.
                        LOL - yep, i guess im lost.

                        Read the 'Small Java' How To Program book

                        after reading, i try to follow the diagrams they show me -- basically im seeing the class being built

                        public class Gradebook

                        private String courseName;

                        public void setCourseName( String name )

                        course name = name;

                        i am missing some characters, i know - but its basically that layout...


                        Now that you've made me feel completely worthless in this - i guess i will try to read up a little more.

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          Originally posted by sobe4481
                          LOL - yep, i guess im lost.

                          Read the 'Small Java' How To Program book

                          after reading, i try to follow the diagrams they show me -- basically im seeing the class being built

                          public class Gradebook

                          private String courseName;

                          public void setCourseName( String name )

                          course name = name;

                          i am missing some characters, i know - but its basically that layout...


                          Now that you've made me feel completely worthless in this - i guess i will try to read up a little more.
                          You are not completely worthless if you still have your powers of reading with you.

                          Comment

                          • CodeTilYaDrop
                            New Member
                            • Aug 2007
                            • 66

                            #14
                            My teacher pointed out a great tutorial under

                            http://sourceforge.net/projects/eclipsetutorial/

                            I think the first 3 or 4 are all about getters and setters. It won't take you long to catch on watching these! They were a great help to me. -

                            Comment

                            Working...