• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76887
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 9742
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
lilly Rankine
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9742
80
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 76887
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Won't you be my neighbor? - Fred Rogers. tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic