I made a simple program that uses OOP methods. Please tell me if I used the 4 methods right. And if not, please show me how.
class Encap{
private String name;
public void setName(String newValue){
name = "Hello, "+newValue+"!";
}
public String getName(){
return name;
}
}
abstract class Abstraction {
int fibCount, flag=0, y;
String inputName;
String names[] = new String [] {"Anna","Joe","Carl"};
Scanner x = new Scanner(System.in);
abstract void abscompute();
}
class abs2 extends Abstraction{
@Override
void abscompute()
{
System.out.print("Enter number of fibonacci: ");
fibCount = x.nextInt();
int[] fib = new int[fibCount];
fib[0] = 0;
fib[1] = 1;
for(int i=2; i < fibCount; i++){
fib[i] = fib[i-1] + fib[i-2];
}
for(int i=0; i< fibCount; i++){
System.out.print(fib[i] + " ");
}
}
}
public class Fibonacci {
public static void main(String[] args) {
Abstraction abs = new abs2();
Encap encap = new Encap();
System.out.print("Enter your name: ");
abs.inputName = abs.x.next();
for (String name : abs.names) {
if(abs.inputName.equals(name)){
encap.setName(abs.inputName);
System.out.println(""+encap.getName());
abs.flag = 1;
}
}
if(abs.flag!=1){
System.out.println("Name doesn't exist..");
}
else{
abs.abscompute();
}
}
}