• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Not sure how to get this code to work.

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ..

 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 76833
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ryan McClain,
Your post was moved to a new topic.
 
WeiJie Lim
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic