Results 1 to 2 of 2
- 11-18-2011, 11:33 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 10
- Rep Power
- 0
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; } }
-
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
-
Cannot find symbol (compile error)
By mrgreenacid in forum New To JavaReplies: 1Last Post: 10-30-2011, 04:55 AM -
Cannot find symbol (compile error)
By mrgreenacid in forum Java SoftwareReplies: 2Last Post: 10-30-2011, 03:42 AM -
USing JGrasp to Compile and receiving Cannot find symbol
By johnb082 in forum New To JavaReplies: 6Last Post: 06-23-2011, 10:37 PM -
Constructor: Cannot find symbol compile error.
By CaptainBeer in forum New To JavaReplies: 4Last Post: 04-28-2011, 11:25 AM -
java:92: cannot find symbol error
By noviceNewbie in forum AWT / SwingReplies: 3Last Post: 12-18-2010, 02:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks