public static final int INCHES_PER_FOOT = 12;
INCHES_PER_FOOT
is defined in a class called Measurement, what code would you use to access it in your class?Measurement.INCHES_PER_FOOT
Why would someone use a static constant?
Record your participation in Piazza clicker question Lesson19 Q1
public class Invoice { //define static constant here ... }
public class Store { public static void main(String[] args) { ... //how do you access the tax rate from the Invoice class? double total = cost + cost * ???; ... } }
Math.pow(...) Math.round(...) Character.isLetter(...) Character.toLowerCase(...)
Record your participation in Piazza clicker question Lesson19 Q2
What about the Character class?
Record your participation in Piazza clicker question Lesson19 Q3
Non-static methods are called instance methods.
Pick a library class we have used and name an instance method it contains
public static double rectangleArea(Rectangle rec) { return rec.getWidth() * rec.getHeight(); }
public static void main(String[] args)
Record your participation in Piazza clicker question Lesson19 Q4
Here is a project containing a Circle class which represents a circle in 2d space.
Record your participation in Piazza clicker question Lesson19 Q5
Now in the same project, add a class called Util
Record your participation in Piazza clicker question Lesson19 Q6
Add a static method to Util that takes an ArrayList of Strings as a parameter and returns the longest word or the empty String if the ArrayList is empty. Call the method longest()
Record your participation in Piazza clicker question Lesson19 Q7
Add a tester class to the project which tests your methods. Here is a starter.
import java.util.ArrayList; public class UtilTester { public static void main(String[] args) { int[] numbers = {2, 7, 4, 9, 11}; ArrayList<String> strings =new ArrayList<>(); strings.add("int"); strings.add("final"); strings.add("static"); strings.add("interface"); strings.add("final"); ArrayListlist = new ArrayList (); //put your test code below //test sum //test longest //test empty ArrayList } }