473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Error messages! area(double, double) cannot be applied to ( )

I keep getting these error messages:

area(double,double) in Rectangle cannot be applied to ()
return "Area: " + Rectangle.area() + "\tCircumference: " + Rectangle.perimeter(); ^

perimeter(double,double) in Rectangle cannot be applied to ()
return "Area: " + Rectangle.area() + "\tCircumference: " + Rectangle.perimeter();
^
setSides(double,double) in Rectangle cannot be applied to (double)
R.setSides(input.nextDouble());
^
3 errors

Tool completed with exit code 1

Can anybody tell me why it is doing this? Thanks in advance!

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class Rectangle
  4. {
  5.     public double length;
  6.     public double width;
  7.  
  8.     public Rectangle()
  9.     {
  10.         length = 0;
  11.         width = 0;
  12.     }
  13.  
  14.     public double getSides()
  15.     {
  16.         return length;
  17.         return width;
  18.     }
  19.  
  20.     public void setSides(double length, double width)
  21.     {
  22.         this.length = length;
  23.         this.width = width;
  24.     }
  25.  
  26.     public double area(double length, double width)
  27.     {
  28.         double area = length * width;
  29.  
  30.         return area;
  31.     }
  32.  
  33.     public double perimeter(double length, double width)
  34.     {
  35.         double perimeter = (length * 2) + (width * 2);
  36.  
  37.         return perimeter;
  38.     }
  39.  
  40.     public String toString()
  41.     {
  42.         return "Area: " + Rectangle.area() + "\tCircumference: " + Rectangle.perimeter();
  43.     }
  44.  
  45.     public static void main(String [] args)
  46.     {
  47.         Rectangle R = new Rectangle();
  48.  
  49.         Scanner input = new Scanner(System.in);
  50.  
  51.         System.out.println("Enter radius: ");
  52.  
  53.         R.setSides(input.nextDouble());
  54.  
  55.         System.out.println(R.toString());
  56.     }
  57. }
  58.  
Oct 27 '06 #1
1 8192
Ganon11
3,652 Expert 2GB
I keep getting these error messages:

area(double,double) in Rectangle cannot be applied to ()
return "Area: " + Rectangle.area() + "\tCircumference: " + Rectangle.perimeter(); ^

perimeter(double,double) in Rectangle cannot be applied to ()
return "Area: " + Rectangle.area() + "\tCircumference: " + Rectangle.perimeter();
^
setSides(double,double) in Rectangle cannot be applied to (double)
R.setSides(input.nextDouble());
^
3 errors

Tool completed with exit code 1

Can anybody tell me why it is doing this? Thanks in advance!

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class Rectangle
  4. {
  5.     public double length;
  6.     public double width;
  7.  
  8.     public Rectangle()
  9.     {
  10.         length = 0;
  11.         width = 0;
  12.     }
  13.  
  14.     public double getSides()
  15.     {
  16.         return length;
  17.         return width;
  18.     }
  19.  
  20.     public void setSides(double length, double width)
  21.     {
  22.         this.length = length;
  23.         this.width = width;
  24.     }
  25.  
  26.     public double area(double length, double width)
  27.     {
  28.         double area = length * width;
  29.  
  30.         return area;
  31.     }
  32.  
  33.     public double perimeter(double length, double width)
  34.     {
  35.         double perimeter = (length * 2) + (width * 2);
  36.  
  37.         return perimeter;
  38.     }
  39.  
  40.     public String toString()
  41.     {
  42.         return "Area: " + Rectangle.area() + "\tCircumference: " + Rectangle.perimeter();
  43.     }
  44.  
  45.     public static void main(String [] args)
  46.     {
  47.         Rectangle R = new Rectangle();
  48.  
  49.         Scanner input = new Scanner(System.in);
  50.  
  51.         System.out.println("Enter radius: ");
  52.  
  53.         R.setSides(input.nextDouble());
  54.  
  55.         System.out.println(R.toString());
  56.     }
  57. }
  58.  
Simple. The way you have defined area and perimeter, you want the function call to pass two variables. Instead, why not just use the length and width inside the class? In other words, rename your functions

Expand|Select|Wrap|Line Numbers
  1. public double area() {...}
  2. public double perimeter() {...}
The code inside each of these functions does not need to be altered.

For set sides, your function header is correct - you want to have two sizes to define how large the rectangle is. Your call, however (R.setSides(input.nextDouble())) only sends 1 double variable. Try R.setSides(input.nextDouble(), input.nextDouble()), and this should work.

Finally, I see one more error in your code - namely, getSides(). You cannot retrun two values in a function. This will not give you an error explicitly, but the function will only return length. Any function automatically exits after the very first return statement. Thus, your code to return width is never touched - obviously, an error in logic.

Try splitting getSides into two functions: double getLength() and double getWidth(). You will have to call both functions instead of only one, but this is the only way to get two seperate variables in Java (that I know of).
Oct 28 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Sorisio, Chris | last post by:
Ladies and gentlemen, I've imported some data from a MySQL database into a Python dictionary. I'm attempting to tidy up the date fields, but I'm receiving a 'mx.DateTime.Error: cannot convert...
8
by: Kragen Sitaker | last post by:
ERROR: Cannot insert a duplicate key into unique index pg_class_relname_nsp_index We've been getting this error in our application every once in a while --- typically once an hour to once a day,...
0
by: Matthew Louden | last post by:
I am trying to implement the sort event in data grid. I set the data grid's AllowSorting property = True. I implement the following code that should be the event will fire when the user click any...
5
by: Nathan Sokalski | last post by:
When running a page I am working on, I recieve the following error: Cannot use a leading .. to exit above the top directory. I suspect this has something to do with the problem I posted in a...
1
by: Vycka | last post by:
Hello, There is a enterprise web application that is based on asp.net technologies and works on Microsoft IIS. The total number of users is 850. When the load of system gets very high, the...
2
by: moondaddy | last post by:
I have a simple sample site I'm building in asp.net 2.0. I created a master page and a default.aspx content page in the project's root directory. Then I created a subfolder called content and...
10
by: antonis | last post by:
When I restarting my pc a warning appears with the error cannot find the file C:\winnt\system32\1.tmp Please advice me how can I solve this problem Thanks
2
by: fniles | last post by:
I am using VB.NET 2005 and MS Access. I use OLEDbCommand ExecuteNonQuery to delete a record from a database. Whenever the program gets a message, it creates a new thread to process that message....
0
by: SMH | last post by:
Hi All, I am currently learning .Net 2, studying for 70-528. I've hit a bit of a brick wall with DataColumn.Expression. As I understand it, this can be used to (For example) concatenate two...
2
by: sam.barker0 | last post by:
Hi , I am having 3 functions.When I step through when func b returns to funca.it throws an error "cannot find function bounds" funca() { .... ... funcb(); }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.