Results 1 to 2 of 2

Thread: Passing Value

  1. #1
    katherine_93 is offline Member
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Default Passing Value

    I need help trying to pass this number through as a sale amount. Then if the sale amount + currentCreditAmount is less than the credit limit the operation will be true and excuted else it will be false and nothing will happen. The total current credit will also need to be calculated as well. So far this is what I have.

    Java Code:
    public class Customer extends Person {
    	
    	double creditLimit = 0.0;
    	double currentCreditAmount;
    	
    	public Customer(String first, String last, String ss, double limit,
    			double amount)
    	{
    		super(first, last, ss);
    		setCreditLimit (limit);
    		setCurrentCreditAmmount (amount);
    	}
    	
    	public void setCreditLimit(double limit) {
    		creditLimit = limit;		
    	}
    	
    	public double getCreditLimit()
    	{
    		return creditLimit;
    	}
    
    	public void setCurrentCreditAmmount(double amount) {
    		currentCreditAmount = amount;
    	}
    	
    	public double getCreditAmount()
    	{
    		return currentCreditAmount;
    	}
    
    	public boolean makeSale (double saleAmount)
    	{
    		if (saleAmount+currentCreditAmount <= creditLimit)
    		{
    			saleAmount+=currentCreditAmount;
    			return true;
    		}
    		else
    		{
    			return false;
    		}
    	}
    }
    
    
    public class CustomerTest {
    	public static void main ( String [] args )
    	{
    		Customer cust1 = 
    			new Customer(
    					"Bob", "Anderson", "222-22-2222", 10000 , 2000 );
    		
    		Customer cust2 = 
    			new Customer(
    					"Jim", "Smoltz", "333-33-3333", 5000 , 3000 );
    		
    		System.out.printf("Customer Name: %s%n", cust1.getFullName());
    		System.out.printf("Did the sale go through? %s\n", cust1.makeSale(4000));
    		System.out.printf("Sale Amount: \n", cust1);
    		System.out.printf("Credit Amount: \n\n", cust1.getCreditAmount());
    		
    		
    		
    		System.out.printf("Customer Name: %s%n", cust2.getFullName());
    		System.out.printf("Did the sale go through? %s", cust1.makeSale(4000));
    	}
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

Similar Threads

  1. Passing a value..
    By Lagarto in forum New To Java
    Replies: 3
    Last Post: 01-23-2011, 05:58 PM
  2. Passing value....
    By casid in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 01-03-2010, 11:19 AM
  3. passing something
    By dinosoep in forum Threads and Synchronization
    Replies: 2
    Last Post: 12-05-2009, 09:26 AM
  4. Passing Objects
    By Java_Developer in forum New To Java
    Replies: 6
    Last Post: 10-29-2009, 01:32 PM
  5. passing value from jsp to applet
    By bhupendrabjain in forum Java Applets
    Replies: 4
    Last Post: 10-07-2008, 01:55 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
  •