You are on page 1of 6

Department of Computer Science CSC-210:Object-Oriented Programming

Bahria University Karachi Campus Semester 02 (Spring 2021)

ASSIGNMENT 04
Solution
Marks: 5

1. Write a java program for Tax calculation of property as per given class diagram. Make 5
objects of Taxable house and bus, and show their taxes. Attach screenshots of your
output as well.
For tax calculation:
InCity house= (estimatedValue / 1000) * 5 + 0.5 * area
Out of City house= (estimatedValue / 1000) * 3
For Bus= (value / 10) + 105 * numberOfSeats

Source Code:
public class Fixed_Property {
protected String location;
protected boolean incity;
protected double estimate_Value;

public class House extends Fixed_Property{


protected double area;

public House(String location,double area,boolean city,double value){


super(location, city, value);
this.area =area;
}
public double getArea(){
return(area);
}
}
public Fixed_Property(String location,boolean city,double value){
Department of Computer Science CSC-210:Object-Oriented Programming
Bahria University Karachi Campus Semester 02 (Spring 2021)

this.location=location;
incity=city;
estimate_Value=value;

}
public String getLocation(){
return(location);
}
}
public class TaxableHouse extends House implements ITaxable{

public TaxableHouse(String location, double area, boolean city, double value) {


super(location, area, city, value);
}
@Override
public double TaxValue() {
if (incity==true)
{
return((estimate_Value/1000)*5+0.5*area);
}
else{
return((estimate_Value/1000)*3);
}
}
}
public class Vehichle {
protected int Reg_num;
protected double value;
protected double maxVelocity;

public Vehichle(int regnum,double maxvelocity,double value){


Department of Computer Science CSC-210:Object-Oriented Programming
Bahria University Karachi Campus Semester 02 (Spring 2021)

Reg_num=regnum;
this.value=value;
this.maxVelocity=maxvelocity;

}
public int getRegnum(){
return(Reg_num);
}}
public class Bus extends Vehichle{
protected int no_of_seat;
public Bus(int regnum, double maxvelocity,int noOfseats, double value) {
super(regnum, maxvelocity, value);
no_of_seat=noOfseats;
}
public int getTotalSeats(){
return(no_of_seat);
}}
public class TaxableBus extends Bus implements ITaxable{

public TaxableBus(int regnum, double maxvelocity, int noOfseats, double value) {


super(regnum, maxvelocity, noOfseats, value);
}
@Override
public double TaxValue() {
return((value/10)+105*no_of_seat);
}}
public interface ITaxable {
double TaxValue();}
public class Calculation {
public static void main(String args[]){
//TaxableBus(int regnum, double maxvelocity, int noOfseats, double value)
Department of Computer Science CSC-210:Object-Oriented Programming
Bahria University Karachi Campus Semester 02 (Spring 2021)

System.out.println("******Tax Calculation For Buss******\n");


TaxableBus B1=new TaxableBus(001,1234,10,65.2600);
System.out.println("Bus 001: "+ B1.TaxValue() );
TaxableBus B2=new TaxableBus(002,4662,213,45630.82);
System.out.println("Bus 002: "+ B2.TaxValue() );
System.out.println("\n******Tax Calculation For House******\n");
TaxableHouse h1=new TaxableHouse("xyz",1256,false,1000000);
System.out.println("House 1: "+ h1.TaxValue() );
TaxableHouse h2=new TaxableHouse("pqr",654,false,2000000);
System.out.println("House 2: "+ h2.TaxValue() );
TaxableHouse h3=new TaxableHouse("abc",931,true,3000000);
System.out.println("House 3: "+ h3.TaxValue() )}}
Department of Computer Science CSC-210:Object-Oriented Programming
Bahria University Karachi Campus Semester 02 (Spring 2021)

2. Can we declare interface members as private?


Answer: No we cannot declare interface members as private or protected

3. What will happen if we are not implementing all the methods of an interface in class
which implements an interface?
Department of Computer Science CSC-210:Object-Oriented Programming
Bahria University Karachi Campus Semester 02 (Spring 2021)

Answer: If we are not implementing all the methods of an interface in class which
implements an interface then we must have to make this class abstract otherwise we
must have to provide the implementation of all the method.

4. Can abstract class extends another abstract class?


Answer: Yes, an abstract class can extends another abstract class

You might also like