Modularity: Classes allow us to split the problem to be solved into distinct tasks
You should be able to think about what a class does, not how it does it
Java Objects are title-case
String
new)Two “flavors” of types:
1 byte is 8 binary digits
All Objects (everything else) (4 bytes)
String is a class (title capitalization)
We can construct strings two ways:
Some string methods:
These work like pointers:
null (meaning “not pointing to object”)Comparison == not the same as .equals()
Answer this short quiz on comparisons of objects on gradescope
Discuss
Write a class called MyTimejava that, given number (integer) as seconds, it converts it to hours:minutes:seconds. Your application should print the equivalent hours, minutes, and seconds in this format: hours:minutes:seconds
Examples: 1 should be converted to the "0:0:1", 3661 should be converted to the "1:1:1", 8274 should be converted to the "2:17:54"
HINTS: There are 3600 seconds in one hour. Use % to calculate minutes and seconds left.
public class MyTime {
private static int getHours(int seconds) {
return seconds/3600;
}
private static int getMinutes(int seconds) {
return seconds/60;
}
public static String getTime(int seconds) {
// get full hours
int hours = getHours(seconds);
// update how many seconds are left
int secondsLeft = seconds - (hours * 3600);
// calculate full minutes
int minutes = getMinutes(secondsLeft);
// update how many seconds are left
secondsLeft = secondsLeft - (minutes * 60);
return hours + ":" + minutes + ":" + secondsLeft;
}
public static void main(String[] args) {
int seconds = 119;
String result = getTime(seconds);
System.out.println(result);
}
}