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

    Default Setting up main method

    Fellow programmers, I am trying to figure out how to tie two classes I created into a main method that will show the capabilities of the customer class. I need to create an array of two Customer objects and attempt to make a sale to each. Then I need to setup the customers and the sale so that one sale will go through and one will fail. When I create the Customer objects I need to make sure to set the creditLimit and currentCreditAmount so that the new sale will work as expected. I have done this successfully I believe.

    Here is what I am having trouble with. Setting it up so I can use System.out.printf to get the following information for each sale: Full name of customer (This getFullName method is set up in my Person Class), sale amount, total current credit, and rather or not the sale went through. When I write my printf and type Person.getFullName I get an error this is also the same with Customer.method So far this is what I have:



    Java Code:
    public class CustomerTest {
    	public static void main ( String [] args )
    	{
    		Person pers1 = new Person();
    		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", pers1.getFullName());
    	 
    	}
    }
    
    public class Person 
    {
    	private String firstName;
    	private String lastName;
    	private String idSSN;
    		
    	public void setFirstName (String first)
    	{
    		firstName = first;
    	}
    	
    	public String getFirstName ()
    	{
    		return firstName;
    	}
    	
    	public void setLastName (String last)
    	{
    		lastName = last;
    	}
    	
    	public String getLastName ()
    	{
    		return lastName;
    	}
    	
    	public void setidSSN (String ss)
    	{
    		idSSN = ss;
    	}
    	
    	public String getidSSN ()
    	{
    		return idSSN;
    	}
    	
    	public Person (String first, String last, String ss)
    	{
    		firstName = first;
    		lastName = last;
    		idSSN = ss;
    	}
    	
    	public String getFullName ()
    	{
    		return String.format("First Name: %s\nLast Name: %s, getFirstName, getLastName");
    	}
    
    
    
    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;
    		}
    	}
    }

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    Also at forums.sun.com.

    @OP: It's best to be upfront when carrying on the discussion at multiple places so everyone can be a party to the entire dialogue and as no-one wants to waste their time repeating what might have been said elsewhere.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

Similar Threads

  1. Help with main method
    By eliCanzee in forum JDBC
    Replies: 4
    Last Post: 01-06-2010, 10:12 AM
  2. calling method from main method
    By bob_bee in forum New To Java
    Replies: 4
    Last Post: 10-02-2009, 06:30 PM
  3. Where do I put main method?
    By jerryrice80 in forum New To Java
    Replies: 4
    Last Post: 09-16-2009, 09:23 PM
  4. Help me for main method
    By eliCanzee in forum AWT / Swing
    Replies: 1
    Last Post: 05-26-2009, 01:43 PM
  5. main method
    By eva in forum New To Java
    Replies: 5
    Last Post: 12-19-2007, 10:25 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
  •