I. Ron Nie

Greenhorn
+ Follow
since Feb 27, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by I. Ron Nie

Hello. you guys are sharp!! I completely missed that!

I fix it and see what happens.

Thanks again. Ron.

Matthew Brown wrote:

I. Ron Nie wrote:In the second version I posted, I called it "DresserApp" and saved it as a file called "DresserApp.java" (after deleting the file "DresserAp.java")


No you didn't. In the second version you posted, you called it "DreserApp" - single "s". Is that error in the real file?

13 years ago
I changed the name of the code.

In the first version I posted originally, I called it "DresserAp" and saved it as a file called "DresserAp.java"

In the second version I posted, I called it "DresserApp" and saved it as a file called "DresserApp.java" (after deleting the file "DresserAp.java")

The quoted error messages I get occur after typing "java DresserApp" in the command prompt.

Matthew Brown wrote:Line 1 has a typo: "DreserApp". Is that the cause, or just a transcription error?

13 years ago
Hello. Here is the code that is giving me error messages



And the error messages are as above:
"Exception in thread "main" java.lang.NoClassDefFoundError: DresserApp
"Caused by java.lang.ClassNotFoundException: DresserApp
"at java.net.URLClassLoader$1.run(URLClassLoader.java;202)
" etc, etc for three more lines
"Could not find the main class: DresserApp. Program will exit."

So it seems to be telling me it can't find the class Dresser (code displayed earlier in thread). And as I mentioned, the class Dresser and DresserApp are both in the same folder in which I am running the Command Prompt.

Any ideas? Thanks in advance.


Nida Brek wrote:I notice that the 'not found' class is DresserApp, yet your code has a class called DresserAp ...

13 years ago
Hello. So I removed te offending close bracket in class Dresser. DresserApp compiled OK, but when I ran the script, I got the following error:

"Exception in thread main java.lang.NoClassDefFoundError: Dresser
"Caused by: java.lang.ClassNotFoundException: DresserApp
"at java.lang...
"at java.net...
"at java.security...
etc... for 3 more lines, then
"Could not find the main class: DresserApp

And yes, class Dresser, and DresserApp have been saved as .java files in the same folder in which I run the command prompt.

Any ideas? Thanks. jmp
13 years ago
Hello. Sorry about the unformated code. I'll fix that in future texts.

I didn't include the error messages because there were three different ones. But I see what you are saying about the closed bracket, and I'll fix that and see what I get, and report back.

In future posts I'll include error messages properly.

I appreciate your help with my learning efforts. Ron
13 years ago
Hello. I was trying do an exercise that requires I create a class, with variables for height, length, and depth, and then write an application that would display those variables.

So I wrote a class --

and then wrote a script --


And when I tried to compile it, I kept getting error messages saying there was a problem with the "show.Attributes" part.

Can anyone tell me what I'm doing wrong? Thanks
13 years ago
It works!!! (grin)

Here is the full code if anyone else wants to try it out:

class Testa {
public static void main(String[] arguments) {
int invest = 14000;
int deltainvest1;
System.out.println("Your initial investment is: " + invest);
deltainvest1 = (int)(invest + (invest * 0.4));
System.out.println("Your initial investment after one year of 40% return is: $" + deltainvest1);

deltainvest1 = deltainvest1 - 1500;
System.out.println ("If your investment loses $1500 in the second year, your return is $" +deltainvest1);

deltainvest1 = (int)(deltainvest1 + (deltainvest1 * 0.12));
System.out.println("If your investment gains 12% in the third year, your total return is $" + deltainvest1);

}
}


Thanks all who helped. ron
13 years ago
Wow, guys!! Thanks for your very helpful and complete reply.

1) I understand the problem and the suggested fixes. I'll give it a try.
2) What is a double? Is that a primitive data type?
3) I'm thinking that the code I'm writing will tell me the initial investment plus the 40% added. So: invest + 40% of invest.

Thanks again for your very complete reply. I'll probably have lots of these questions in the weeks to come. I appreciate your patience with stupid questions. Ron.


Matthew Brown wrote:Hi. Welcome to JavaRanch!

You're using integer variables, so they can't cope with anything after the decimal point. So the 0.4 is a problem. 0.4 is a double, so any calculation involving it is also going to give a double.

So when you try and assign that to an integer, you are potentially throwing away everything after the decimal point. The compiler won't let you do that without explicitly saying so. You potentially have this problem every time you convert from a "bigger" to a "smaller" type.

So you've got two options. One, you could use double variables throughout. Or, you can add an explicit cast like this:This is telling the compiler "yes, I know I'm going to lose information, and I'm happy with that".

By the way, the calculation doesn't look right, based on what you've described. I'd expect one of the following:

13 years ago
Hello. I'm new to Java and programming. This question is probably really stupid for experienced programmers.

I'm writing a practice code to tell me the value of an investment after one year of 40% growth. I declared two interger variables for the initial investment, and for the one year later investment. Then I wrote the following

deltainvest = invest + (invest * 0.4);

When compiling, I get the following message:

possible loss of precision
found : double
required : int

and then there is a "carrot" displayed under the plus sign in the above line of code.

Can anyone tell me what I am doing wrong? thanks
13 years ago