[B] I have done assignment about Interface, but I am not sure is it ok or not? [/B]
I have done my assignment about interface, but I don't know is it ok or not, please could anyone help me?
assignment is:
Project Module - Object Oriented Programming/Interface
1. Write a programme to print your name, qualification and the name of your college by implementing interfaces.
++++++++++++++++
public interface People_Interface {
// Methods Declaration to print your name, qualification and the name of your college.
public void printName();
public void printQualification();
public void printCollegeName();
}
+++++++++++++++++
public class Student_details implements People_Interface{
public void printName(){
System.out.println("My name is Josef");
}
public void printQualification(){
System.out.println("My qualification is Bachelor's degree of IT");
}
public void printCollegeName(){
System.out.println("College name is Al-Khorazmy");
}
}
++++++++++++++++++++
public class Student {
public static void main(String[] args) {
People_Interface print = new Student_details();
print.printName();
print.printQualification();
print.printCollegeName();
}
}
+++++++++++++++++++++
2. Modify the above programme by implementing separate interfaces to print:
- Your Name
- Your Age
- Name of Your College
- Just print the line "I am a Java Programmer
In the above programme use the same main method to call different interfaces and print the output which should look like this:
Output:
My Name is : "Your Name"
My Age is : "Your Age"
My College is : "Your College's Name"
I am a Java Programmer
++++++++++++++++++++++
public class Printing implements Printing_Interface{
public void printName(){
System.out.print("My name is: ");
}
public void printAge(){
System.out.print("My Age is: ");
}
public void printCollegeName(){
System.out.print("My College is: ");
}
public void printIAmAJavaProgrammer(){
System.out.println("I am a Java Programmer");
}
}
+++++++++++++++++++++++++++++++
public interface Printing_Interface {
// Methods Declaration to print your name, qualification and the name of your college.
public void printName();
public void printAge();
public void printCollegeName();
public void printIAmAJavaProgrammer();
}
++++++++++++++++++++++++++++++++++
public class Student_details implements Student_Interface{
private String name;
private int age;
private String collegeName;
public void setName(String value){
name = value;
}
public String getName(){
return name;
}
public void setAge(int value){
age = value;
}
public int getAge(){
return age;
}
public void setCollegeName(String value){
collegeName = value;
}
public String getCollegeName(){
return collegeName;
}
}
++++++++++++++++++++++++++++++++++
public interface Student_Interface {
// Methods Declaration to print your name, qualification and the name of your college.
public void setName(String value);
public String getName();
public void setAge(int value);
public int getAge();
public void setCollegeName(String value);
public String getCollegeName();
}
+++++++++++++++++++++++++++++++++++
public class Student {
public static void main(String[] args) {
Student_Interface student1 = new Student_details();
student1.setName("Akhmad");
student1.setAge(30);
student1.setCollegeName("Al-Khorazmiy");
Printing_Interface printing = new Printing();
printing.printName();
System.out.println(student1.getName());
printing.printAge();
System.out.println(student1.getAge());
printing.printCollegeName();
System.out.println(student1.getCollegeName());
printing.printIAmAJavaProgrammer();
}
}
+++++++++++++++++++++++++++++++++++++++
Sorry about too much code, if anyone can help I really appreciate this
regards
Akhmad