Common requirements:
- 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 : [Link])
Q1: Create a new project named “Q1”.
In package “Core” that contains: IMenu, IExtendBiMenu , IExtendOctalMenu, IExtendHexaMenu
1. Create an interface “IMenu”, it includes:
- int[] DecToBi(): to change a decimal number to binary number( using a array to store the binary
number)
- Int [] DecToOctal(): to change a decimal number to octal number( using a array to store the octal
number)
- char[] DecToHexa(): to change a decimal number to hexa number( using a array to store the
hexa number)
2. An interface IExtendBiMenu extends IMenu and some prototype
- Int BiToDec(int [] number): to change a binary number to a decimal number
- Int[] Add(int[] number): to add two binary numbers and return a binary number
3. An interface IExtendOctalMenu extends IMenu and some prototype
- Int OctalToDec(int [] number): to change a binary number to a decimal number
- Int[] Add(int[] number): to add two octal numbers and return a octal number
4. An interface IExtendHexalMenu extends IMenu and some prototype
- Int HexaToDec(char [] number): to change a hexa number to a decimal number
- Char add(char [] number): to add two hexa numbers and return a hexa number
In package “NumberSystem” that contains: DecimalNumberSystem, BinarySystem, OctalNumberSystem,
HexaNumberSystem
1. Create a class “DecimalNumberSystem” , it implements IMenu and includes:
- Private int DecimalNumber: store a decimal number
- Int base (validate base is only 10)
- Constructor/Getter/setter
- Implementing all abstract methods
2. Create a class “BinaryNumberSystem” extends DecimalNumberSystem , it implements
IExtendBiMenu, and inludes something:
- int[] BiNumber: store a binary number
- constructor/getter/setter
- Implements all abstract methods
Note: base accepts only 2
3. Create a class “OctalNumberSystem” extends DecimalNumberSystem , it implements
IExtendOctalMenu, and inludes something:
- int[] OctalNumber: store a octal number
- Implements all abstract methods
Note: base accepts only 8
4. Create a class “HexaNumberSystem” extends DecimalNumberSystem , it implements
IExtendHexalMenu, and inludes something:
- char[] HeaxNumber: store a octal number
- Implements all abstract methods
Note: base accepts only 16
5. Create a class Tester. In main method student types exactly the same as below code:
Int choice;
Scanner s=new Scanner([Link]);
[Link](“enter number1:”);
int number1=[Link]();
[Link](“enter number2:”);
int number2=[Link]();
IMenu num1=new DecimalNumberSystem(number1);
IMenu num2=new DecimalNumberSystem(number2);
[Link](“Choose base (2/8/16):”
Choice=[Link]();
If( choice==2)
{
// test binary system
Int[] bi_1=[Link]();
Int[] bi_2=[Link]();
IExtendBiMenu m2=new BinaryNumberSystem(bi_1);
Int[] result=[Link](bi_2);
IExtendBiMenu finalresult=new BinaryNumberSystem(result);
[Link](finalresult);
}
Else if (choice==8)
{
// test octal system
Int[] oc_1=[Link]();
Int[] oc_2=[Link]();
IExtendOctalMenu m3=new OctalNumberSystem(oc_1);
Int[] result2=[Link](oc_2);
IExtendOctalMenu finalresult=new OctalNumberSystem(result2);
[Link](finalresult);
}
Else if(choice==16)
{
// test hexa system
char[] h_1=[Link]();
char[] h_2=[Link]();
IExtendHexaMenu m4=new OctalNumberSystem(h_1);
Int[] result3=[Link](h_2);
IExtendHexaMenu finalrrsult=new OctalNumberSystem(result3);
[Link](finalresult);
}
for example:
TC1: TC2: TC3:
enter number1:267 enter number1:267 enter number1:267
enter number2:125 enter number2:125 enter number2:125
Choose base (2/8/16):2 Choose base (2/8/16):16 Choose base (2/8/16):8
OUTPUT: OUTPUT: OUTPUT:
100001011 10B 413
1111101 7D 175
0110001000 188 610
Q2: Create a new project named “Q2”.
1. Create an abstract class called “Shape”. It contains some abstract functions:
- Double getArea()
- Double getPerimeter()
- Final double PI=3.14
2. Create a class called Circle extends Shape and implements the Comparable interface . It includes
3 fields : int x,y; double radius
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:
//create two Circle objects using constructors
// call the output method
//call the compareTo method to compare the area of these circle objects
//create two Rectangle objects using constructors
// call the output method
//call the compareTo method to compare the perimeter of these rectangle objects
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
Q3: Create a new project named “Q3”.
Create an interface as the following:
public interface IString {
public int f1(String str);
public String f2(String str);
}
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.
The program output might look something like:
1. Test f1() 1. Test f1()
2. Test f2() 2. Test f2()
Enter TC (1 or 2): 1 Enter TC (1 or 2): 2
Enter a string: Enter a string:
a a1 b2 c34 d6 ab 12321 uv 12321 xy
OUTPUT: OUTPUT:
2 ab XX uv 12321 xy