This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!

# Tatenda Mawoneke

Greenhorn
since Feb 11, 2020
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
1
1
Total given
0
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by Tatenda Mawoneke

Greetings, i am trying to get an understanding of classes and i am hard stuck on an error for the following code:

the output:

1 week ago

Stephan van Hulst wrote:In integral types, the number of bits determines the length of the range of numbers you can save.

In floating point types, the number of bits determines the maximum precision of numbers you can save.

In short, double gives you less rounding error than float.

using "Tim Moores" code above, Is this what you meant by errors:

like how float value rounds to 6130.4346 instead of 6130.4347?
1 week ago
Greetings, i read online that float is 32 bit and that double is 64 bit. What does this mean?? i know what a bit is, i can convert bit to decimal...but what i don't know is the importance between the difference between the two.

I wrote this small code to try see what is difference but that didn't really help paint the picture for me:

Any guidance is appreciated
1 week ago

Campbell Ritchie wrote:. . . This is what you started off with:- . . .And this is my corrupted version:- . . . If you are doing arithmetic with + in the same line as String concatenation, put () round the arithmetic. . . . .

This reduction is nice i understood it thanks, implemented it too:

What i did not really get was the "String concatenation" part...are you saying when adding two strings put them in brackets like so:

1 week ago
1 thing i am unsure of is the ones like this line:

what is really going on here: the "(int)(Math.random()" in particular what is that and why is it multiplied by the total number of items in the Icecream_flavour array? How does this produce a random number for the Icecream_flavour array
1 week ago

Campbell Ritchie wrote:Delete lines 9‑12. Use the .length fields throughout, or array1.length + array2.length for the total.

Thank you for your suggestion it really trimmed out the code and made it simpler. Also just added a little more touches to improve.

1 week ago

Dave Tolls wrote:num_of_Toppings is the total of one and two (7 in this case).
Consequently when you use it to generate the index to use for the arrays it has a pretty high chance of producing a number that's too large.

Ok i see the mistake thanks for your help!

have edited the code and this works fine :

1 week ago
Update:

so i notice when i run the code it works sometimes but sometimes it doesnt:

1 week ago
I am reading a book "Head First Java" and page 16 states:

so i tried to replicate this so i can make sure i understand it and did it like this in my own way:

what i am hoping the code does is to suggest a random combination for ice-cream flavour and toppings

now the error i receive when i run the (idk if it compiles is it now called a script?) code this is the error i receive :

Any thoughts appreciated.
1 week ago

Campbell Ritchie wrote:Head First Java? Even at fifteen years old, it is probably my favourite beginners' book. Don't try to run anything on objects from the Party class.
SDK is an old name for the JDK; the version numbers show that you have successfully run Java8. If you want Java13, try the following instruction at the command line, but I have probably got some of the folder names wrong:-Beware: code compiled with Java13 won't usually run on older versions.

Ok i will continue with this java version then and proceed to use notepad++.
Thanks.
1 week ago

Campbell Ritchie wrote:Please show us what happens when you execute these two commands:-

java -version
javac -version

That tutorial is no better than many on YouTube; I can see several things I am not happy about:-
• 1: It is out of date, using Java6 and Win7. On Win10 you have to create a separate PATH entry in a separate line for each program you want to run.
• 2: He is creating a user Path; I think it would be better to add the PATH to Java® to the beginning of the existing system PATH.
• 3: He calls the long error message after writing javac “crap”. It isn't crap at all.
• 4: The Java® code is incorrectly indented.
• 5: It is poor style to have [] after “args”. The [] belong after “String”.
• 6: It is poor style to have an xyz.java file and a class name starting with a lower‑case letter.
• 7: I would prefer to have the \Java folder elsewhere than the root of a drive.
• 8: He neither explains what he is doing with the PATH, nor that the installation window shows the correct PATH to add. See that video at 2′ 41″.
• If you are running Java11+, you can delete the xyz.class file and run your code by writing java Greetings.java Remember to give the class name a capital G.

The idea of the PATH is that it guides the OS where to find the programs called javac and java; they are both in the same PATH. It looks through all the PATH entries in order until it finds a program matching the requested name, e.g. java.

So for java version:

and for javac version:

note: I am using a book called "Head First Java" and i am just getting into it however it just says you need java sdk and a notepad but doesn't show how sdk work or what it is...it just shows the scripts and how to write them. So the video there is just the one i happened to have watched did not know it is not so good.

1 week ago
Perhaps you can tell me something also...

I installed " Java SE Development Kit 8u241" and also " Java SE Development Kit 13.0.2" and made a "environment variable" that goes to the bin for java...all this i saw on a video for getting started with java. Can you explain what the purpose of this would be?
1 week ago
Thank you i was about to google differences between typing java and javac.
1 week ago

Tim Moores wrote:"javac" is for compiling code, not for executing code. Re-read my previous post carefully - it tells you how to execute code.

Ok i see, my problem is solved thank you!
1 week ago
So i changed the code and added the public for class :

the file is saved in "C:\Users\mawoneket\Documents\Java Scripts" and it it saved as "greetings"

in command prompt i have used "C:\Users\mawoneket\Documents\Java Scripts>javac greetings.java" and this just jumps to the next line

when i use "C:\Users\mawoneket\Documents\Java Scripts>javac greetings" i get the message saying "error: Class names, 'greetings', are only accepted if annotation processing is explicitly requested
1 error"

Any thoughts on my errors?
1 week ago