Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Directions The assignment will consist of 6 files. They must be called < Lastnam

ID: 3688484 • Letter: D

Question

Directions

The assignment will consist of 6 files. They must be called <LastnameFirstnameUnit5.java> (driver program)
LastnameFirstnameTaxable.java
LastnameFirstnameRealState.java

LastnameFirstnameTerrain.java (which extends LastnameFirstnameRealState)

LastnameFirstnameBuilding.java (which extends LastnameFirstnameRealState)

LastnameFirstnameBoat.java

The files must be called as specified above, (LastnameFastname = LnFn = Your Last Name Your First Name)

Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter.

Only submit the .java files needed to make the program run. Do not submit the .class files or any other files.

Style Components

Include properly formatted prologue, comments, indenting, and other style elements as shown in Chapter 2 starting page 64 and Appendix 5 page 881-892.

Compilation

All programs should compile. Even if the program is not fully operational, students should comment out the sections that are not working and present a code that compiles. The commented-out sections will be an indication of the attempts the student made to complete the tasks in the assignment.

Basic Requirements

Write a program that creates an Array List of Taxable element and create and add 20 Taxable elements at random. Then produce three tables that summarizes the taxes owed by each type of Taxable Assets.

Review output details on the sample below. Try to produce an output that is closer to the one shown, except for the actual values.
Remember to use the get and set methods whenever you need to get the value or modify a value of any instance variable everywhere in your program.

LnFnTaxable.java

This is an interface with only the following abstract method:

          public double getTax();

LnFnRealState.java

This is an abstract class. It should be declared as such. However, it contains the following private instance variables:

·       description (String) a String that names and or describe the Real State.

·       area (double) the square feet for this Real State.

·       unitPrice (double) the price for each square feet in the Real State.

The class should provide public accessor (get) and mutator (set) methods for all its instance variables. The class also should have a constructor method with parameters that initialize all its corresponding instance variables.

LnFnTerrain.java

This is a subclass from the LnFnRealState class. It contains the following private instance variables:

·       agroFraction (double) the fraction of the Terrain’s area that can be used for agriculture.

·       numberOfTrees (int) the number of trees inside the Terrain.

The class should provide public accessor (get) and mutator (set) methods for all its instance variables. The set method for the agroFraction should check that the value received is between 0.0 to 1.0. If the value is outside these limits, the instance variable should not be changed.

The class also should have a constructor method with parameters that initialize all its corresponding instance variables and the instance variables for its superclass (LnFnRealState).

This class will also implement the Taxable Interface. The getTax method will return the amount a tax assessed for this Terrain. A Terrain pays 1% of the value obtained by multiplying its area by its unitPrice by the fraction used for agriculture plus 10 dollars per each tree in the Terrain.

LnFnBuilding.java

This is also a subclass from the LnFnRealState class. It contains the following private instance variables:

·       dwellingArea (double) the built area of the Building in square feet.

·       numberOfStories (int) the number of stories in the Building.

The class should provide public accessor (get) and mutator (set) methods for all its instance variables. The class also should have a constructor method with parameters that initialize all its corresponding instance variables and the instance variables for its superclass (LnFnRealState).

This class will also implement the Taxable Interface. The getTax method will return the amount a tax assessed for this Building. A Building, will pay 1% of the value obtained by multiplying its land area (from parent class) by its unitPrice plus 2% of the value obtained by multiplying its dwelling area by its unitPrice by 3.

LnFnBoat.java

This class does not subclass from LnFnRealState class, or any other user class, only from the Object class. It contains the following private instance variables:

·       description (String) a String that names and or describe the Boat.

·       footage (double) the length of the Boat in feet.

·       numberOfCabins (int) the number of cabins in the Boat.

The class should provide public accessor (get) and mutator (set) methods for all its instance variables. The class also should have a constructor method with parameters that initialize all its corresponding instance variables.

This class will also implement the Taxable Interface. The getTax method will return the amount a tax assessed for this Boat. A Boat, will pay 100 dollars for every feet of length plus 500 dollars for every cabin in the Boat.

LnFnUnit5.java

This is the Driver class. This class will only contain the main method. This method will declare an Array List of Taxable Objects. Then, using a loop, the method will add at random 20 Taxable Objects to the Array List: either a Terrain, a Building or a Boat. The program will decide which object to add by creating a random number between 0 and 100 at the beginning of each loop. If the random number is less than 20, it will add a Boat, if it is greater than or equal to 20, but less than 60, it will add a Terrain, otherwise it will add a Building.

The parameters for the constructors for each of these Taxable objects will also be created at random. Their descriptions could be the names of the classes followed by a unique number. The areas would be random numbers between 100 and 10000 sqf. The unit prices would be between 10 to 1000 dollars. The fractions would be a decimal number between 0 and 1. The number of trees a number between 0 and 200. The number of stories in a Building an Cabins in a Boat would be number between 1 to 4. Boats have a footage between 10 to 50 feet. You may review the java.util.Random documentation to familiarize yourself with the creation of Random numbers.

After the Array is completely defined, use 3 loops to produce the tables showing in the example below. The first table shows all the attributes of the Terrains, including   its taxes and a summary at the end indicating the total. minimum, maximum, and average value for taxes. Tables 2 and 3 do the same for Buildings and Boats respectively. When using a loop in the Array List, remember that you can identify if an element of the Array List is a Terrrain, Building, or Boat by using the instanceof boolean operation. Remember also, that if you identify an object in either of these classes, you may cast it to use all its methods. For example, if you want to check that you have a Boat on the element i of Array List p, you could say:

If (p.get(i) instanceof Boat) {

     System.out.println( ( (Boat) p.get(i) ).getFootage());

}

This will pint the Footage of the Boat.

Directions

The assignment will consist of 6 files. They must be called <LastnameFirstnameUnit5.java> (driver program)
LastnameFirstnameTaxable.java
LastnameFirstnameRealState.java

LastnameFirstnameTerrain.java (which extends LastnameFirstnameRealState)

LastnameFirstnameBuilding.java (which extends LastnameFirstnameRealState)

LastnameFirstnameBoat.java

The files must be called as specified above, (LastnameFastname = LnFn = Your Last Name Your First Name)

Proper coding conventions required the first letter of the class start with a capital letter and the first letter of each additional word start with a capital letter.

Only submit the .java files needed to make the program run. Do not submit the .class files or any other files.

Style Components

Include properly formatted prologue, comments, indenting, and other style elements as shown in Chapter 2 starting page 64 and Appendix 5 page 881-892.

Compilation

All programs should compile. Even if the program is not fully operational, students should comment out the sections that are not working and present a code that compiles. The commented-out sections will be an indication of the attempts the student made to complete the tasks in the assignment.

Basic Requirements

Write a program that creates an Array List of Taxable element and create and add 20 Taxable elements at random. Then produce three tables that summarizes the taxes owed by each type of Taxable Assets.

Review output details on the sample below. Try to produce an output that is closer to the one shown, except for the actual values.
Remember to use the get and set methods whenever you need to get the value or modify a value of any instance variable everywhere in your program.

LnFnTaxable.java

This is an interface with only the following abstract method:

          public double getTax();

LnFnRealState.java

This is an abstract class. It should be declared as such. However, it contains the following private instance variables:

·       description (String) a String that names and or describe the Real State.

·       area (double) the square feet for this Real State.

·       unitPrice (double) the price for each square feet in the Real State.

The class should provide public accessor (get) and mutator (set) methods for all its instance variables. The class also should have a constructor method with parameters that initialize all its corresponding instance variables.

LnFnTerrain.java

This is a subclass from the LnFnRealState class. It contains the following private instance variables:

·       agroFraction (double) the fraction of the Terrain’s area that can be used for agriculture.

·       numberOfTrees (int) the number of trees inside the Terrain.

The class should provide public accessor (get) and mutator (set) methods for all its instance variables. The set method for the agroFraction should check that the value received is between 0.0 to 1.0. If the value is outside these limits, the instance variable should not be changed.

The class also should have a constructor method with parameters that initialize all its corresponding instance variables and the instance variables for its superclass (LnFnRealState).

This class will also implement the Taxable Interface. The getTax method will return the amount a tax assessed for this Terrain. A Terrain pays 1% of the value obtained by multiplying its area by its unitPrice by the fraction used for agriculture plus 10 dollars per each tree in the Terrain.

LnFnBuilding.java

This is also a subclass from the LnFnRealState class. It contains the following private instance variables:

·       dwellingArea (double) the built area of the Building in square feet.

·       numberOfStories (int) the number of stories in the Building.

The class should provide public accessor (get) and mutator (set) methods for all its instance variables. The class also should have a constructor method with parameters that initialize all its corresponding instance variables and the instance variables for its superclass (LnFnRealState).

This class will also implement the Taxable Interface. The getTax method will return the amount a tax assessed for this Building. A Building, will pay 1% of the value obtained by multiplying its land area (from parent class) by its unitPrice plus 2% of the value obtained by multiplying its dwelling area by its unitPrice by 3.

LnFnBoat.java

This class does not subclass from LnFnRealState class, or any other user class, only from the Object class. It contains the following private instance variables:

·       description (String) a String that names and or describe the Boat.

·       footage (double) the length of the Boat in feet.

·       numberOfCabins (int) the number of cabins in the Boat.

The class should provide public accessor (get) and mutator (set) methods for all its instance variables. The class also should have a constructor method with parameters that initialize all its corresponding instance variables.

This class will also implement the Taxable Interface. The getTax method will return the amount a tax assessed for this Boat. A Boat, will pay 100 dollars for every feet of length plus 500 dollars for every cabin in the Boat.

LnFnUnit5.java

This is the Driver class. This class will only contain the main method. This method will declare an Array List of Taxable Objects. Then, using a loop, the method will add at random 20 Taxable Objects to the Array List: either a Terrain, a Building or a Boat. The program will decide which object to add by creating a random number between 0 and 100 at the beginning of each loop. If the random number is less than 20, it will add a Boat, if it is greater than or equal to 20, but less than 60, it will add a Terrain, otherwise it will add a Building.

The parameters for the constructors for each of these Taxable objects will also be created at random. Their descriptions could be the names of the classes followed by a unique number. The areas would be random numbers between 100 and 10000 sqf. The unit prices would be between 10 to 1000 dollars. The fractions would be a decimal number between 0 and 1. The number of trees a number between 0 and 200. The number of stories in a Building an Cabins in a Boat would be number between 1 to 4. Boats have a footage between 10 to 50 feet. You may review the java.util.Random documentation to familiarize yourself with the creation of Random numbers.

After the Array is completely defined, use 3 loops to produce the tables showing in the example below. The first table shows all the attributes of the Terrains, including   its taxes and a summary at the end indicating the total. minimum, maximum, and average value for taxes. Tables 2 and 3 do the same for Buildings and Boats respectively. When using a loop in the Array List, remember that you can identify if an element of the Array List is a Terrrain, Building, or Boat by using the instanceof boolean operation. Remember also, that if you identify an object in either of these classes, you may cast it to use all its methods. For example, if you want to check that you have a Boat on the element i of Array List p, you could say:

If (p.get(i) instanceof Boat) {

     System.out.println( ( (Boat) p.get(i) ).getFootage());

}

This will pint the Footage of the Boat.

Explanation / Answer

We will now proceed with the implementation of the Java files one by one.

Implementing LnFnTaxable.java:-

public interface LnFnTaxable {

public void getTax(){

}

}

//As this is the interface, so we will be just providing the definition of the function here.
The implementation of this method will be handled by the class which implements it.

Implementing LnFnRealState.java:-

public abstract class LnFnRealState {

private string description;
private double area;
private double unitPrice;

/*Generally acording to the java convention we need to initialize the variable that we declare in the class.
For that we have used the constructor at the bottom. */

/* Setting up the setter methods to set the data for the instance variables.
*/

public void setDescription( String description){
this.description=description;
}

public void setArea(double area) {
this.area= area;
}

public void setunitPrice(double unitPrice) {

this.unitPrice= unitPrice;

}

/* Now setting up the getter methods to get the data for what the user have set.

public String getDescription() {
return description;
}

public double getunitPrice() {
return unitPrice;
}

public double getarea() {
return area;
}

/* Setting up the constructor for this class. */

LnFnRealState(string description, double area, double unitPrice) {
this.description = description;
this.area = area;
this.unitPrice = unitPrice;
}
}

// Implementing the LnFnTerrain.java class.

class LnFnTerrain extends LnFnRealState implements LnFnTaxable {

private double agroFraction;
private int numberOfTrees;

//Implementing the setter methods to set the instance variables.

public void setagroFraction( double agroFraction) {
if(agroFraction > 0.0 && agroFraction <= 1)
this.agroFraction = agroFraction;
   else
   this.agroFraction = agroFraction;
}

public void setnumberOfTrees( int numberOfTrees) {

this.numberOfTrees = numberOfTrees;
}

//Implementing the getter methods to get the values of the instance variables set.

pubic int getnumberOfTrees() {
return numberOfTrees;
}

pulic double getagroFraction() {
return agroFraction;
}

/*Now implementing the constructor for this class to initialize the instance variables for this class
and also the variables of the superclass.
*/
LnFnTerrain(int numberOfTrees, double agroFraction) {
super(); //We will call the constructor of the superclass to initialize its own variable.
this.numberOfTrees = numberOfTrees;
this.agroFraction = agroFraction;
}

public double getTax() {
return ((area*unitPrice)*0.01);
  
}
}

//Implementing LnFnBuilding.java class.

class LnFnBuilding extends LnFnRealState implements LnFnTaxable{

private double dwellingArea;
private int numberOfStories;

//Getter methods

public double getdwellingArea() {
return dwellingArea;
}

public int getnumberOfStories() {
return numberOfStories;
}

//Implementing setter methods

public void setdwelligArea(double dwellingArea) {
this.dwellingArea = dwellingArea;
}

public void setnumberOfStories(int numberOfStories) {
this.numberOfStories = numberOfStories;
}

//Setting up with the constructor

LnFnBuilding(double dwellingArea, int numberOfStories) {
super();
this.dwellingArea = dwellingArea;
this.numberOfStories = numberOfStories;
}

public double getTax() {
return (((area*unitPrice)*0.01) + ((dwellingArea*unitPrice*3)*0.02));
}

//Implementimg the class LnFnBoat.java

class LnFnBoat extends LnFnRealState implements LnFnTaxable{

private string description;
private double footage;
private int numberOfCabins;

//Getter methods

public String getdescription() {
return description;
}

public double getfootage() {
return footage;
}

public int getnumberOfCabins() {
return numberOfCabins;
}

// Setter methods

public void setdescription( String description)
this.description = description;
}

public void setfootage( double footage) {
this.footage = footage;
}

public void setnumberOfCabins( intt numberOfCabins) {
this.numberOfCabins = numberOfCabins;
}

//Constructor for this class

LnFnBoat(string description, double footage, int numberOfCabins) {
this.description = description;
this.footage = footage;
this.numberOfCabins = numberOfCabins;
}

public double getTax() {

return ((footage*100)+(500*numberOfCabins));
}

//Implementing the main driver class of the program.
This is the program which class all other classes.

public class LnFnUnit5 {

public static void main(String[] args) {
ArrayList<LnFnTerrain> list = new ArrayList<LnFnTerrain>();
ArrayList<LnFnBuilding> list1 = new ArrayList<LnFnBuilding>();
ArrayList<LnFnBoat> list2 = new ArrayList<LnFnBoat>();
  
//This has been used to create the random number from 1 to 100 and it is stored in the variable.
for(int i=0; i < 20 ; i++){
int a= (int)(Math.random()*100));
   if(a<20)
   list2.add( new LnFnBoat( ) );
   else if(a >= 20 && a< 60)
list.add(new LnFnTerrain( ));
else
list1.add(new LnFnBuilding( ));
}     

There has been a slight confusion after reaching this far. The problem is, do we need to define the parameter of the super class
in the constructor itself??, because according to my implementation the superclass instance variable has been called by using the
super() method which creates an ambiguity while calling the objects of the class.
Please do make sure, and let me know, the rest will be implemented accordingly.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote