• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What am I doing wrong?

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to my professor he says that I am not correctly calculating the floor and wall space correctly. Please help I am not sure what I am doing wrong. Thanks!


 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am not correctly calculating the floor and wall space correctly.


What values does the program calculate?  What are the correct values?  

Do you have the formulas for doing the calculations?  Can you get them from your professor?


One big problem I see with the code is the 2 and 3 letter variable names which make the code very hard to read and understand.  Variable names should describe the values that they hold.
 
Saloon Keeper
Posts: 10739
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I find this suspect

On line 1 you have floortype * floorspace, and on line 3 you have hardwood * floorspace. These don't seem consistent.
I would think that your floor type is a choice of menu options 1...n and doesn't necessarily represent the cost.
Your prompt for floortype doesn't give the user any clue as to what the possible options are and what they mean.
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
These are the values that are suppose to be inputted.  (Below.) My professor said that the results 723.77 for the wall and 762.96 for the flooring. However my answers were completely different as I got 462 for the wall and 120 for the floor. If you could review these results please let me know if I am correct or wrong. Please let me know if my code HAS ERROS. Thanks!

o Room is 12.75 feet long, 11.25 feet wide, and 12 feet high
o Door is 1.95 feet wide by 10 feet high
o Window 1 is 2.5 feet wide by 5 feet high
o Window 2 is 6.8 feet wide by 7.2 feet high
o Bookshelf is 8 feet long by 6 feet high by 3 feet deep
o Cost per square foot for painting is $0.95
o Cost per square foot for carpeting is $1.25



 
Marshal
Posts: 8865
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junaid Mahmud wrote:my answers were completely different
...
Please let me know if my code HAS ERROS.

Most likely.

I'd suggest you to name variables properly, so you'd understand what each of them represents, and could check if you got formulae correct. For instance, what variable 'bookshlefp' (<- I copied/pasted) represents? lb * hb (<- how about those? what they represent?). No worries, I'd get confused too with such naming.

Can you write down the formulas you have been given how to perform the calculations?
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

results 723.77 for the wall and 762.96 for the flooring.


Take a paper and pencil and work out the values manually.
Copy and paste your computations here so we can see what you have done to find the values.

When you can manually compute the correct values, then work on fixing the code to compute the correct values.
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We did not receive any formulas
 
Liutauras Vilda
Marshal
Posts: 8865
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junaid Mahmud wrote:We did not receive any formulas


double door = (ld - hd);


Please explain what this formula calculates?
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would guess most of the "formulas" are pretty standard:
area = width * height
cost = square feet * $/square foot
etc
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:

Junaid Mahmud wrote:We did not receive any formulas


double door = (ld - hd);


Please explain what this formula calculates?



It finds the area of the door
 
Liutauras Vilda
Marshal
Posts: 8865
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junaid Mahmud wrote:double door = (ld - hd);

It finds the area of the door



Junaid Mahmud wrote:double window1 = (lw1 * hw1);


Please tell what this formula then does?
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:

Junaid Mahmud wrote:double door = (ld - hd);

It finds the area of the door



Junaid Mahmud wrote:double window1 = (lw1 * hw1);


Please tell what this formula then does?



It will find the area of window 1
 
Liutauras Vilda
Marshal
Posts: 8865
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, subtracting height from length gives you an area as well as length multiplied by height gives an area?
 
Norm Radder
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you write the the numbers and compute the two values to show what formulas are needed?
 Since you know what the answers should be you should be able to manipulate the numbers to get the answers you were given.
 
Junaid Mahmud
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey I'm back! I had figured out what my mistake was. My professor assigned a new assignment in which I have to build off my previous assignment. In this new assignment I have to as the user the number of doors, windows, and bookshelves and then the length width and height depending on the item and number of items. This all has to be done in loops which I suck at and have no idea where to start. Thanks! here is the code.




   
 
Carey Brown
Saloon Keeper
Posts: 10739
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might want to consider refactoring your code to make it more object oriented. Looking for nouns gives us a hint at what classes we might need.

  • Material with a field for name and cost.
  • An abstract Item with fields for name, length, width, and height and methods getWallArea() and getFloorArea().

  • Subclasses of Item:
  • Room
  • Shelf
  • Window

  • From here, making a List<Item> can hold any number and combination of Rooms, Shelves, and Windows.

    Your main user input loop then begins to look something like:
     
    Friends help you move. Good friends help you move bodies. This tiny ad will help:
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic