1. (5 pts) Given an integer array: int A[] = new int[10]; It is easy to...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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); 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); 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. 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. 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. (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. (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 7.4) 7.5) public static void printx(int i) { if(i 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? 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? 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 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 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 } public void setSalary(double x) { } public double getSalary() { } // blank5: setup salary // blank6: get salary } public void setSalary(double x) { } public double getSalary() { } // blank5: setup salary // blank6: get salary
Expert Answer:
Related Book For
Financial Accounting and Reporting a Global Perspective
ISBN: 978-1408076866
4th edition
Authors: Michel Lebas, Herve Stolowy, Yuan Ding
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
Heights Academy, a private school, serves 500 students: 200 in the middle school (Grades 6 to 8) and 300 in the high school (Grades 9 to 12). Each school group has its own assistant principal, and...
-
Most cities are served by only one cable Company. How might this monopoly power affect prices and service? What should the government do, if anything?
-
In Exercises determine whether the sequence with the given nth term is monotonic and whether it is bounded. Use a graphing utility to confirm your results. a n ne-n/2
-
Gilead is a large drug producer, with a majority of its prescription drug product sales occurring in the United States. Gilead produces anti-HIV drug therapies, including the drugs Atripla, Truvada,...
-
Francis Corporation purchased an asset at a cost of $50,000 on March 1, 2012. The asset has a useful life of 8 years and a salvage value of $4,000. For tax purposes, the MACRS class life is 5 years....
-
Discuss each of the following terms: (a) data (b) database (c) database management system (d) database application program (e) data independence (f) security (g) integrity (h) views 2. What is...
-
Nautilus Resources is investing in a new heavy oil upgrader in northern Alberta. Nautilus has hired Rite Build Contractors to construct the facilities. The contract price is $3,600 million to be...
-
Prove that the n = 1 (ground state) and n = 3 (second excited state) wavefunction for a 1-D particle in a box are orthogonal.
-
What is the importance of the agency/client relationship and how do you maintain a good relationship with your clients in an PR agency.
-
A 9.3m2 wall consists of 10cm of red brick (k=0.66 W/m.K), 2.5cm of pine (k=0.1W/m.K), and 1.2cm of plasterboard (k=0.52 W/m.K). The internal and external film coefficients are 9.38W/m2.K and 34.1...
-
As an employer what will you do if a customer gives a compliment about your employee and the service of your restaurant and bar? Explain in detail.
-
What makes a presenter's persona successful? What makes you trust or mistrust a speaker? What makes you connect or disconnect?
-
Griffin separates theories into two "camps": objective and interpretive. Where do you feel more at home? Why?
-
(a) Write a pseudocode for your program. Exercise 2 [Find & Generate] Please answer the following: Which variables do you need? ) Which variables do you use for input? ) Which types do you use for...
-
What are some of the features of the Unified Process (UP)?
-
Haeffner PLC is an accounting firm. Some of its clients face the following situations. For each, it is assumed that a reliable estimate can be made of any outflows expected: 1. On 9 December X1 the...
-
Multiple Choice Questions 1. In a capital increase, the difference between the price paid by the buyer for a companys common share and the par value of each share can be called (several possible...
-
In the following list of qualitative characteristics of an accounting signal, choose the two that seem to you to be the most important ones (Explain your choice): (a) Verifiable (b) Fair and true (c)...
-
The Captain of an interstellar photon-rocket spaceship wishes to maintain a constant acceleration \(a\) in the instantaneous rest-frame of the ship, since that would provide a constant effective...
-
Prove from Fermat's Principle that the angles of incidence and reflection are equal for light bouncing off a mirror. Use neither algebra nor calculus in your proof! (Hint: The result was proven by...
-
An ideal converging lens focusses light from a point object onto a point image. Consider only rays that are straight lines except when crossing an air-glass boundary, such as those shown in the...
Study smarter with the SolutionInn App