Home of the Ultimate Xbox 360 Modding Tool, Horizon. XboxMB.com is a community of Xbox 360 gamers and modders who share Tutorials, News, Reviews, and other resources. Xbox Message Boards is free to sign up and use, so what are you waiting for? Register Now!
Say that you are interested in the value of the quadradic...
3X 2 -8X + 4
...for several values of X. Write a program that has a double precision variable X. Assign a value to it. Write statement that computes a value for the quadradic and stores the result in another double precision variable. Finally write out the result, something like:
At X = 4.0 the value is 20.0
Run the program with several values for X (edit the program for each value of X) and examine the result. Use values with decimal points, large values, small values, negative values, and zero. Solve the equation with paper and pencil (use the quadradic formula.) The quadradic should evaluate to zero at X = 2.0 and at X = 2/3. Try these values for X. Are the results exactly correct?
Do not write the code, if you do it for me, then I won't learn anything forcing me to go back to my teacher for more help . Just try to explain it to me step by step. Thanks , my grade is a 100% in Java class ,I'm trying to keep it!
1. It's asking you to code a program that executes the following function: 3X 2 -8X + 4
"I assume that is: ((3.0*x) * 2.0 - (8.0*x) + 4.0)" //Put .0 to make all numbers double.
2. You must create a double variable and store the number you want to use for x.
("like double x = 3.0"
3. Then you need to create a new double variable which will hold the result of the function.
(like double result = "((3.0*x) * 2.0 - (8.0*x) + 4.0)"
4. Then you just need to display the result.
"like System.out.println("At x = " + x + " the value is: " + result)"
1. It's asking you to code a program that executes the following function: 3X 2 -8X + 4
"I assume that is: ((3.0*x) * 2.0 - (8.0*x) + 4.0)" //Put .0 to make all numbers double.
2. You must create a double variable and store the number you want to use for x.
("like double x = 3.0"
3. Then you need to create a new double variable which will hold the result of the function.
(like double result = "((3.0*x) * 2.0 - (8.0*x) + 4.0)"
4. Then you just need to display the result.
"like System.out.println("At x = " + x + " the value is: " + result)"
Quote:
Originally Posted by SPEED
Initialize x as a double equal to 4.0
Initialize result as a double equal to the math, which you need to figure out how to do (or not, since Seth gave it to you)
For example: double result = 3*(xval);
That would set result = 12.0 if xval = 4.0
Then just put it all together.. System.out.print("At X = "+xval+", the value is "+result);
My next task.
Modify the program in exercise 2 so that one run of the program will evaluate and write out the value of the quadratic for three different values of X: 0.0, 2.0, and 4.0 (or any three values of your choice.)
Write the program using the following equation.
.5x2 - 3x - 14
In writing the program make use of your editor's "copy" and "paste" functions to avoid re-typing similar lines.
Modify the program in exercise 2 so that one run of the program will evaluate and write out the value of the quadratic for three different values of X: 0.0, 2.0, and 4.0 (or any three values of your choice.)
Write the program using the following equation.
.5x2 - 3x - 14
In writing the program make use of your editor's "copy" and "paste" functions to avoid re-typing similar lines.
Since he just wants you to copy/paste it, just do it like so:
double x1 = 0.0; //you really might as well make these int x1=0; etc
double x2 = 2.0;
double x3 = 4.0;
I don't understand this. I use int 0 for this correct?
Write a program that averages the rain fall for three months, April, May, and June. Declare and initialize a variable to the rain fall for each month. Compute the average, and write out the results, something like:
Rainfall for April: 12
Rainfall for May : 14
Rainfall for June: 8
Average rainfall: 11.333333
To get the numerical values to line up use the tabulation character '\t' as part of the character string in the output statements. Check that your program prints the correct results. There is a beginner's error lurking in this program too! Did you fall victim to it?
int rainApril = 12;
int rainMay = 14;
int rainJune = 8;
double rainAvg = (double)(rainApril+rainMay+rainJune)/3; //cast as double to return correct results, not casting results in a rounded number
System.out.println("\tRainfall for April: "+rainApril);
System.out.println("\tRainfall for May: "+rainMay);
System.out.println("\tRainfall for June: "+rainJune);
System.out.println("\tAverage Rainfall: "+rainAvg);
int rainApril = 12;
int rainMay = 14;
int rainJune = 8;
double rainAvg = (double)(rainApril+rainMay+rainJune)/3; //cast as double to return correct results, not casting results in a rounded number
System.out.println("\tRainfall for April: "+rainApril);
System.out.println("\tRainfall for May: "+rainMay);
System.out.println("\tRainfall for June: "+rainJune);
System.out.println("\tAverage Rainfall: "+rainAvg);
Quote:
Originally Posted by Wookie
Do not write the code, if you do it for me, then I won't learn anything forcing me to go back to my teacher for more help . Just try to explain it to me step by step. Thanks , my grade is a 100% in Java class ,I'm trying to keep it!
Not sure if you were giving him the code, or not.
So I copied that.
Not sure if you were giving him the code, or not.
So I copied that.
I feel like **** right now and don't feel like taking the time to explain everything, so I just gave him the code and commented what he should need to know. It's a basic program, so he should be able to read my code and learn from it.