Question
Please write the Java code for each of the following exercises in BlueJ. You need to start training on this for the projects. For each
Please write the Java code for each of the following exercises in BlueJ. You need to start training on this for the projects. For each exercise, write a comment before the code stating the exercise number. For example, you should write something like this in your code:
public class ExpressionPalooza {
public static void main(String [] args) {
//Exercise 1
Code to accomplish the tasks in Exercise 1
//Exercise 2
Code to accomplish the tasks in Exercise 2
.
.
}
}
Make sure you are using the appropriate indentation and styling conventions
Exercise 1
In BlueJ, create a new project called Exec1 Create a class in that project called ExpressionPalooza Write the main method for that class In main , declare an integer variable named size In a separate assignment statement, assign the value 348 to size Print out the value as follows: The size is 348 Compile the code and run the method.
Exercise 2
After printing the original value of size, assign it a new value of 876 Then print it as follows: The size is now 876. Make sure you include a period at the end of the output What happened to the original value of size? Answer this question using a comment
Exercise 3
Declare another integer variable named result Using a separate assignment statement, compute the value 8642 times 4 minus 57 and store it in the variable named result Print the result: The result is xxx
Exercise 4
Now copy and paste the last assignment and println statements. Change the assignment statement to force the subtraction to happen first. Change the output to: The result is now xxx
Exercise 5
Compute and print the following values -- do the computation right in the println statement. Do these one at a time (edit, compile, run) and predict the results before you run the method! 15 / 5 is xxx
15 / 2 is xxx
15 / 5.0 is xxx
15 / 2.0 is xxx
15.0 / 2 is xxx
Again, compute and print the following values. Do these one at a time and predict the results each time! 14 % 5 is xxx
15 % 5 is xxx
32 % 5 is xxx
178 % 10 is xxx
5936 % 1000 is xxx
Exercise 6
Declare an integer variable named height and initialize it to 70 in the declaration. This is the height of a person in inches. Compute and print the height of the person as follows: That person is xxx feet, xxx inches tall.
Exercise 7
Declare an integer variable named radius and initialize it to 12 in the declaration. Declare a double variable named circumference. Use an assignment statement to compute the circumference of a circle with the given radius (2 times pi times the radius). Use the Math.PI constant in the calculation. Print the result: The circumference of a circle with radius xxx is xxx
Exercise 8
Using the same radius, compute the area of the circle and store it in a double variable named area The formula for the area of a circle is pi times the radius squared. Use the Math.pow method to square the radius. Print the result : The area of a circle with radius xxx is xxx
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started