Intro To Java OOP Homework 1
Intro To Java OOP Homework 1
/**
* Write a method to convert the given seconds to
hours:minutes:seconds.
* @param seconds to convert
* @return string for the converted seconds in the format: 23:59:59
* Example: If input seconds is 1432, print and return output in the
format: 0:23:52
*/
public String convertTime(int seconds){
// TODO: Your code goes here
return null;
}
We’ll run Java tests against your program to test whether each method implementation is
correct and whether you have considered enough cases. Examples of cases have been
provided in the javadocs.
The main method has not been completely implemented for you (see example below). You’ll
need to write code (where it says “// TODO”) to use it to run and interact with your program,
and to see if your methods are working as expected. Spend some time on testing.
sc.close();
}
Tips for this Assignment
In this assignment, some tips are given as follows:
● Modulus operation in Java:
“%” is the modulus operator in Java. It returns the remainder, after division.
For example:
int result1 = 4 % 2; //result1 is 0
int result2 = 1000 % 90; //result2 is 10
● int to String conversion in Java:
There are multiple ways to convert an int to a String.
○ Use “Integer.toString(int)”
For example:
int num = 9;
String str = Integer.toString(num); //str is “9”
○ Use “String.valueOf(int)”
For example:
int num = 9;
String str = String.valueOf(num); //str is “9”
● String to int conversion in Java:
○ Use “Integer.parseInt(str)”
For example:
String str="0";
int num = Integer.parseInt(str); //num is 0
● Getting a specific char in a String by index in Java:
○ Use “charAt(int)”
For example:
String str = "cit";
char firstChar = str.charAt(0); //firstChar is ‘c’
Introduction to Java & Object Oriented Programming
Submission
To complete the assignment, write the program as described in S impleGame.java and
implement the methods in it. Do not modify the name of the methods in S impleGame.java or
the automated testing will not recognize it. Submit the completed program using the steps
outlined in the assignment in Coursera.
Evaluation
Points: Each method is worth 10 points.