• Post Reply Bookmark Topic Watch Topic
  • New Topic

help me solve this  RSS feed

 
mare san
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to solved this ? please >_<

 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi mare,

we love to help, but eh... what exactly is the problem?

Greetz,
Piet
 
mare san
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a question like that on my quiz . they need to add something missing coding onto that . please kindly help me solve this puzzle T_T
 
mare san
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the question like this

 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm.. these questions can indeed be nasty.

So, you are supposed to add some missing code. Now, that could mean several things:

1) maybe the 'mathematics' package does not exist and you are supposed to write that package?

2) or could it be that the classes 'circle', 'triangle' and 'cube' do not exist and you have to create these
classes? (by the way: by convention these class names should start with a capital letter, like 'Circle')

3) or maybe these classes do exist, but not the methods 'are' and 'volume'?

4) or are you supposed to write an interface, that all the classes should implement?

Well, it is obvious that you give us some more information. If that is difficult, then show us
the literal assignment (if in English, German or French).

Greetz,
Piet
 
mare san
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this the the question T_T

 
mare san
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hopefully the question image can be seen T_T
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see only a small light blue square. Can't you copy the assignment and paste it?
After you have pasted it, select that text, and then press the 'tt' button,
above your answering text box. That will put your text in a white background.

Greetz,
Piet
 
mare san
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually its from the books . welp i try.. TOT

webpage
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see.

Well, let's start at the beginning. Do you know what a package is, and how to create one?

 
mare san
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yea is it something like create the java from the .txt to .java right? @_@7
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote:
Well, let's start at the beginning. Do you know what a package is, and how to create one?


My question would be a bit "earlier" than that -- actually, before any coding (or designing on paper). In order to create a mathematical package, you should actually know the mathematical formula(s). So, what are the needed formulas? And you do know that a triangle doesn't have any volume, right?

Henry
 
mare san
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yyea.. henry ^^7
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Okay, instead of us asking you what do you know? And you responding with "yes, you know it". How about this?

Since you know how to get started, and you know the mathematics behinds the questions, can you tell us what have you done so far? And what issues you are running into -- and why you are having problems?

Henry
 
mare san
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IDK henry... I've try wut i can even all my classmates also cant solved this.. my apologies
 
mare san
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i guess im not suitable to learn this programming course. its hard to understand form the teacher haha ^^7
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Piet Souris wrote:
Well, let's start at the beginning. Do you know what a package is, and how to create one?


My question would be a bit "earlier" than that -- actually, before any coding (or designing on paper). In order to create a mathematical package, you should actually know the mathematical formula(s). So, what are the needed formulas? And you do know that a triangle doesn't have any volume, right?

Henry

I couldn't disagree more.

As you see from the image OP sent in, it is about creating a package with some classes in it. That has got nothing
to do with knowing formulas, although it is possible that that was OP's only problem.

As you noticed, it is not simple to get information from OP, so I decided to put some simple quck
questions in the hope to find out quickly what the problem was.

I do not like the way you interrupted me. I find it rude and impolite towards me.

Greetz,
Piet
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't get the photo link to open; please would you post it using the Img button, PS.
 
Roel De Nijs
Sheriff
Posts: 11338
177
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I can't get the photo link to open; please would you post it using the Img button, PS.

I updated the image link in OP's post, so now you can see the question/assignment straight away.

I hope that's ok with you, mare san?
 
Ash Jon
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first post! but I think I can help.

You haven't really given a good description of the problem but it looks like you need to create the mathematics package and create the classes, so this will help you (I'm not doing it all for you though, defeats the purpose, but take a look and you'll get the idea):



The code you posted to start doesn't actually show you passing arguments to the new objects, but without further information I'm assuming it's needed. If not, simply set the private members in the class itself and update the argument requirement in the class constructor

Mar_san, packages (namespaces) are basically collections of similar classes (though they don't have to be similar at all). They have more value than that simple sentence but you should research it, it is important.

To create the mathematics package, find where your default class is located and then create a new folder called mathematics. Then open notepad (if you're not using an IDE) and type in 'package mathematics; public class Cube { }' then save as Cube.java in the mathematics folder. Simply repeat for each class needed. Once done, you have Cube, Triangle etc all in the package mathematics. Go from there and if you did it right, you should be able to now use the new package using the code you gave in the first post.

Hope it helps
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it does help. I think something along those lines will help no end. There are still problems, e.g. no arguments, as you pointed out yourself.
Ash Jon wrote: . . .
// this is more likely the constructor based on the diagram and code (applies to all classes)
// public Cube() { } < you can leave it out altogether though if you wanted, the Java compiler will create the constructor for you
// but best to create it yourself regardless
. . .
I think you may have misunderstood the rules about default constructors. A lot of people consider default constructors poor design, but you only get a default constructor if you don't write any constructors. The compiler does not add a no‑arguments constructor everywhere. Only if you don't write any constructors at all. I personally would recommend creating as few constructors as possible but at least one per class. So I wouldn't write a no‑arguments constructor at all. Do you want a circle which chooses its own diameter?

private final double PI = 3.14; // pi will never change so final or you can just use the built in Math.PI
// or just stick to 'double PI' as shown on the diagram
I would go for Math.PI. What is the point of having two different values for PI? They should never have written PI on that diagram.

. . . Hope it helps
Yes, it does, as I said earlier.
 
Ash Jon
Greenhorn
Posts: 16
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Yes, it does help. I think something along those lines will help no end. There are still problems, e.g. no arguments, as you pointed out yourself.
Ash Jon wrote: . . .
// this is more likely the constructor based on the diagram and code (applies to all classes)
// public Cube() { } < you can leave it out altogether though if you wanted, the Java compiler will create the constructor for you
// but best to create it yourself regardless
. . .
I think you may have misunderstood the rules about default constructors. A lot of people consider default constructors poor design, but you only get a default constructor if you don't write any constructors. The compiler does not add a no‑arguments constructor everywhere. Only if you don't write any constructors at all. I personally would recommend creating as few constructors as possible but at least one per class. So I wouldn't write a no‑arguments constructor at all. Do you want a circle which chooses its own diameter?

private final double PI = 3.14; // pi will never change so final or you can just use the built in Math.PI
// or just stick to 'double PI' as shown on the diagram
I would go for Math.PI. What is the point of having two different values for PI? They should never have written PI on that diagram.

. . . Hope it helps
Yes, it does, as I said earlier.


Hi Campbell.

I understand about leaving out constructors where possible, now lol, I had initially thought that it was bad practice to leave it out so thank you for clearing that up, it is appreciated.

My post wasn't that clear. When I wrote the two constructors (the default commented), it was based on the diagram, which doesn't have a constructor at all. I put one in to show how it could work. It was meant as either/or, not to have two constructors (I understand that the compiler only creates default constructors in the absence of any constructors in the code).

Thanks,
Ash



 
mare san
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wouahh cool guys .. thank you for the help TAT /
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I see what you mean about constructors. As I said yesterday I believe you should always write one constructor for every class, and then only add overloaded constructors when there is a good reason for them.

That diagram from earlier does not show well‑designed code at all, and I think the original question was difficult to answer. There may have been more information which OP hasn't given us, or maybe even which OP has overlooked.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!