• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

How to write code properly to calculate cost of carpet and fitting in Java

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I need to write a method calculateCarpetCost() that takes two int arguments representing the width and length in metres of the carpet to be purchased and returns the cost of the carpet as a double. It should first calculate the area of the carpet than multiply this by the price. But I am struggling with how I should start it off. If anyone can help many thanks, I am up late and have a class to teach tomorrow! the things I do for fun!




that looks wrong! if anyone can help many thanks and please no mean comments if you can't help.
 
Marshal
Posts: 66637
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please indent your code correctly; the compiler might let that code pass (actually, it won't) but the bad indentation will confuse you and you won't be able to understand your own work.
Please remind yourself of the structure of a class (your textbook should help you), and about methods, constructors and fields. Give all your fields private access.
 
lilly Potter
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
..These methods should be private. So I need to write a method calculateCarpetCost() that takes two int arguments representing the width and length in metres of the carpet to be purchased and returns the cost of the carpet as a double. It should first calculate the area of the carpet than multiply this by the price. But I am struggling with how I should start it off. If anyone can help many thanks, I am up late and have a class to teach tomorrow! the things I do for fun!


I am not sure if that is according to the brief
 
Carey Brown
Saloon Keeper
Posts: 6469
61
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This method doesn't make use of any member variables so it should be declared 'static'. I'm not sure what else you're asking.
 
Campbell Ritchie
Marshal
Posts: 66637
251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

lilly Potter wrote:..These methods should be private. . . .

I said the fields should be private. What makes you think the methods should be private?
 
Evil is afoot. But this tiny ad is just an ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!