Results 1 to 3 of 3

Thread: Math question

  1. #1
    BenH is offline Member
    Join Date
    Dec 2011
    Posts
    48
    Rep Power
    0

    Default Math question

    Hi there.

    I am writing a program that calculates the value of the inventory of a product then it adds a 5% restocking fee to the value of the inventory. Here is my formula for the program: calEquals = m1 * 10 * restockFee; The code is posted below. The problem I am having is the value of the inventory is $130.00. But when I add the restocking fee the answer is $6.5. What am I doing wrong? Can someone help me with this?

    Java Code:
    /*
    Author: Ben Hartnett
    Sources: Java: A Beginner's Guide
    Source 2: Monster example posted on student forums
    Date Retrieved: 1-26-2012
    */
    
    public class InventoryAdvanced {
    
    public static void main(String args[]){
    
    		//Define the calculation variables
    		double c1;
    		double c2;
    		double c3;
    
    		//Declare the calculation variables
    		c1 = 13.00;
    		c2 = 5.00;
    		c3 = 10.00;
    
    		//Declare the 5% restocking fee
    		double fee = .05;
    
    		//Create the objects
    		InventoryDefine swordstone = new InventoryDefine("Sword In The Stone Movie", 1, 10, 13.00, 130.00);
    		InventoryDefine hercules = new InventoryDefine("Hercules Movie", 2, 20, 5.00, 100.00);
    		InventoryDefine mermaid = new InventoryDefine("The Little Mermaid Movie", 3, 30, 10.00, 300.00);
            InventorySort sortThis = new InventorySort();
    		InventoryCal cal = new InventoryCal();
    		SwordStone movie = new SwordStone();
    
    		//Use an object to store the array
       		InventoryDefine[] inventoryArray = new InventoryDefine[3];
    
    		//Declare the arrays
       		inventoryArray[0] = swordstone;
       		inventoryArray[1] = hercules;
       		inventoryArray[2] = mermaid;
    
    		//Call the method from the sortThis object
    		sortThis.Sort(inventoryArray);
    
    		//Call the method from InventoryCal
    		cal.calVar(c1, c2, c3);
    
    		//Override the method from InventoryInherit
    		movie.calVar(c1, fee);
    
    	}
    }
    Java Code:
    public class SwordStone extends InventoryCal {
    
    	//Create the calculation method
    	public void calVar(double m1, double restockFee){
    
    		//Create the calculation variable
    		double calEquals;
    
    		//Create the equation
    		calEquals = m1 * 10 * restockFee;
    
    		//Display the result
    		System.out.println("Sword In The Stone product value with restocking fee:" + calEquals);
    
    	}
    
    }

  2. #2
    mwr1976 is offline Senior Member
    Join Date
    Oct 2011
    Posts
    106
    Rep Power
    0

    Default Re: Math question

    130 * .05 = 6.5 you should do a calculation like this:

    Java Code:
    double cost = 130.00;
    
    cost += (cost * fee) ;
    hope it helps!

  3. #3
    BenH is offline Member
    Join Date
    Dec 2011
    Posts
    48
    Rep Power
    0

Similar Threads

  1. Doing Math
    By nicholas205 in forum New To Java
    Replies: 1
    Last Post: 01-28-2012, 03:18 AM
  2. Discrete Math Question
    By HardToHandle in forum New To Java
    Replies: 9
    Last Post: 01-16-2012, 08:49 AM
  3. Create Math.sin without math.sin
    By vudoo in forum New To Java
    Replies: 11
    Last Post: 12-07-2010, 07:23 AM
  4. Math.random Question
    By noble in forum New To Java
    Replies: 21
    Last Post: 09-16-2010, 03:17 AM
  5. Math class question
    By shendel in forum New To Java
    Replies: 1
    Last Post: 03-05-2009, 01:06 PM

Posting Permissions

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