Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Java question in exam help

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java question in exam help

    Hi i am new to the forum and just wanted some advice to the following question, i have just completed my java exam at university and the following question came up below

    In Java code, write class called Student with the following features:
    • a private instance variable int studentNumber that is initialised to zero.
    • a private instance variable String firstName;
    • a private instance variable String lastName;
    • a constructor which takes an integer argument and two String arguments to
    initialises the three respective data items.
    • a public method with signature equals(Student s) . . .

    could someone tell me how they would of answered this so i know i was on the right track

    thanks jag


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java question in exam help

    Can you post the code you have written and ask some questions about it?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java question in exam help

    I dont have the code that i wrote, i was kinda stuck on the whole question

    --- Update ---

    i was stuck on the constructor bit, the rest was fairly simple

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java question in exam help

    No, problem. You can take as long as you need to write the code again.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java question in exam help

    i know the rest of the code norm its just the constructor bit i was stuck on i wouldn't know how to answer it thats why i needed help for that bit

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java question in exam help

    Post what you have tried and any errors you are getting.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Apr 2012
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java question in exam help

    Hi norm this is my code

    `public class student {`
    `private int studentnumber = 0;`

    `public student () {`
    `firstname= "forename":`
    `lastname="surname":`

    `public student (integer studentnumber, string firstname, string lastname) {`

    `this.firstname= firstname`
    `this.lastname= lastname:`


    My question is how do i add the integer in the argument do i have to use int =? and how would i go about doing the public signature equals any help would be appreciated thanks

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java question in exam help

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    Also use the compiler to find any errors so you can correct them and post correct code if you can. Otherwise copy the full text of the error messages and paste it here if you need help.

    how do i add the integer in the argument
    An example of using an int as an arg in a call to a method:
      someMethod(234);  // pass the int arg 234 to someMethod()
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Java question in exam help

    Several problems with that. "integer" and "string" are not data types from the standard library. What you mean are "int" and "String". Capitalization is important and makes a difference in java.
    The next Problem is, that your class-name starts with a lowercase letter which, although not illegal, is discouraged and bad coding practice.
    And then you try to use variables called "firstname" and "lastname" but these variables are never defined in your program. You should get a "cannot find symbol" error from your compiler.

Similar Threads

  1. an exam question
    By a939 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 16th, 2014, 12:10 PM
  2. "Help with answer to question from java 6 practice exam book!
    By StanTheMan in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 15th, 2013, 12:33 PM
  3. exam question help please_2
    By mrjavajava in forum Java Theory & Questions
    Replies: 3
    Last Post: February 4th, 2013, 09:34 AM
  4. exam question help please
    By mrjavajava in forum Java Theory & Questions
    Replies: 1
    Last Post: February 3rd, 2013, 07:59 AM
  5. exam revision question help please
    By mrjavajava in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 3rd, 2013, 06:08 AM