Answer to Question #196597 in Java | JSP | JSF for Vinit

Question #196597

Create an Investment class that contains fields to hold the initial value of an investment, the

current value, the profit (calculated as the difference between current value and initial value),

and the percent profit (the profit divided by the initial value). Include a constructor that requires

initial and current values and a display function. Create a House class that includes fields for

street address and square feet, a constructor that requires values for both fields, and a display

function. Create a HouseThatIsAnInvestment class that inherits from Investment and House. It

includes a constructor and a display function that calls the display functions of the parents


1
Expert's answer
2021-05-21T11:52:43-0400
import java.util.Scanner;


class Investment {
	// contains fields to hold the initial value of an investment, the
	// current value, the profit (calculated as the difference between current value
	// and initial value),
	// and the percent profit (the profit divided by the initial value).


	private double initialValue;
	private double currentValue;
	private double profit;
	private double percentProfit;


	/**
	 * Constructor
	 * 
	 * @param initialValue
	 * @param currentValue
	 */
	public Investment(double initialValue, double currentValue) {
		this.initialValue = initialValue;
		this.currentValue = currentValue;
	}


	public double calculateProfit() {
		profit = currentValue - initialValue;
		return profit;
	}


	public double calculatePercentProfit() {
		profit = calculateProfit();
		percentProfit = profit / initialValue;
		return percentProfit;
	}


	public void display() {
		System.out.println("The initial value of an investment: " + initialValue);
		System.out.println("The current value of an investment: " + currentValue);
		System.out.println("The profit: " + profit);
		System.out.println("The percent profit: " + calculatePercentProfit());
	}
}


class House extends Investment {
	private String streetAddress;
	private double squareFeet;


	/**
	 * Constructor
	 * @param initialValue
	 * @param currentValue
	 * @param streetAddress
	 * @param squareFeet
	 */
	public House (double initialValue,double currentValue,String streetAddress,double squareFeet) {
		super(initialValue, currentValue);
		this.streetAddress=streetAddress;
		this.squareFeet=squareFeet;
		
	}


	public void display() {
		super.display();
		System.out.println("The street address: " + streetAddress);
		System.out.println("The square feet: " + squareFeet);
	}


}


class HouseThatIsAnInvestment extends House {


	public HouseThatIsAnInvestment(double initialValue, double currentValue, String streetAddress, double squareFeet) {
		super(initialValue, currentValue, streetAddress, squareFeet);
		
	}


}


public class MusicDemo {


	public static void main(String[] args) {
		HouseThatIsAnInvestment houseThatIsAnInvestment=new HouseThatIsAnInvestment(20, 150, "Street Address",25.5);
		houseThatIsAnInvestment.calculateProfit();
		houseThatIsAnInvestment.calculatePercentProfit();
		houseThatIsAnInvestment.display();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS