Results 1 to 20 of 24
- 10-19-2008, 04:52 PM #1
Member
- Join Date
- Oct 2008
- Posts
- 13
- Rep Power
- 0
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.
- 10-19-2008, 04:58 PM #2
Member
- Join Date
- Oct 2008
- Posts
- 13
- Rep Power
- 0
Answer to Line 1
class cube { -this desribes a new java class called cube
- 10-19-2008, 05:35 PM #3
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.
- 10-19-2008, 05:49 PM #4
Member
- Join Date
- Oct 2008
- Posts
- 13
- Rep Power
- 0
what about the answer i wrote for the first line,is it correct?
- 10-19-2008, 07:18 PM #5
Cross post
Pls i need help with these 2 Java Questions
db
- 10-19-2008, 08:26 PM #6
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:CJSLJava Code:Cube c = new Cube();
Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 10-19-2008, 08:40 PM #7
Member
- Join Date
- Oct 2008
- Posts
- 13
- Rep Power
- 0
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?
- 10-19-2008, 08:43 PM #8
That line creates a new instance, does not describe.
- 10-19-2008, 08:51 PM #9
Member
- Join Date
- Oct 2008
- Posts
- 13
- Rep Power
- 0
thanks my apologies-i'm a doctor trying to learn java-it ain't easy,but i am willing to learn.
- 10-19-2008, 08:58 PM #10
Member
- Join Date
- Oct 2008
- Posts
- 13
- Rep Power
- 0
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?
- 10-19-2008, 09:01 PM #11
Good. keep going.
-
- 10-19-2008, 09:31 PM #13
AH that explains the sun forum name
- 10-19-2008, 09:39 PM #14
Cross forum cross post.
Java Programming - Pls i need help with these 2 Java Questions
db
- 10-19-2008, 10:33 PM #15
Member
- Join Date
- Oct 2008
- Posts
- 13
- Rep Power
- 0
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?
- 10-19-2008, 11:33 PM #16
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 ...
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 10-19-2008, 11:46 PM #17
Member
- Join Date
- Oct 2008
- Posts
- 13
- Rep Power
- 0
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.
- 10-20-2008, 12:14 AM #18
Member
- Join Date
- Oct 2008
- Posts
- 13
- Rep Power
- 0
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
- 10-20-2008, 01:25 AM #19
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
- 10-20-2008, 01:31 AM #20
Member
- Join Date
- Oct 2008
- Posts
- 13
- Rep Power
- 0
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.
Similar Threads
-
Java Questions...
By Xarver in forum New To JavaReplies: 11Last Post: 09-20-2008, 05:37 AM -
Few Questions about java
By Grom in forum NetBeansReplies: 11Last Post: 09-13-2008, 02:26 PM -
2 simple java questions
By jimJohnson in forum New To JavaReplies: 2Last Post: 02-02-2008, 09:35 AM -
few java questions
By hiaslpix in forum New To JavaReplies: 4Last Post: 01-01-2008, 05:47 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks