How can add interface java file to these three java files that runs together? Java file 1: package property2;
How can add interface java file to these three java files that runs together?
Java file 1:
package property2;
import java.util.Scanner;
public class Property2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// Read property name and rent as input values from the keyboard
System.out.println("Enter property name: ");
String propertyName=in.nextLine();
System.out.println("Enter property rent amount: ");
int rent=Integer.parseInt(in.nextLine());
Property property = new Apartment(propertyName, rent);
System.out.println("Property Name: "+property.getPropertyName());
System.out.println("Property Rent$: "+property.getRentAmount());
}
}
Java file 2:
package property2;
import javax.lang.model.SourceVersion;
abstract class Property
{
protected String propertyName;
protected int rentAmount;
public Property(String propertyName, int rentAmount)
{
this.propertyName = propertyName;
this.rentAmount = rentAmount;
}
public abstract String getPropertyName();
public abstract int getRentAmount();
}
Java file 3:
package property2;
class Apartment extends Property
{
/*Apartment class constructor that takes two input
* arguments and calls the constructor of the abstract class*/
public Apartment(String PropertyName, int RentAmount)
{
super(PropertyName, RentAmount);
}
@Override
/*
* Return propertyName value
* */
public String getPropertyName() {
return propertyName;
}
@Override
/*
* Return rentAmount value
* */
public int getRentAmount() {
return rentAmount;
}
}

Step by step
Solved in 6 steps with 3 images









