cannot find symbol symbol : method

New Project Help

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 10859 Views - Last Post: 12 February 2009 - 09:41 AM Rate Topic: -----

#1 tscott  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 370
  • Joined: 30-January 09

cannot find symbol symbol : method

Posted 06 February 2009 - 01:54 PM

 import java.util.Scanner;

public class Landscape
{
  public static void main (String [] args)
  {
	Scanner keyboard = new Scanner (System.in);
	
	int feet3, feet3_6, feet6, treespurchased, treeheight, delivery;
	String input;
	int answer;
	
	System.out.printf("%12s", "Nachbauer Gardens");
	System.out.println ();
	System.out.println("Tree Purchasing System");
	System.out.println("How many trees do you wish to purchase? ");
	treespurchased = keyboard.nextInt();
	
	System.out.print("Enter 1 for delivery only, 2 for planting, 3 for none : (1=delivery, 2=planting, 3=none) ");
					   input = keyboard.nextLine();
					   answer = input.intAt(0);
	System.out.println("Green Fields Billing Statement");
	System.out.print("\nNUMBER OF TREES PURCHASED " + treespurchased); 
  }
}

	


1 error found:
File: C:\Documents and Settings\Tim\Desktop\javaprograms\Landscape.java [line: 21]
Error: C:\Documents and Settings\Tim\Desktop\javaprograms\Landscape.java:21: cannot find symbol
symbol : method intAt(int)
location: class java.lang.String


I want the output to analyze what the user hit it doesn't need to print that but later I'm going to have that be analyzed based on what they hit so I can print that there is a delivery charge. In a If statement

Is This A Good Question/Topic? 0
  • +

Replies To: cannot find symbol symbol : method

#2 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: cannot find symbol symbol : method

Posted 06 February 2009 - 02:32 PM

there isnt a method called intAt(), what are you trying to do, maybe i can hook you up with the correct method name
Was This Post Helpful? 0
  • +
  • -

#3 tscott  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 370
  • Joined: 30-January 09

Re: cannot find symbol symbol : method

Posted 06 February 2009 - 02:54 PM

in my book it says there is a input.charAt(0) but in this case I'm working with #'s not characters so I need something that will analyze the input as if the #1s were press y for yes press n for no
Was This Post Helpful? 0
  • +
  • -

#4 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: cannot find symbol symbol : method

Posted 06 February 2009 - 02:58 PM

well you can still use 1, 2 and 3 as characters
import java.util.Scanner;

public class Landscape
{
  public static void main (String [] args)
  {
	Scanner keyboard = new Scanner (System.in);
   
	int feet3, feet3_6, feet6, treespurchased, treeheight, delivery;
	String input;
	char answer;
   
	System.out.printf("%12s", "Nachbauer Gardens");
	System.out.println ();
	System.out.println("Tree Purchasing System");
	System.out.println("How many trees do you wish to purchase? ");
	treespurchased = keyboard.nextInt();
   
	System.out.print("Enter 1 for delivery only, 2 for planting, 3 for none : (1=delivery, 2=planting, 3=none) ");
					   input = keyboard.nextLine();
					   answer = input.charAt(0);
	System.out.println("Green Fields Billing Statement");
	System.out.print("\nNUMBER OF TREES PURCHASED " + treespurchased);
  }
}


Was This Post Helpful? 0
  • +
  • -

#5 tscott  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 370
  • Joined: 30-January 09

Re: cannot find symbol symbol : method

Posted 06 February 2009 - 10:41 PM


import java.util.Scanner;

public class Landscape
{
  public static void main (String [] args)
  {
	Scanner keyboard = new Scanner (System.in);
	
	int feet3, feet3_6, feet6, treespurchased, treeheight, delivery;
	String input;
	char answer;
	
	System.out.printf("%12s", "Nachbauer Gardens");
	System.out.println ();
	System.out.println("Tree Purchasing System");
	System.out.println("How many trees do you wish to purchase? ");
	treespurchased = keyboard.nextInt();
	
	System.out.print("Enter 1 for delivery only, 2 for planting, 3 for none : (1=delivery, 2=planting, 3=none) ");
					   input = keyboard.nextLine();
					   answer = input.charAt(0);
					   
	System.out.println("Green Fields Billing Statement");
	System.out.print("\nNUMBER OF TREES PURCHASED " + treespurchased); 
  }
}

	

OUTPUT:

Nachbauer Gardens
Tree Purchasing System
How many trees do you wish to purchase?
[DrJava Input Box]
Enter 1 for delivery only, 2 for planting, 3 for none : (1=delivery, 2=planting, 3=none) java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(Unknown Source)
at Landscape.main(Landscape.java:21)
> 2
2


What does this error message mean above? I can't seem to figure it out. Any help would be appreciated
Was This Post Helpful? 0
  • +
  • -

#6 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: cannot find symbol symbol : method

Posted 06 February 2009 - 11:44 PM

The message means that the string input has zero length, so there is no indexed position zero.

	System.out.println("How many trees do you wish to purchase? ");
	treespurchased = keyboard.nextInt();


When inputting an integer the scanner leaves the end of line in the buffer. So the your next call to nextLine() will read that rather than the answer to the prompt. Here's a way to avoid that. :)
...
	input = keyboard.nextLine();
	
	if (input.trim().length() > 0) //did user enter anything?
		try {
			treespurchased = Integer.parseInt(input);			
		}
		catch(NumberFormatException ex) {
			// handle error when user doesn't enter a number
		}
	else
		treespurchased = 0;

	System.out.print("Enter 1 for delivery only, 2 for planting, 3 for none : (1=delivery, 2=planting, 3=none) ");
	
	input = keyboard.nextLine();

	if (input.trim().length() > 0)
		answer = input.charAt(0);
	else
		answer = 3; // assume none
...


This post has been edited by n8wxs: 06 February 2009 - 11:46 PM

Was This Post Helpful? 0
  • +
  • -

#7 tscott  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 370
  • Joined: 30-January 09

Re: cannot find symbol symbol : method

Posted 09 February 2009 - 02:46 PM

Thank you for the help but I'm still getting in error.


 import java.util.Scanner;

public class Landscape
{
  public static void main (String [] args)
  {
	Scanner keyboard = new Scanner (System.in);
	
	int feet3, feet3_6, feet6, treespurchased, treeheight, delivery, length;
	String input;
	char answer;
	
	System.out.printf("%12s", "Nachbauer Gardens");
	System.out.println ();
	System.out.println("Tree Purchasing System");
	System.out.println("How many trees do you wish to purchase? ");
	treespurchased = keyboard.nextInt();
	
	System.out.print("Enter 1 for delivery only, 2 for planting, 3 for none : (1=delivery, 2=planting, 3=none) ");
					   input = keyboard.nextLine();
					   
					   if input.trim().length() > 0)
							 try {
						 treespurchased = Integer.parseInt (input);
					   }
					   catch(NumberFormatException ex) {
					   }
						   else
							 treespurchased = 0;
							 System.out.print("Enter 1 for delivery only, 2 for planting, 3 for none : (1=delivery, 2=planting, 3=none) ");
						   input = keyboard.nextLine();

						   if (input.trim().length() > 0)
							 answer = input.charAt(0);
						   else
							 answer = 3;
					   
	System.out.println("Green Fields Billing Statement");
	System.out.print("\nNUMBER OF TREES PURCHASED " + treespurchased); 
  }
}




1 error found:
File: C:\Documents and Settings\Tim\Desktop\javaprograms\Landscape.java [line: 22]
Error: C:\Documents and Settings\Tim\Desktop\javaprograms\Landscape.java:22: '(' expected


can you also tell me why you used if input.trim().length() > 0)
Was This Post Helpful? 0
  • +
  • -

#8 prajayshetty  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 31
  • View blog
  • Posts: 920
  • Joined: 27-April 07

Re: cannot find symbol symbol : method

Posted 09 February 2009 - 02:56 PM

you missed a brace in the if loop check it in the test condition

if input.trim().length() > 0) make it to if (input.trim().length() > 0)
Was This Post Helpful? 0
  • +
  • -

#9 tscott  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 370
  • Joined: 30-January 09

Re: cannot find symbol symbol : method

Posted 09 February 2009 - 03:26 PM

Thanks for the help but now the only problem is my output after I enter the delivery says trees purchased 0> when it should say the number the user inputted. as shown in the code below.

OUTPUT:
Nachbauer Gardens
Tree Purchasing System
How many trees do you wish to purchase?
[DrJava Input Box]
Enter 1 for delivery only, 2 for planting, 3 for none : (1=delivery, 2=planting, 3=none)
[DrJava Input Box]
Green Fields Billing Statement

NUMBER OF TREES PURCHASED 0>

import java.util.Scanner;

public class Landscape
{
  public static void main (String [] args)
  {
	Scanner keyboard = new Scanner (System.in);
	
	int feet3, feet3_6, feet6, treespurchased, treeheight, delivery, length;
	String input;
	char answer;
	
	System.out.printf("%12s", "Nachbauer Gardens");
	System.out.println ();
	System.out.println("Tree Purchasing System");
	System.out.println("How many trees do you wish to purchase? ");
	treespurchased = keyboard.nextInt();
	
						  input = keyboard.nextLine();
					   
					   if (input.trim().length() > 0)
							 try {
						 treespurchased = Integer.parseInt (input);
					   }
					   catch(NumberFormatException ex) {
					   }
						   else
							 treespurchased = 0;
							 System.out.println("Enter 1 for delivery only, 2 for planting, 3 for none : (1=delivery, 2=planting, 3=none) ");
						   input = keyboard.nextLine();

						   if (input.trim().length() > 0)
							 answer = input.charAt(0);
						   else
							 answer = 3;
					   
	System.out.println("Green Fields Billing Statement");
	System.out.print("\nNUMBER OF TREES PURCHASED " + treespurchased); 
  }
}


Was This Post Helpful? 0
  • +
  • -

#10 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: cannot find symbol symbol : method

Posted 09 February 2009 - 05:14 PM

what is this supposed to mean??
if (input.trim().length() > 0)
							 try {
						 treespurchased = Integer.parseInt (input);
					   }
					   catch(NumberFormatException ex) {
					   }
						   else
							 treespurchased = 0;
							 System.out.println("Enter 1 for delivery only, 2 for planting, 3 for none : (1=delivery, 2=planting, 3=none) ");
						   input = keyboard.nextLine();

						   if (input.trim().length() > 0)
							 answer = input.charAt(0);
						   else
							 answer = 3;


Was This Post Helpful? 0
  • +
  • -

#11 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: cannot find symbol symbol : method

Posted 09 February 2009 - 06:05 PM

Modified title to be more descriptive of the problem.
Was This Post Helpful? 0
  • +
  • -

#12 tscott  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 370
  • Joined: 30-January 09

Re: cannot find symbol symbol : method

Posted 09 February 2009 - 06:56 PM

I will have to eventually calculate a Delivery charge based on what input the user has given ie. 1 for delivery of 150 2 for plating 100.00, 3 none, no charge
Was This Post Helpful? 0
  • +
  • -

#13 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: cannot find symbol symbol : method

Posted 09 February 2009 - 07:37 PM

probably the if else statements are messing things up
Was This Post Helpful? 0
  • +
  • -

#14 tscott  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 370
  • Joined: 30-January 09

Re: cannot find symbol symbol : method

Posted 11 February 2009 - 10:58 AM

Here is the assignment:

A landscape service sells trees that customers can carry home themselves, have delivered, or have delivered and planted. The tree costs per tree are as follows:

Under 3 Ft 39.00
3 - 6 ft 60.00
over 6 ft 79.00

Delivery only: 20.00 per tree with a maximum fee of 100.00 per order
Delivery and planting 50% off the cost of each tree purchased.

Your program is to input the # of trees purchased, their height and delivery. All trees purchased at a time will be of the same height. Ask the user if they want delivery and or planting.

Calculate total tree cost, delivery and planting charges and total all charges.

So that is what I'm trying to do perhaps now you can see if my else and if statements make sense.

Any help is greatly appreciated as I'm learning a lot this community is really great



import java.util.Scanner;

public class Landscape
{
  public static void main (String [] args)
  {
	Scanner keyboard = new Scanner (System.in);
	
	int feet3, feet3_6, feet6, treespurchased, treeheight, delivery, length;
	String input;
	char answer;
	
	System.out.printf("%12s", "Nachbauer Gardens");
	System.out.println ();
	System.out.println("Tree Purchasing System");
	System.out.println("How many trees do you wish to purchase? ");
	treespurchased = keyboard.nextInt();
	
						  input = keyboard.nextLine();
					   
					   if (input.trim().length() > 0)
							 try {
						 treespurchased = Integer.parseInt (input);
					   }
					   catch(NumberFormatException ex) {
					   }
						   else
							 treespurchased = 0;
							 System.out.println("Enter 1 for delivery only, 2 for planting, 3 for none : (1=delivery, 2=planting, 3=none) ");
						   input = keyboard.nextLine();

						   if (input.trim().length() > 0)
							 answer = input.charAt(0);
						   else
							 answer = 3;
					   
	System.out.println("Green Fields Billing Statement");
	System.out.print("\nNUMBER OF TREES PURCHASED " + treespurchased); 
  }
}




OUTPUT:
Nachbauer Gardens
Tree Purchasing System
How many trees do you wish to purchase?
[DrJava Input Box]
Enter 1 for delivery only, 2 for planting, 3 for none : (1=delivery, 2=planting, 3=none)
[DrJava Input Box]
Green Fields Billing Statement

NUMBER OF TREES PURCHASED 0>
Was This Post Helpful? 0
  • +
  • -

#15 tscott  Icon User is offline

  • D.I.C Regular

Reputation: 2
  • View blog
  • Posts: 370
  • Joined: 30-January 09

Re: cannot find symbol symbol : method

Posted 11 February 2009 - 02:25 PM

any help would be greatly appreciated :)

This post has been edited by tnachbauer: 11 February 2009 - 02:26 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2