1. Write if/else statements that are the functional equivalent of the following statement using the conditional operator:...
Question:
1. Write if/else statements that are the functional equivalent of the following statement using the conditional operator:
message = (grade >= 60) ? “You are Passing.” : “You are Failing”;
2. Write a boolean expression involving a variable with the identifier speed that evaluates to true only when speed is less than 35 or greater than 75 and assign that result to a boolean variable that you declare.
3. Suppose you are trying to test a method that determines whether a person is eligible for a special tax credit based on their age being greater than or equal to 65 and living alone. Propose a series of unit tests that would test whether such a method functions correctly. For each test, you should specify the value for age (an int) and the value for living alone (a boolean) and what your expected value (a boolean) for the method should be. For this particular case you should not allow people to be below 1 year of age or greater than 130 years of age.
Note: You do not actually need to write the unit tests or any code at all. You just need to indicate what you would use for input values and what output you expect to receive based on that input.
4. After executing the following code, the value of the variable result is a number larger than 1. What you say about the values of the other variables in the statement?
int result = tardisInsideVolume.compareTo(tardisOutsideVolume);
5. What is wrong with the following code? How would you fix it? Note, you can assume any variables that are used have been properly declared and initialized.
boolean b = 75 < numberOfWins < 100;
6. What is the result of the boolean variable b1 after executing the following statements?
Student student1 = new Student(“Bob”, 12345);
Student student2 = new Student(“Bob”, 12345);
boolean b1 = student1 == student2;
7. Suppose you need to write some code to process user input. Which type of loop would you use and why do you think it is the best choice?
8.Describe what the following Java statement does in plain language.
inRange = age >= 25 && age <= 32;
9 .When would you want to use a do while loop instead of a while loop?
10. What is the output of the following Java code:
for (int i = 0; i <= 3; i++){
for (int j = 5; j > i; j--){
System.out.print(j + “ ”);
}
System.out.println();
}
11. Write a while loop that allows a program to read type-safe int values. You can assume that a Scanner object with the identifier scan has been declared and properly initialized for you.
12. Write some java code that will print out the academic standing of a student based on the GPA for their previous semester which is stored in a variable with the identifier recentGPA. If the student has a GPA below 1.0 the message "Academic Suspension" should be output. Between 1.0 and 2.0, the message "Academic Probation" should be output. Above 2.0 should output the message "Good Standing".
13. Write a draw method for the Ball class that will allow a Ball object to draw itself. You may assume the class has the following instance variables: xPos, yPos, diameter, color. The first three are of type int, and the last is of type Color.
14. How many iterations (if any) will each of the following example for loops make? .
1) for (int a = 0; a < 12; a++) {}
2) for (int b = 7; b >= 0; b--) {}
3) for (int c = 5; c <= 20; c+=5) {}
15. Suppose you are writing a GUI application and have created a subclass of the JFrame class that contains a JTextField object with the identifier numberOfDonuts. Write some Java code that will allow you to get the value a user has entered in that field and convert it to an int. You do not need to worry about checking if the value is a number first.
16. Describe what is meant by the term infinite loop.
17. Write a mutator method for an instance variable of type int with the identifier employeeID. Your mutator method should not allow values larger 9999 or less than 0 and automatically adjust values outside of that range to the appropriate max or minimum value.
18. Write a unit test (both method header and body) for a static method of the Conversion class called feetToInches. The method takes a single argument of type int which represents for the number of feet to be converted. You can assume that there are 12 inches in 1 foot.
19. Write some Java code involving if, else if, and else statements that are equivalent to the following switch case:
switch(number) {
case 2:
System.out.println("Second place");
case 1:
System.out.println("First place");
System.out.println("Top 2 finish!");
break;
case 3:
System.out.println("Third place");
break;
default:
System.out.println("Also ran");
}
20. Write some Java code that will generate random numbers 1 – 10 inclusive until it generates the number 10. Your code should also keep a count of how many numbers have been generated. You can assume that a Random object with the identifier rand has already been declared and instantiated for you to use in your solution.
21. Override the equals method for the JediMaster class. The JediMaster class has two fields that should be considered when testing for equality: one of type String with the identifier name, and the other of type int with the identifier midichlorianCount.
Applied Regression Analysis and Other Multivariable Methods
ISBN: 978-1285051086
5th edition
Authors: David G. Kleinbaum, Lawrence L. Kupper, Azhar Nizam, Eli S. Rosenberg