Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2014
    Posts
    4
    Rep Power
    0

    Default Very new to java, need a little guidance with a Project (percentage question)

    Hi, and thank you for helping/looking at this in advanced.

    I'm trying to code an if-else statement where I need to find the percentage discount on an item without hardcoding it.

    double Item1=30.50;
    double Item2=40.50;
    double discount=.07;

    These are the values I have. Basically I just need an explanation of how to code a statement so I receive the calculated discount of a Full or Compact. Sorry If I explained this poorly.

    Here is the excerpt from the code, I can copy the whole code in too if needed.

    Java Code:
           System.out.println("You selected Item1.");
                              System.out.print("Have coupon? [Y or N]");
                              answer = kb.next();
                    if (answer.equalsIgnoreCase("n"))
                           System.out.print("Price is 30.50 per day.");
                    if (answer.equalsIgnoreCase("y"))	  
    	              >This is what I'm looking for<

  2. #2
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    184
    Rep Power
    0

    Default Re: Very new to java, need a little guidance with a Project (percentage question)

    I mean, if I understand what you're saying, you may just be over thinking this.

    Not "hard-coding" it simply would mean not doing the calculations yourself and printing out "Price is 27.49" or whatever.

    All you would need to do is print out "Price is " + ( calculations here )" per day."

    That is the whole idea of not "hard-coding" - so that you can later go in, change your discount to .09 or something, and get an updated result automatically.

Similar Threads

  1. Need guidance, first Java assignment.
    By Creature in forum New To Java
    Replies: 5
    Last Post: 10-02-2013, 06:04 AM
  2. Percentage in Java
    By threlot in forum New To Java
    Replies: 1
    Last Post: 11-13-2012, 10:43 AM
  3. [URGENT] Due in 1.5 hrs. VERY easy java project question
    By inimitablesikh in forum New To Java
    Replies: 1
    Last Post: 09-29-2011, 07:38 AM
  4. Project Guidance
    By Catfather in forum Advanced Java
    Replies: 2
    Last Post: 02-28-2011, 06:36 AM
  5. Replies: 1
    Last Post: 01-07-2011, 06:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •