• Post Reply Bookmark Topic Watch Topic
  • New Topic

Pseudocode To Java Help  RSS feed

 
kyle organi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, I have this psuedocode I need changing to Java, but I am struggling. Here is what I have currently, but it's not working. Any help would be appreciated. Thanks!

This is the Java code I made:




This is the Pseudocode:

 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any time you are adding, you need a number. I'd use int.

AND PLEASE DON'T USE ALL CAPS.
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the ranch!

What is the problem with the code. What is not working? What did you understand from the compiler error?

Have a look at this - http://www.coderanch.com/how-to/java/KeepItDown
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kyle. Welcome to the Ranch!

It's not much help to say something isn't working. What isn't working? Have a look at this link -> ItDoesntWorkIsUseless

Starting on line 1, though: Java doesn't have a built-in class called string. It does have one called String, though: case matters. And 'x' indicates character literal. You've used it as both a String and a number in that code, neither of which are valid.
 
kyle organi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Any time you are adding, you need a number. I'd use int.

AND PLEASE DON'T USE ALL CAPS.


sorry just signed up to this website, also do you mind helping me by editing my current code to show me what you mean? thanks
 
kyle organi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:Hi Kyle. Welcome to the Ranch!

It's not much help to say something isn't working. What isn't working? Have a look at this link -> ItDoesntWorkIsUseless

Starting on line 1, though: Java doesn't have a built-in class called string. It does have one called String, though: case matters. And 'x' indicates character literal. You've used it as both a String and a number in that code, neither of which are valid.


sorry there, forgot to copy that bit off the code, this is the full code I have:

 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what happens when you try that code out.

And welcome again
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kyle organi wrote: . . . do you mind helping me by editing my current code . . . thanks
Push the and buttons. But only change the formatting (block capitals), not the actual code. Changes are recorded and I can cause your post to revert to an older version.
 
kyle organi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:And what happens when you try that code out.

And welcome again





The error message says:

Error on line 7 in program
possible loss of precision
found : double
required: int

But every time I type double or int in line 7 it says:

balance is already defined in main(java.lang.String[])
 
kyle organi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
kyle organi wrote: . . . do you mind helping me by editing my current code . . . thanks
Push the and buttons. But only change the formatting (block capitals), not the actual code. Changes are recorded and I can cause your post to revert to an older version.


can't you just copy the code i posted and just edit that instead?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kyle organi wrote:Error on line 7 in program
possible loss of precision
found : double
required: int

But every time I type double or int in line 7 it says:

balance is already defined in main(java.lang.String[])

Right. You can't redefine balance. You can declare it originally as a double and not an int (a few lines up in the program.)
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kyle organi wrote:can't you just copy the code i posted and just edit that instead?

No.

First off: We're NotACodeMill (←click). We will help you to find the problem, but we won't do the work for you.

Second: The business of providing an SSCCE is yours. Again, we will help if you need it; but the initial effort has to come from you.

We're all volunteers here, and we answer lots of questions a day; so the clearer your question is, and the more help you give us, the better your chances of getting a speedy reply.

Hope you understand the "rules" now.

Winston
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Loss of precision means you are trying to get a floating‑point value into an integer variable. That doesn't work. Consider which variables should be integer (usually declared as int) or floating‑point (usually double).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!