Click here to Skip to main content
15,887,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi ! so i have this assignment where i have to create a Wall paint calculator and I am having some difficulties coding it..









Java
import java.util.Scanner;

class ProgramA{
  public static void main(String [] args)
          {
System.out.println("Welcome To Wall Paint Cost Calculator");
int length;
int width;
int height;
int cost;

Scanner keyboard = new Scanner (System.in);

System.out.println("Please enter below your room length in meters ");
length = keyboard.nextInt ();

System.out.println("Please enter below your room width in meters ");
width = keyboard.nextInt ();

System.out.println("Please enter below your room width in meters ");
height = keyboard.nextInt();

System.out.println("Your total area is:");
cost = length + width * height * 4 ;

System.out.println(cost);

}
}





The problem with this is code is that when i launch the program and type in my numbers for example lets say length is : 5 + width : 6 * height : 3 then * 4 I am always getting 77.

Please help thanks!

What I have tried:

import java.util.Scanner;

class ProgramA{
public static void main(String [] args)
{
System.out.println("Welcome To Wall Paint Cost Calculator");
int length;
int width;
int height;
int cost;

Scanner keyboard = new Scanner (System.in);

System.out.println("Please enter below your room length in meters ");
length = keyboard.nextInt ();

System.out.println("Please enter below your room width in meters ");
width = keyboard.nextInt ();

System.out.println("Please enter below your room width in meters ");
height = keyboard.nextInt();

System.out.println("Your total area is:");
cost = length + width ;

System.out.println(cost);

}
}
Posted
Updated 14-Feb-17 10:11am
v2

Quote:
The problem with this is code is that when i launch the program and type in my numbers for example lets say length is : 5 + width : 6 * height : 3 then * 4 I am always getting 77.

Not sure it is a problem. When I do 5+6*3*4, I get 77

When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. It allow you to execute lines 1 by 1 and to inspect variables as it execute, it is an incredible learning tool.

Debugger - Wikipedia, the free encyclopedia[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to.
 
Share this answer
 
Height * Width * 2 gives you the area for two walls.

Height * Length * 2 gives the area of the two other walls

Add the two areas to get the total.

Walls of course may be the same length but doing it this way allows for different length walls.

5 * 3 = 15 * 2 = 30
6 * 3 = 18 * 2 = 36

Total 66.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900