File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Not sure how to get this code to work. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Not sure how to get this code to work." Watch "Not sure how to get this code to work." New topic
Author

Not sure how to get this code to work.

WeiJie Lim
Ranch Hand

Joined: Sep 05, 2012
Posts: 85
What I am planning to do here is to calculate the tax (7%) of a product given its name. I declared 2 variables milk and corn.

I can't get the program to 'remember' the value of the variable assigned to it ..

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

It's not really clear what your problem is. If it's that you're trying to turn the user's input "milk" into the local variable milk, you can't do that directly. You can do something like:



This approach is not scalable or flexible though. Without knowing what your exact assignment is, or what you're learned so far and are allowed to use, or what concept is being tested here, it's hard to advise any particular approach.
WeiJie Lim
Ranch Hand

Joined: Sep 05, 2012
Posts: 85
Oh, sorry for not being able to express my query accurately =/

The actual question is " Assuming that you are asked to calculate the GST ( 7% tax) of a product given the price. The formulae would be : gst*0.07.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

WeiJie Lim wrote:Oh, sorry for not being able to express my query accurately =/

The actual question is " Assuming that you are asked to calculate the GST ( 7% tax) of a product given the price. The formulae would be : gst*0.07.


That doesn't really clarify what particular problem you're having though.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7684
    
  19

Jeff Verdegan wrote:
WeiJie Lim wrote:The actual question is " Assuming that you are asked to calculate the GST ( 7% tax) of a product given the price. The formulae would be : gst*0.07.
That doesn't really clarify what particular problem you're having though.

And it isn't actually a question either.

@WeiJie: programming is NOT coding. Before you write a line of Java code you should plan what you want to do.

My advice: write down the steps you need to accomplish your task in detail, and in English (or your native language); and do it with your computer turned OFF.

You will never be able to code a solution until you understand the problem.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

In addition to what Winston says, when you do start coding, start small. Start as small as you need to to get it to compile and run. Maybe that means you start with:


and after that you add just enough code to calculcate the tax on a hardcoded value. And once you get that working, you move on to taking user input or summing up totals or whatever else you need to do. But at each step, you start with a working program and add just a little bit to it and get that program working before moving on. Don't be afraid to write separate, small, throw-away programs to test a concept by itself, without the clutter of the other stuff you've done so far. I've been programming professionally for possibly longer than you've been alive and I still do that all the time.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
Ryan McClain,
Your post was moved to a new topic.
WeiJie Lim
Ranch Hand

Joined: Sep 05, 2012
Posts: 85
Thanks all for the replies. I greatly appreciate them =) .

I realised I may have misinterpreted the question.

Here's what I got after I spent some time jotting down my plans .. Should be correct I guess haha.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Not sure how to get this code to work.