Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. (5 pts) Given an integer array: int A[] = new int[10]; It is easy to print values of array elements from the first
1. (5 pts) Given an integer array: int A[] = new int[10]; It is easy to print values of array elements from the first one to the last one by using a for loop. Can you use a for loop to print those values from the LAST array element to the FIRST array element? (i.e. print values in the reversed order). 2. (2pts) What is a recursive method? 3. (2pts) What are important factors when designing a recursive method? 4. (2pts) is the following method recursive method? If it is, are there any design flaws? What are those flaws? public static void ABC(int x) { System.out.println(x); } ABC(x); 5. (4 pts) Finish the method below. It converts a Celsius temperature (which is passed as a method parameter "celsius") to a Fahrenheit temperature. The method returns the Fahrenheit result in floating point number. The conversion formula is: F = (9.0/5.0) X C + 32 public static } cToF(double celsius) { 6. Review our course example Dice.java (in Week13&14 folder) and answer the following questions. 6.1. (2pts) Have we defined any member variables in the Dice class? If yes, what are they? 6.2. (2pts) What modifiers we used to define those variables? (public? private?) Why we use that specific modifier? 6.3. (2pts) Have we defined any member methods in the Dice class? If yes, what are they? 6.4. (2pts) How would you call those methods? Please write down a piece of code. 7. (10 pts) Read code parts below and answer the questions. Each code part is independent. 7.1) public static int X(int a[]) { int sum = 0; for(int w = 0; w 7.4) 7.5) public static void printx(int i) { if(i 8. Read the code below and answer the questions (4 pts): public class Counter { private static int count = 0; private int self; public Counter() { ++count; self = 0; } public Counter(int i) { ++count; self = i; } public void addMe(int i) { self = self + i; } public void runMe() { System.out.println("the System.out.println("the } } public static void main(String[] args) { Counter a = new Counter(); Counter b = new Counter(100); a.addMe(3); b.addMe(5); value of count is " + count); value of self is "+self); a.runMe(); b.runMe(); } 8.1) What is the different between member variable count and self? 8.2) What will be printed when the program is executed? 9. The code part below tries to define an Employee class. Obviously, class Employee provides ways to set/get names, SSN, and salary. Please fill out the blanks below. (The comment at the end of each blank line indicates the expected behavior the line should have. There is only one statement at each blank line) (12 pts). Note: there are 6 blanks in this question. public class Employee { private String firstName; private String lastName; private String social; private double monthlySalary; public Employee(String first, String last, String ssn) { firstName = first; lastName = last; } public void setFirstName(String first) { firstName = first; } public void setLastName(String last) { } public String getName() { } monthlySalary = 0; } // blank1: setup SSN } public void setSSN(String ssn) { public String getSSN() { // blank2: setup last name return (firstName + " " + lastName); // blank3: setup SSN // blank4: get SSN } public void setSalary(double x) { } public double getSalary() { } // blank5: setup salary // blank6: get salary
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