Class Object120
- java.lang.Object
-
- Object120
-
public class Object120 extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description Object120(java.lang.Object... args)
Automated constructor: Initialize each field of the subclass with the provided args, in the order the fields are declared within the subclass' file.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static char
charAt(java.lang.String _this, int i)
Select a single character from a string, by index (starting at 0).static <T,S extends T>
intcompareTo(java.lang.Comparable<T> _this, S that)
Check whether one value is greater, equal, or lesser than another.static boolean
contains(java.lang.String _this, java.lang.CharSequence target)
Return whether or not one String contains another.boolean
equals(java.lang.Object oth)
static boolean
equals(java.lang.Object _this, java.lang.Object that)
Are two values equal? Works on any values (non-null).static boolean
equalsIgnoreCase(java.lang.String a, java.lang.String b)
Are two Strings equal (up to case, but including punctuation).static java.lang.String
getVersion()
Return the version number of this library (since it might get updated through the semester).int
hashCode()
static int
indexOf(java.lang.String _this, java.lang.String target)
Return where one string is contained inside another.static boolean
isEmpty(java.lang.String _this)
Return whether or not a String is the empty string "" (0 letters long).static int
length(java.lang.String _this)
Return the number of characters in a string.static void
printVersion()
Print version information to the console window.static int
randomInt(int n)
Return a random integer in [0,n).static java.lang.String
substring(java.lang.String _this, int from)
Return a substring of the given string from index `from` up through the last character.static java.lang.String
substring(java.lang.String _this, int from, int to)
Return a substring of the given string, from index `from` up to but not including index `to`.static char
toChar(int n)
Return character corresponding to a particular the unicode value.static char
toChar(java.lang.String s)
Convert a String-of-length-1 to a char.static double
toDouble(int n)
Convert an int to a double.static double
toDouble(java.lang.String s)
Convert a String to a double.static int
toInt(char c)
Return the unicode value of a character.static int
toInt(double x)
Convert a double to an int (truncating towards zero).static int
toInt(java.lang.String s)
Convert a String into an int.static java.lang.String
toLowerCase(java.lang.String _this)
Return a lower-case version of the given string.java.lang.String
toString()
java.lang.String
toString(boolean includeFieldNames)
Return a String which looks like a constructor call:static java.lang.String
toString(java.lang.Object _this)
Convert any value into a String.static java.lang.String
toUpperCase(java.lang.String _this)
Return an upper-case version of the given string.
-
-
-
Constructor Detail
-
Object120
public Object120(java.lang.Object... args)
Automated constructor: Initialize each field of the subclass with the provided args, in the order the fields are declared within the subclass' file. Remember that if a use writes their own constructor for a subclass, this constructor will still get called first with 0 args, unless the explicitly called `super` with more args. Alas, we can't check here whether they actually manage to initialize their fields correctly...
-
-
Method Detail
-
getVersion
public static java.lang.String getVersion()
Return the version number of this library (since it might get updated through the semester).
-
printVersion
public static void printVersion()
Print version information to the console window.
-
randomInt
public static int randomInt(int n)
Return a random integer in [0,n).- Parameters:
n
- the top end of the range.- Returns:
- a pseudorandom integer in [0,n). E.g. randomInt(100) might return 0 or 1 or 99, but never 100.
- See Also:
Random.nextInt(int)
-
equals
public static boolean equals(java.lang.Object _this, java.lang.Object that)
Are two values equal? Works on any values (non-null). A static version of Object.equals(Object), for use in CS1 before we introduce objects.- Parameters:
_this
- the first value to compare. (Must be non-null.)that
- the second value to compare. (Must be non-null.)- Returns:
- true iff `_this` equals `_that`.
For example:
equals( "hello", "howdy" ) = false equals( "hello", "hello" ) = true equals( 23, 22+1 ) = true
- See Also:
Object.equals(Object)
-
toString
public static java.lang.String toString(java.lang.Object _this)
Convert any value into a String. A static version of Object.toString(), for use in CS1 before we introduce objects.- Parameters:
_this
- The value to stringify. Cannot be null.- Returns:
- a String representation of `_this`.
For example:
toString(43) = "43" toString(true) = "true"
- See Also:
Object.toString()
-
compareTo
public static <T,S extends T> int compareTo(java.lang.Comparable<T> _this, S that)
Check whether one value is greater, equal, or lesser than another. A static version of compareTo(Object), for use in CS1 before we introduce objects.- Parameters:
_this
- The first value to compare.that
- The second value to compare.- Returns:
- a positive number if `_this` is greater than `that`, zero if `_this` is equal to `that`, or a negative number if `_this` is less than `that`.
- See Also:
Comparable.compareTo(Object)
-
equalsIgnoreCase
public static boolean equalsIgnoreCase(java.lang.String a, java.lang.String b)
Are two Strings equal (up to case, but including punctuation). A static version of String.equalsIgnoreCase(String), for use in CS1 before we introduce objects.- Parameters:
a
- The first string to compare. Cannot be null.b
- The second string to compare. Cannot be null.- Returns:
- true iff a and b are the same (ignoring case).
For example:
equalsIgnoreCase( "hi", "HI" ) = true equalsIgnoreCase( "hi", "hi " ) = false equalsIgnoreCase( "", "" ) = true
- See Also:
String.equalsIgnoreCase(String)
-
length
public static int length(java.lang.String _this)
Return the number of characters in a string. A static version of String.length(), for use in CS1 before we introduce objects.- Parameters:
_this
- The string to find the length of. Cannot be null.- Returns:
- The number of characters in `_this`.
For example:
length( "hi ho" ) = 5 length( "z" ) = 1 length( "" ) = 0
- See Also:
String.length()
-
substring
public static java.lang.String substring(java.lang.String _this, int from, int to)
Return a substring of the given string, from index `from` up to but not including index `to`. A static version of `String.substring(int,int)`, for use in CS1 before we introduce objects.- Parameters:
_this
- The `String` to take a substring from. Cannot be null.start
- The index of the first character of the substring.stop
- The index of the first character after the substring.- Returns:
- A String consisting from characters at indices [`start`,`stop`) from `_this`.
- See Also:
String.substring(int,int)
-
substring
public static java.lang.String substring(java.lang.String _this, int from)
Return a substring of the given string from index `from` up through the last character. A static version of `String.substring(int)`, for use in CS1 before we introduce objects.- Parameters:
_this
- The `String` to take a substring from. Cannot be null.start
- The index of the first character of the substring.- Returns:
- A String consisting from characters at indices [`start`,`length(_this)`) from `_this`.
- See Also:
String.substring(int)
-
indexOf
public static int indexOf(java.lang.String _this, java.lang.String target)
Return where one string is contained inside another. A static version of `String.indexOf(String)`, for use in CS1 before we introduce objects.- Parameters:
_this
- The `String` to look inside. Cannot be null.target
- The String to try to find occuring inside `_this`. Cannot be null.- Returns:
- The index of `_this` where `target` starts, or -1. That is: if int i=indexOf(s1,s2), then i==-1 || equals(s2,substring(s1,i,i+length(s2))) (equivalently, i==-1 || s2.equals(s1.substring(i,i+s2.length())))
- See Also:
String.indexOf(String)
-
toLowerCase
public static java.lang.String toLowerCase(java.lang.String _this)
Return a lower-case version of the given string. A static version of `String.toLowerCase()`, for use in CS1 before we introduce objects.- Parameters:
_this
- The `String` to take a substring from. Cannot be null.- Returns:
- A lower-case version of `_this`.
- See Also:
String.toLowerCase()
-
toUpperCase
public static java.lang.String toUpperCase(java.lang.String _this)
Return an upper-case version of the given string. A static version of `String.toUpperCase()`, for use in CS1 before we introduce objects.- Parameters:
_this
- The `String` to convert to upper case. Cannot be null.- Returns:
- An upper-case version of `_this`.
- See Also:
String.toUpperCase()
-
toInt
public static int toInt(java.lang.String s)
Convert a String into an int.- Parameters:
s
- A string which is a valid representation of an int; cannot be empty.- Returns:
- the int represented by `s`.
For example:
toInt("2") = 2 toInt("007") = 7
- Throws:
java.lang.NumberFormatException
- if `s` does not represent a valid double. stringToDouble("2+3") throws NumberFormatException
-
toDouble
public static double toDouble(java.lang.String s)
Convert a String to a double.- Parameters:
s
- A string which is a valid representation of a double.- Returns:
- the double represented by `s`.
For example:
toDouble("43.2") = 43.2 toDouble("2") = 2.0 toDouble("007") = 7.0
- Throws:
java.lang.NumberFormatException
- if `s` does not represent a valid double. For example:toDouble("2+3") -> NumberFormatException
-
toDouble
public static double toDouble(int n)
Convert an int to a double. (Same as casting to an int, but use the regular syntax for calling-a-method.)- Parameters:
n
- the int to convert.- Returns:
- n as a double.
For example:
intToDouble(0) = 0.0 intToDouble(-2) = -2.0 intToDouble(2000000000) = 2e9 intToDouble(2000000001) = 2.000000001e9
-
toInt
public static int toInt(double x)
Convert a double to an int (truncating towards zero). (Same as casting to an int, but use the regular syntax for calling-a-method.)- Parameters:
x
- The double to convert to an int.- Returns:
- The int nearest to x, but between 0 and x.
For example:
doubleToInt(0.0) = 0 doubleToInt(3.1) = 3 doubleToInt(3.9) = 3 doubleToInt(-3.1) = -3.0 doubleToInt(-3.9) = -3.0
- See Also:
Double.intValue()
,Math.floor(double)
,Math.ceil(double)
,Math.round(double)
-
toChar
public static char toChar(int n)
Return character corresponding to a particular the unicode value. For "ordinary" characters, this is the ascii value ('A'=43,'B'=44','a'=97,...)- Parameters:
n
- The unicode(ascii) value to convert to a char. Must be valid as a short -- in [0,65536).- Returns:
- the character corresponding to the unicode value `n`.
-
toInt
public static int toInt(char c)
Return the unicode value of a character. For "ordinary" characters, this is the ascii value ('A'=43,'B'=44','a'=97,...)- Parameters:
c
- The character to get the unicode value of.- Returns:
- the unicode value of `c`.
-
toChar
public static char toChar(java.lang.String s)
Convert a String-of-length-1 to a char.- Parameters:
s
- A string of length 1.- Returns:
- s as a char.
- See Also:
String.charAt(int)
-
charAt
public static char charAt(java.lang.String _this, int i)
Select a single character from a string, by index (starting at 0). A static version of `String.charAt(int)`, for use in CS1 before we introduce objects.- Parameters:
_this
- The `String` to select a character from. Cannot be null.i
- The index of the character to select from s; 0 <= i < length(s).- Returns:
- The `i`th character of `_this`.
- See Also:
String.toLowerCase()
-
contains
public static boolean contains(java.lang.String _this, java.lang.CharSequence target)
Return whether or not one String contains another. A static version of `String.contains(CharSequence)`, for use in CS1 before we introduce objects.- Parameters:
_this
- The `String` to look inside of. Cannot be null.target
- The String to look for in `_this`.- Returns:
- whether or not `target` occurs in `_this`.
- See Also:
String.contains(CharSequence)
,indexOf(String,String)
,String.indexOf(String)
-
isEmpty
public static boolean isEmpty(java.lang.String _this)
Return whether or not a String is the empty string "" (0 letters long). A static version of `String.isEmpty()`, for use in CS1 before we introduce objects.- Parameters:
_this
- The String to compare to "". Cannot be null.- Returns:
- whether or not equals(_this,"") (equivalently, length(_this)==0).
- See Also:
String.isEmpty()
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object oth)
- Overrides:
equals
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toString
public java.lang.String toString(boolean includeFieldNames)
Return a String which looks like a constructor call:- Parameters:
includeFieldNames
- If true, include the field names along with their values.- Returns:
- a String which looks just like a constructor call
when `includeFieldNames` is false,
or similar to one when `includeFieldNames` is true.
For example:
class Foo extends Object120 { int n; String s } new Foo(7,"hi").toString(false) = "new Foo( 7, \"hi\" )" new Foo(8,"ho").toString(true) = "new Foo( n=8, s=\"ho\" )"
Bug: Depending on the Java compiler, the field names might not be given in the same order they are declared in the class. (This is because java.lang.reflect doesn't provide access to the declared order; however, many implementations happen to to use that order.)
-
-