Ex 4
Ex 4
- Create a new folder that is named with the following format: studentID-studentname-
workshopNumber. The folder contains 4 projects: Q1,Q2,Q3,Q4,….
Example: se18123-nguyenvana-WS01 or SE12123-nguyen van a-WS01
- Use jdk 1.8
- The result must be formated like the given tesstcase
- Submit your result to the LMS page( example : se18123-nguyenvana-WS01.zip)
System.out.println(finalresult);
}
Else if (choice==8)
{
// test octal system
Int[] oc_1=num1.DecToOctal();
Int[] oc_2=num2.DecToOctal();
System.out.println(finalresult);
}
Else if(choice==16)
{
// test hexa system
char[] h_1=num1.DecToHexa();
char[] h_2=num2.DecToHexa();
System.out.println(finalresult);
}
for example:
methods:
1. Constructors, getters, setters (use try..catch to check x,y >=0 and radius>0)
2. Implements all abstract methods
3. void output(): to display detail of the circle
4. override the compareTo() method. This function is used to compare two Circles’s area.
Notice that: return 1 if the first circle ‘s area > the second circle area
return -1 if the first circle ‘s area < the second circle area
return 0 if they are the same
3. Create a class called “Rectangle” extends Shape and implements the Comparable interface. It
contains two fields: int width, int height
Methods:
1. Constructors, getters, setters (use try..catch to check width,height>0)
2. Implements all abstract methods
3. Void output(): to display detail of the rectangle
4. Override the compareTo() to compare two Rectangles’s perimeter
Notice that: return 1 if the first circle ‘s perimeter > the second circle perimeter
return -1 if the first circle ‘s perimeter < the second circle perimeter
return 0 if they are the same
4. Create a class Tester to test all functions. In the main method, do requirements:
TC1:
1. Test 2 circle’s output & compareTo method
2. Test 2 rectangle’s output & compareTo method
enter option: 1
circle 1
enter x: 1.5
enter y:2.0
enter radius:10
circle 2
enter x:1
enter y:2
enter radius:2
OUTPUT:
(1.5,2,10) (1,2,2)@1
TC2:
1. Test 2 circle’s output & compareTo method
2. Test 2 rectangle’s output & compareTo method
enter option: 2
rectangle 1
enter width: 5
enter length:20
rectangle 2
enter width: 50
enter length:200
OUTPUT:
(5,20) (50,200)@-1
Write a class named MyString, which implements the interface IString. The class MyString implements
methods f1 and f2 in IString as below:
f1: Count and return number of words containing at least 1 odd digit.
f2: Return the string s, which is obtained by replacing the (first) palindrom word in str with the
string "XX" (word = a string without space(s), a word is called palindrom if it and its reverse are
the same).
Write a class Tester to test the program.