Page 1 of 2 12 LastLast
Results 1 to 20 of 24
  1. #1
    jyde is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default Pls i need help with these 2 Java Questions

    1. Describe in detail (i.e., line for line) what the following piece of code does.


    class Cube {
    int side;
    }
    _________________________________________

    class MainCube {

    public static void main(String[] args) {
    Cube c = new Cube();
    c.side = 10;
    System.out.println(“side is “ + c.side);
    }
    }







    2. Circle

     Design a Circle class which is described by the length of its radius

     Design a method that calculates the total surface area of the circle.
    - Equation: Pi * radius * radius

     Design a method that calculates the circumference of the circle.
    - Equation: 2 * Pi * radius

    (Note: Put the design of the class and methods on paper – to be handed up)

     Implement the Circle using a java class, i.e. Circle.java

     Write a MainCircle.java class which

    - Instantiates a new Circle instance,
    - Reads in the length of circle’s radius.
    - Assigns the value of the radius to the instance variable
    - Uses the Circle methods to print the area and circumference to the console.
    - Increases the length of the radius by 10.
    - Uses the Circle methods to print the increased area and circumference to the console.

  2. #2
    jyde is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default Answer to Line 1

    class cube { -this desribes a new java class called cube

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default

    Sounds like a HW assignment.
    What help are you looking for?
    You provide the answers for the rest of the lines and we'll grade them.

  4. #4
    jyde is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default

    what about the answer i wrote for the first line,is it correct?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default this is your homework assigment

    jyde, a couple of things:

    • Do not cross post your questions (it is VERY obvious that this question does not belong in the Advanced Java section). Cross posting irritates people to no end... the same people who would help you answer your questons.

    • The forum is not going to do your homework for you. If you have a specific problem or question with your code, then the forum will help you.

    As for answer you posted, yes that is correct.

    It will be interesting to see your answer for:
    Java Code:
    Cube c = new Cube();
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    jyde is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default

    Sorry for cross posting.I am new to the forum or any forum for that matter.
    I believe
    Cube c = new Cube();-describes the creation of a new cube instance/object.
    What do you think?

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default

    That line creates a new instance, does not describe.

  9. #9
    jyde is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default

    thanks my apologies-i'm a doctor trying to learn java-it ain't easy,but i am willing to learn.

  10. #10
    jyde is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default

    Let me try the next 2 lines-
    c.side = 10;-assign the value of 10 to the instance variable
    System.out.println(“side is “ + c.side);-print the value to the console.

    What do you think?

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default

    Good. keep going.

  12. #12
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by jyde View Post
    thanks my apologies-i'm a doctor trying to learn java-it ain't easy,but i am willing to learn.
    Quick question: what kind of doctor are you? (Gastroenterologist here)

  13. #13
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default

    AH that explains the sun forum name

  14. #14
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

  15. #15
    jyde is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default

    So far-
    1)class Cube { -describes a new java class called Cube.java
    2)int side;-primitive data type integer for storing whole numbers for the instance variable
    3)}-close the instance variable
    _________________________________________

    4)class MainCube {-describes a new java class called
    MainCube.java and this contains the special 'Main' method of the class

    5)public static void main(String[] args) {-Program starts execution here
    6)Cube c = new Cube();-create a new cube instance and 'c' is the name of the object reference to the new instance
    7)c.side = 10;-assign the value of 10 to the instance variable
    8)System.out.println(“side is “ + c.side);-print the value to the console
    9)}-close the instance variable
    10)}-close the program

    What do you think?any alterations or corrections?

  16. #16
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Some comments...

    Some minor corrections:
    • 3) This closes the Cube class, not the variable assignment. The variable assignment is closed with the ;
    • 5) If I were the teacher of the class I would also expect the desciption of the public, static & void
    • 9) This closes the "main" method
    • 10) Is the close of the mainCube class

    Keep going ...
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  17. #17
    jyde is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default

    I'm a G.P.By the way Darryl,stop following me around.i didn't know both fora are the same,i was only trying to be a conscientious student looking for help with my assignments.

  18. #18
    jyde is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default

    Thanks CJSLMAN and Norm-your comments have been inspiring:


    So far-
    1)class Cube { -describes a new java class called Cube.java
    2)int side;-primitive data type integer for storing whole numbers for the instance variable
    3)}-close the cube class
    _________________________________________

    4)class MainCube {-describes a new java class called
    MainCube.java and this contains the special 'Main' method of the class

    5)public static void main(String[] args) {-Program starts execution here
    6)Cube c = new Cube();-create a new cube instance and 'c' is the name of the object reference to the new instance
    7)c.side = 10;-assign the value of 10 to the instance variable
    8)System.out.println(“side is “ + c.side);-print the value to the console
    9)}-close the 'main' method
    10)}-close the MainCube class

    What do you think?any more alterations or corrections?
    Unfortunately,i wouldn't be attempting the second question because we haven't had the lectures yet until week 2 which is next weekend,but you can be sure i will be back to the forum

  19. #19
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Quote Originally Posted by jyde View Post
    I'm a G.P.
    I knew healthcare was a mess, but G.P. are valuable, we need more, not fewer.
    What is driving you to Java?

    One quick comment, you seem to be catching on.

    Software is the most anal, picky, and non-communicative thing you have ever imagined. It does not "know what you mean" at all, ever. Most doctors get used to a good nurse who when they mumble, knows exactly what you meant and does it nearly before you say it.

    Software does not do this. You must do it the exactly right way. Java is actually worse in this regard than some other languages (PHP, Perl) but I tend to like it, because sometimes perl will do stuff that I didn't expect

  20. #20
    jyde is offline Member
    Join Date
    Oct 2008
    Posts
    13
    Rep Power
    0

    Default

    i'm doing my masters in health informatics so as to operate a paperless service.I also know that,unlike my nurses,java is case-sensitive.i gat to hit my bed now,so might not be able to respond to any more comments as swiftly,tommorrow is another day.thanks everyone for all your comments,i have been truly inspired by the forum.Good night and talk to you later.

Page 1 of 2 12 LastLast

Similar Threads

  1. Java Questions...
    By Xarver in forum New To Java
    Replies: 11
    Last Post: 09-20-2008, 05:37 AM
  2. Few Questions about java
    By Grom in forum NetBeans
    Replies: 11
    Last Post: 09-13-2008, 02:26 PM
  3. 2 simple java questions
    By jimJohnson in forum New To Java
    Replies: 2
    Last Post: 02-02-2008, 09:35 AM

Posting Permissions

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