I am doing a homework assignment. I am confused as to whether or not the stored variables will be saved, so do I create a new line for every item that I will need to recall later? that is what I have done, but do I need too? I have pasted what code have wriiten so far.(below)
Here is what it asks for:
Create a Java program called AverageWeight.java that uses the Scanner class to store the weights, expressed in pounds, of five people in appropriately named variables. The program should calculate the average of these weights and express the average in kilograms (1 pound = .454 kilograms.) The conversion factor should be stored in a named constant. Express the average to the nearest tenth of a kilogram. (Hint:To round a number to the nearest 0.1, add half that, 0.05, to the number, multiply it by 10, convert it to an integer, then divide it by 10.0. For example, 65.78 + .05 becomes 65.83, 65.83 times 10 is 658.3, then 658.3 converted to an integer is 658, and finally 658 divided by 10.0 is 65.8, which is 65.78 rounded to the nearest 0.1.) Output all the original and new information in the command window.
//output all original and new info outputMessage = "Original names and weights in pounds are" allPersons + allWeights "there average weight in pounds equals" averageWeight "." /n; "The total average weight" averageWeight "in kilograms equals" kiloWeight ".";
//print output to screen System.out.println( outputMessage );
} // end main
} // end class
The errors that I am getting:
C:\JavaChp01\AverageWeight.java:18: not a statement String person1; person2; person3; person4; person5; allPersons, outputMessage; ^ C:\JavaChp01\AverageWeight.java:18: not a statement String person1; person2; person3; person4; person5; allPersons, outputMessage; ^ C:\JavaChp01\AverageWeight.java:18: not a statement String person1; person2; person3; person4; person5; allPersons, outputMessage; ^ C:\JavaChp01\AverageWeight.java:18: not a statement String person1; person2; person3; person4; person5; allPersons, outputMessage; ^ C:\JavaChp01\AverageWeight.java:18: not a statement String person1; person2; person3; person4; person5; allPersons, outputMessage; ^ C:\JavaChp01\AverageWeight.java:18: ';' expected String person1; person2; person3; person4; person5; allPersons, outputMessage; ^ C:\JavaChp01\AverageWeight.java:64: ';' expected allPersons = person1, person2, person3, person4, person5; ^ C:\JavaChp01\AverageWeight.java:65: ';' expected allWeight = weight1, weight2, weight3, weight4, weight5; ^ C:\JavaChp01\AverageWeight.java:69: illegal start of expression multiply = (* 10); ^ C:\JavaChp01\AverageWeight.java:69: ')' expected multiply = (* 10); ^ C:\JavaChp01\AverageWeight.java:70: illegal start of expression divide = (/ 10); ^ C:\JavaChp01\AverageWeight.java:70: ')' expected divide = (/ 10); ^ C:\JavaChp01\AverageWeight.java:71: ';' expected kiloWeight = averageWeight * KILO_CONVERSION + ADD_HALF + multiply + convert to integer + divide; ^ C:\JavaChp01\AverageWeight.java:76: ';' expected outputMessage = "Original names and weights in pounds are" allPersons + allWeights "there average weight in pounds equals" averageWeight "." /n; ^ C:\JavaChp01\AverageWeight.java:77: not a statement "The total average weight" averageWeight "in kilograms equals" kiloWeight "."; ^ C:\JavaChp01\AverageWeight.java:77: ';' expected "The total average weight" averageWeight "in kilograms equals" kiloWeight "."; ^ 16 errors
Tool completed with exit code 1
I am stuck! Any advise to help me learn what I am doing wrong would be greatly appreciated. I
change your displayed name to a first name and last name, we have to do this to keep things managable.
Initializer lists are separated by comma, your other init list works. this is why.
We do not do homework, your question is worded fine but be aware so you dont get disappointed
Whenever you get stuck, just fix the first few compiler errors. If that leaves you wondering what to do, just plug the wording of the compiler errors into your book's index and keep reading. That's how I got going,
Sometimes the ^ character from the compiler will be off from where the real error is. Look around the first compiler error, then look in your book.
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."