## Suppose that a program has been written that produces the output shown

Suppose that a program has been written that produces the output shown in the previous problem. Now the author wants the program to be scalable using a class constant called SIZEThe previous output used a constant height of 6, since there were 6 lines. The following is the output for a constant height of 4. Create a new table that shows the expressions for the character counts at this new size of 4, and compare these tables to figure out the expressions for any size using the SIZE constant.

Data from Previous Problem

Write a table that determines the expressions for the number of each type of character on each of the 6 lines in the following output.

## Consider the following program, saved into a file named Example.java:What would happen

Consider the following program, saved into a file named Example.java:

What would happen if each of the following changes were made to the Example program? For example, would there be no effect, a syntax error, or a different program output? Treat each change independently of the others.

a. Change line 1 to: public class Demonstration

b. Change line 9 to: public static void MAIN(String[] args) {

c. Insert a new line after line 11 that reads:

System.out.println();

d. Change line 2 to: public static void printMessage() {

e. Change line 2 to: public static void showMessage() { and change lines 11 and 12 to: showMessage();

f. Replace lines 3–4 with: System.out.println( ” The first rule of Java Club is, ” );

## Trace the evaluation of the following expressions, and give their resulting values:a.

Trace the evaluation of the following expressions, and give their resulting values:

a. 2 + 3 * 4 − 6

b. 14 / 7 * 2 + 30 / 5 + 1

c. (12 + 3) / 4 * 2

d. (238 % 10 + 3) % 7

e. (18 − 7) * (43 % 10)

f. 2 + 19 % 5 − (11 * (5 / 2))

g. 813 % 100 / 3 + 2.4

h. 26 % 10 % 4 * 3

i. 22 + 4 * 2

j. 23 % 8 % 3

k. 12 − 2 − 3

l. 6/2 + 7/3

m. 6 * 7 % 4

n. 3 * 4 + 2 * 3

o. 177 % 100 % 10 / 2

p. 89 % (5 + 5) % 5

q. 392 / 10 % 10 / 2

r. 8 * 2 − 7 / 4

s. 37 % 20 % 3 * 4

t. 17 % 10 / 4

## Modify your pow method from Exercise 5 to make a new method

Modify your pow method from Exercise 5 to make a new method called pow2 that uses the type double for the first parameter and that works correctly for negative numbers. For example, the call pow2(–4.0, 3) should return –4.0 * –4.0 * –4.0 , or –64.0 , and the call pow2(4.0, –2) should return 1 / 16, or 0.0625.

Data from Exercise 5

Write a method called pow that accepts a base and an exponent as parameters and returns the base raised to the given power. For example, the call pow(3, 4) should return 3 * 3 * 3 * 3, or 81. Assume that the base and exponent are nonnegative.

## Write a method called quadrant that accepts as parameters a pair of

Write a method called quadrant that accepts as parameters a pair of double values representing an (x, y) point and returns the quadrant number for that point. Recall that quadrants are numbered as integers from 1 to 4 with the upper-right quadrant numbered 1 and the subsequent quadrants numbered in a counterclockwise fashion:

Notice that the quadrant is determined by whether the x and y coordinates are positive or negative numbers. Return 0 if the point lies on the x- or -axis. For example, the call of quadrant(-2.3, 3.5) should return 2 and the call of quadrant(4.5, -4.5) should return 4.

## Consider a method printTriangleType that accepts three integer arguments representing the lengths

Consider a method printTriangleType that accepts three integer arguments representing the lengths of the sides of a triangle and prints the type of triangle that these sides form. The three types are equilateral, isosceles, and scalene. An equilateral triangle has three sides of the same length, an isosceles triangle has two sides that are the same length, and a scalene triangle has three sides of different lengths.

However, certain integer values (or combinations of values) would be illegal and could not represent the sides of an actual triangle. What are these values? How would you describe the precondition(s) of the printTriangleType method?

## Write a method called evenSumMax that accepts a Scanner for the console

Write a method called evenSumMax that accepts a Scanner for the console as a parameter. The method should prompt the user for a number of integers, then prompt the integer that many times. Once the user has entered all the integers, the method should print the sum of all the even numbers the user typed, along with the largest even number typed. You may assume that the user will type at least one nonnegative even integer. Here is an example dialogue:

How many integers? 4

Next integer? 2

Next integer? 9

Next integer? 18

Next integer? 4

Even sum = 24, Even max = 18

## Write a method called printGPA that accepts a Scanner for the console

Write a method called printGPA that accepts a Scanner for the console as a parameter and calculates a student’s grade point average. The user will type a line of input containing the student’s name, then a number that represents the number of scores, followed by that many integer scores. Here are two example dialogues:

Enter a student record: Maria 5 72 91 84 89 78

Enter a student record: Jordan 4 86 71 62 90

Maria’s grade is 82.8 because her average of

(72 + 91 + 84 + 89 + 78)/5 equals 82.8.

## Write the method called printTriangleType referred to in Self-Check Problem 25. This

Write the method called printTriangleType referred to in Self-Check Problem 25. This method accepts three integer arguments representing the lengths of the sides of a triangle and prints the type of triangle that these sides form. Here are some sample calls to printTriangleType:

printTriangleType(5, 7, 7);

printTriangleType(6, 6, 6);

printTriangleType(5, 7, 8);

printTriangleType(2, 18, 2);

The output produced by these calls should be

isosceles
equilateral

scalene
isosceles

Your method should throw an IllegalArgumentException if passed invalid values, such as ones where one side’s length is longer than the sum of the other two, which is impossible in a triangle. For example, the call of printTriangleType(2, 18, 2); should throw an exception.

Data from Self check Problem 25

Consider a method printTriangleType that accepts three integer arguments representing the lengths of the sides of a triangle and prints the type of triangle that these sides form. The three types are equilateral, isosceles, and scalene. An equilateral triangle has three sides of the same length, an isosceles triangle has two sides that are the same length, and a scalene triangle has three sides of different lengths.

However, certain integer values (or combinations of values) would be illegal and could not represent the sides of an actual triangle. What are these values? How would you describe the precondition(s) of the printTriangleType method?