Results 1 to 2 of 2
  1. #1
    vcardell is offline Member
    Join Date
    Nov 2011
    Posts
    10
    Rep Power
    0

    Default I'm getting CustomerTest.java:38: error: cannot find symbol when i try to compile

    the error msg i'm getting is

    C:\myjavaclass>javac CustomerTest.java
    CustomerTest.java:38: error: cannot find symbol
    customerArray[i]=new Customer(a[i][0],new Address(a[i][1],a[i][
    2],a[i][3],Integer.parseInt(a[i][4])), new Policy(p,a[i][6],Double.parseDouble(a
    [i][7])));

    ^
    symbol: method parseDouble(String)
    location: class Double
    1 error

    I can't figure out what i'm doing worng...
    Any help would be greatly appreciated.

    Here is the problem i'm working on below.


    Write all classes to adhere to our Java class coding standards. Notice that Customer is composed of class Policy and class Address and that Customer has an additional method, calculateBill.

    Write a program, CustomerTest, where main declares a two-dimensional String array, dataArray, that looks as follows.

    Jones, 122 Cooper Street, Arlington, Virginia, 53456, auto, A1234, 325.00
    Smith, 21A Lover Lane, Dallas, Texas, 75025, life, L5467, 175.75
    Hanover, 4315 Express Way, Euless, Texas, 73867, home, H3956, 1200.00
    Kincaid, 225 Dora Lane, Tulsa, Oklahoma, 63901, auto, A2012, 550.50
    Sierra, 789 Bowen Road, New Orleans, Louisiana, 53412, life, L4378, 212.60

    Each row of the array is the name of the customer, street, city, state, zip, policy type, policy number, and annual premium. Each row can be used to create an instance of Customer.

    CustomerTest has two additional methods: buildInstances, and createReport. buildInstances and createReport have the following signatures:

    Customer[] buildInstances(String data[][]))

    String createReport(Customer array[])

    The main method calls buildInstances which creates a customer array from the data in the original array and returns the new array. Then main calls createReport which walks through the customer array, calls calculateBill for each customer, and builds a string of all the customers and their amount due for each policy and the grand total. The main method prints the string returned from createReport.

    calculateBill returns the billing amount. This is calculated as follows.
    If the customer lives in Texas and has a home policy, they are given a 10% discount.
    If the customer has an auto policy and lives out of state, they are charged an extra 5%.

    Printout should be aligned and formatted to look like this at the system prompt.

    Name State Policy Type Annual Premium
    Jones Texas AUTO $341.25
    Smith Texas LIFE $175.75
    Hanover Texas HOME $1,080.00
    Etc etc

    Total Premiums Due $x,xxx.xx

    Here is my code for the address,policy,and customer classes and customertest

    Java Code:
    public class Address 
    {
    	private String street;
    	private String city;
    	private String state;
    	private int zip;
    
    	public Address()
    	{
    		setStreet("");
    		setCity("");
    		setState("");
    		setZip(0);
    	}
    	public Address(String s, String c, String t, int z)
    	{
    		setStreet(s);
    		setCity(c);
    		setState(t);
    		setZip(z);
    	}
    
    	public void setStreet(String s)
    	{
    		street = s;
    	}
    	public void setCity(String c)
    	{
    		city = c;
    	}
    	public void setState(String t)
    	{
    		state = t;
    	}
    	public void setZip(int z)
    	{
    		zip = z;
    	}
    	
    	public String getStreet()
    	{
    		return street;
    	}
    	public String getCity()
    	{
    		return city;
    	}
    	public String getState()
    	{
    		return state;
    	}
    	public int getZip()
    	{
    		return zip;
    	}
    	public String toString()
    	{
    		return ("Streeet" + street + "City" + city + "State" + state + "Zip" + zip);
    	}
    }
    Java Code:
    public class Policy
    {
    	
    	private String policyNumber;
    	private double annualPremium;
    	public enum PolicyType{AUTO, HOME, LIFE};
    	private PolicyType pType;
    
    	
    	
    	public Policy()
    	{
    		setPolicyNumber("");
    		setAnnualPremium(0);
    		setPType(PolicyType.AUTO);
    	}
    	
    	public Policy(PolicyType t, String p, double a)
    	{
    		setPType(t);
    		setPolicyNumber(p);
    		setAnnualPremium(a);
    		
    	}
    	public void setPType(PolicyType t)
    	{
    		pType = t;
    	}
    	
    	public void setPolicyNumber(String p)
    	{
    		policyNumber = p;
    	}
    	
    	public void setAnnualPremium(double a)
    	{
    		annualPremium = a;
    	}
    	public PolicyType getPType()
    	{
    		return pType;
    	}
    	
    	public String getPolicyNumber()
    	{
    		return policyNumber;
    	}
    	
    	public double getAnnualPremium()
    	{
    		return annualPremium;
    	}
    	public String toString()
    	{
    		return ("Policy type" + pType + "Policy number" + policyNumber + "Annual premium" + annualPremium);
    	}
    }
    Java Code:
    public class Customer 
    {
    	private String name;
    	private Address address;
    	private Policy policy;
    
    
    	public Customer()
    	{
    		setName("");
    		setAddress(new Address());
    		setPolicy (new Policy());
    	}
    	
    	public Customer(String n, Address a, Policy p)
    	{
    		setName(n);
    		setAddress(a);
    		setPolicy(p);
    	}
    
    	public void setName(String n)
    	{
    		name = n;
    	}
    	public void setAddress(Address a)
    	{
    		address = a;
    	}
    	public void setPolicy(Policy p)
    	{
    		policy = p;
    	}
    	
    	public double calculateBill()
    	{
    		double amount = 0;
    		
    		if(address.getState().equals("Texas")&&(policy.getPType()==Policy.PolicyType.HOME))
    		amount = policy.getAnnualPremium() *.90;
    		//System.out.printf("$%.2f",amount);
    			
    		
    		
    		else if (!address.getState().equals("Texas")&&(policy.getPType()==Policy.PolicyType.AUTO));
    		amount = policy.getAnnualPremium() *1.05;
    		//System.out.printf("$%.2f",amount);
    			
    		
    		
    		return amount;	
    			
    	}
    
    	public String getName()
    	{
    		return name;
    	}
    	public Address getAddress()
    	{
    		return address;
    	}
    	public Policy getPolicy()
    	{
    		return policy;
    	}
    	
    	public String toString()
    	{
    		return ("Name" + name + "address" + address.toString() + "policy" + policy.toString());
    	}
    }
    Java Code:
    public class CustomerTest
    {
    	public static void main(String args[])
    	{
    	
    		String stringArray[][] = {{"Jones","122 Cooper Street","Arlington","Virginia","53456","auto","A1234","325.00"},
    				  	  {"Smith","21A Lover Lane","Dallas","Texas","75025","life","L5467","175.75"},
    				   	  {"Hanover","4315 Express way","Euless","Texas","73867","home","H3956","1200.00"},
    				 	  {"Kincaid","225 Dora Lane","Tulsa","Oaklahoma","63901","auto","A2012","550.50"},
    				  	  {"Sierra","789 Bowen Road","New Orleans","Louisiana","53412","life","L4378","212.60"}};
    	
    		
    		String s;
    		
    			
    
    		Customer array[] = new Customer[stringArray.length];
    		
    		s = createReport(array);
    		array = buildInstances(stringArray);
    		
    		
    		System.out.printf("%-15s%-15s%-15s%15s\n","Name","State","PolicyType","Annual Premium");
    		System.out.print(s);
    
    	}
    	
    	public static Customer[] buildInstances(String dataArray[][])
    	{
    		Policy.PolicyType pt = null;
    		Customer customerArray[] = new Customer[dataArray.length];
    
    		for (int i = 0; i< dataArray.length; i++)
    		{
     				
    			if (dataArray[i][5].equals("auto"))
    				pt = Policy.PolicyType.AUTO;
    			
    			else if (dataArray[i][5].equals("life"))
    				pt = Policy.PolicyType.LIFE;
    			
    			else if (dataArray[i][5].equals("home"))
    				pt = Policy.PolicyType.HOME;
    
    			//double p = Double.parseDouble(dataArray[i][7]);
    
    		customerArray[i] = new Customer(dataArray[i][0],new Address(dataArray[i][1],dataArray[i][2],dataArray[i][3],Integer.parseInt(dataArray[i][4])), 
    			
    				new Policy(pt, dataArray[i][6],Double.parseDouble(dataArray[i][7])));
    		}		
    		return customerArray;
    
    		
    	}
    
    	
    public static String createReport(Customer array[])
    	{
    		String message ="";
    		double total = 0;
    		
    		for (int i = 0; i< array.length; i++)
    		{
    			
    			total+= array[i].calculateBill();
    			message +=String.format("%-15s%-15s%-15s%$%-15.2f\n", 
    array[i].getName(),array[i].getAddress().getState(), array[i].getPolicy().getPType(),
    array[i].calculateBill());
    		
    		}
    		message+=String.format("Total Premium Due                 $%-50.2f\n",total);
    		return message;
    
    	}
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: I'm getting CustomerTest.java:38: error: cannot find symbol when i try to compile

    Are you sure that that is the error that this code generates and not a NullPointerException (NPE)?

Similar Threads

  1. Cannot find symbol (compile error)
    By mrgreenacid in forum New To Java
    Replies: 1
    Last Post: 10-30-2011, 05:55 AM
  2. Cannot find symbol (compile error)
    By mrgreenacid in forum Java Software
    Replies: 2
    Last Post: 10-30-2011, 04:42 AM
  3. Replies: 6
    Last Post: 06-23-2011, 11:37 PM
  4. Constructor: Cannot find symbol compile error.
    By CaptainBeer in forum New To Java
    Replies: 4
    Last Post: 04-28-2011, 12:25 PM
  5. java:92: cannot find symbol error
    By noviceNewbie in forum AWT / Swing
    Replies: 3
    Last Post: 12-18-2010, 03:46 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
  •