Oop Homework 2
Oop Homework 2
COURSE : AT47
STUDENT ID : D20131064637
EXERCISE 1
MAIN CLASS
package chapter10_array;
import java.util.Scanner;
Person aa;
Person [] person;
aa = new Person();
aa.setName("Name");
aa.setAge(2);
aa.setGender( "g" );
gender = inpStr.charAt(0);
PERSON CLASS
package chapter10_array;
Name=w;
Age=b;
Gender=c;
return Name;
return Age;
return Gender;
}
EXERCISE 2
COMPARE TO
SUBSTRING
String str= new String("quick brown fox jumps over the lazy dog");
System.out.println(str.substring(15));
System.out.println(str.substring(15, 20));
}
END WITH
START WITH
String str= new String("quick brown fox jumps over the lazy dog");
+str.startsWith("brown", 6));
+str.startsWith("quick", 6));
}
TRIM
VALUE OF
str1 = str1.copyValueOf(data);
str2 = str2.copyValueOf(data, 5, 3 );
}
EXERCISE 3
/**
* Precondition.
* other words.
*/
if (!condition) {
/**
* Precondition.
*/
if (objectToBeTested == null) {
throw new RuntimeException("Precondition: The expectation '" + objectName + " is not null' is
violated");
/**
* Postcondition.
* other words.
*/
public static void Ensure(boolean condition, String description) {
if (!condition) {
/**
* other words.
*/
if (!condition) {
EXERCISE 4
CATCHER
import java.io.*;
try{
}catch(ArrayIndexOutOfBoundsException e){
class TestExceptionPropagation1{
void m(){
int data=50/0;
void n(){
m();
void p(){
try{
n();
obj.p();
System.out.println("normal flow...");