Jasvant Singh Dosanjh Jasvant Singh Dosanjh - 2 months ago 8
Java Question

Variables and Assignment statements

Im having a hard time finishing the problem. I don't know what to do with the int and double values for the calculations. How would i go through with solving them. I am using Jgrasp for my class.
Calculations:

Standard: (20.0 + 40.0 + 5.0 + 60.0 + 30.0 ) / 5

Weighted: 20.0 * 0.15 + 40.0 * 0.1 + 4.0 * 0.2 + 60.0 * 0.25 + 30.0 * 0.3

standard carpet cost: $620.0

weighted carpet cost: $640.0

The Code that I have is

import javax.swing.JOptionPane;

public class Project2A

public static void main(String[] args)
{
int sqftbrm = 20;
int sqftdrm = 40;
int sqfthal = 5;
int sqftgrm = 60;
int sqftstr = 30;

double bf = .15;
double df = .10;
double hf = .20;
double gf = 0.25;
double sf = .30;

char stndCst[] = {"(sqftbrm + sqftdrm +sqfthal + sqftgrm + sqftstr)"/5};
String stdcst = new String(stndCst);
System.out.print(stdcst);

char wtAvg[] = {"sqftbrm*bf" + "sqftdrm*df" + "sqfthal*hf" + "sqftgrm*gf" + "sqftstr*sf");
String wtAverage = new String(wtAvg);
System.out.print(wtAverage);
}

Answer

Outside of the fact that you should probably be using an IDE to easily identify your mistakes.... Semi colon on main method, missing brackets, invalid variable types, etc.

All you have is two arrays with one string value each.

char stndCst[] = {"(sqftbrm + sqftdrm +sqfthal + sqftgrm + sqftstr)"/5};

char wtAvg[] = {"sqftbrm*bf" + "sqftdrm*df" + "sqfthal*hf" + "sqftgrm*gf" + "sqftstr*sf"} ;

If you want to do math with some variables, then remove the quotes.

For example,

double stndCst = (sqftbrm + sqftdrm +sqfthal + sqftgrm + sqftstr) / 5.0;

double wtAvg = sqftbrm*bf + sqftdrm*df + sqfthal*hf + sqftgrm*gf + sqftstr*sf ;
Comments