Public class test03 public void start string result

This preview shows page 3 - 4 out of 4 pages.

public class Test03 { public void start() { String result; result = lots(2 + 1, 3, "3"); (a) result = lots(2 + 1, 3, 4); (b) result = lots(22, "Hi", 4); (c) result = lots(8, 3.4, 'x'); (d) result = lots(22, 1.2, "4"); (e) } } (a), (e) will compile private String lots(int a, double b, String c) { System.out.println(a + b + c); return c + " " + a; } 18 1 2 3 4 5 6 7 8 9 Ex04 What is incorrect with the following method definition? public class Problem1 { public void start() { int b = calculate(3, 1.1); } private int calculate(int a, double b) { double amount = a + b *2; return amount; } } The returnType and the type of value returned do not match.
Image of page 3

Subscribe to view the full document.

CS101 Lecture 7 4 19 1 2 3 4 5 6 7 8 9 10 Ex05 What is incorrect with the following method definition? public class Problem2 { public void start() { int b = calculate(3, 1.1); } private int calculate(int a, double b) { int amount = (int)(a + b * 2); return amount; amount = amount + 2; } } The return statement must be the last statement in the method 1 2 3 4 5 6 7 8 9 10 11 12 13 Ex06 - Give the output public class ProcessUserInput { public void start() { } private String convertAmt ( String name, int amt, double perDollar ) { double amount = amt * perDollar; String result = name + " " + amount; return result; } } NZ$100 = AU$85.0 NZ$200 = Euros 100.0 String amount = convertAmt ( "AU$", 100, 0.85 ); System.out.println("NZ$100 = " + amount); amount = convertAmt ( "Euros", 200, 0.5 ); System.out.println("NZ$200 = " + amount); 21 What you need to know Defining methods: the variable to which the method call is assigned must be of the same type as the return type of the method the method call is replaced by the value which is returned by the method, the parameters must match in order and type, Calling a method: return statement returnType, list of parameters,
Image of page 4
You've reached the end of this preview.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern