Question

In: Computer Science

Java Program using inheritance, create a program that will take input from the user to answer...

Java Program

using inheritance, create a program that will take input from the user to answer this information: (Create a method for home, car, and personal loan) Thanks!

montly income= 80,000
extra income=30,000
any libality=40,000
total income=80,000+30,000-40,000=?

eligibility for homeloan=total_income*80% for home loan
eligibility for car loan=total_income*60% for carloan
eligibility for personal loan=total_income*70% for personal loan

Solutions

Expert Solution

PersonIncome.java

//super class
public class PersonIncome {
   //member variables
   private double monthlyIncome;
   private double extraIncome;
   private double liability;
  
   //constructor
   public PersonIncome(double monthlyIncome, double extraIncome, double liability)
   {
       this.monthlyIncome = monthlyIncome;
       this.extraIncome = extraIncome;
       this.liability = liability;
   }
  
   //method that calculates and returns total income
   public double getTotalIncome()
   {
       return this.monthlyIncome + this.extraIncome - this.liability;
   }
}

LoanEligibility.java


public class LoanEligibility extends PersonIncome{
   //constructor
   public LoanEligibility(double monthlyIncome, double extraIncome, double liability)
   {
       //call the super class constructor
       super(monthlyIncome, extraIncome, liability);
   }

   //method that calculates and returns the eligibility for home loan
   public double getEligibleHomeAmount()
   {
       return getTotalIncome() * 80 / 100;
   }

   //method that calculates and returns the eligibility for car loan
   public double getEligibleCarAmount()
   {
       return getTotalIncome() * 60 / 100;
   }

   //method that calculates and returns the eligibility for personal loan
   public double getEligiblePersonalAmount()
   {
       return getTotalIncome() * 70 / 100;
   }
}

TestLoan.java

import java.util.Scanner;

public class TestLoan {

   public static void main(String[] args) {
       //create object to Scanner class to read input from user
       Scanner input = new Scanner(System.in);
      
       double monthlyIncome, extraIncome, liability;
      
       //prompt and read monthly income
       System.out.print("Enter monthly income: $");
       monthlyIncome = input.nextDouble();
      
       //prompt and read extraIncome
       System.out.print("Enter extra income: $");
       extraIncome = input.nextDouble();
      
       //prompt and read extraIncome
       System.out.print("Enter liabilities if any: $");
       liability = input.nextDouble();
      
       //create an object LoanEligibility class
       LoanEligibility loanObj = new LoanEligibility(monthlyIncome, extraIncome, liability);
      
       //get and display home loan
       System.out.println("\nEligibility for home loan: " + loanObj.getEligibleHomeAmount());
       //get and display car loan
       System.out.println("Eligibility for car loan: " + loanObj.getEligibleCarAmount());
       //get and display personal loan
       System.out.println("Eligibility for personal loan: " + loanObj.getEligiblePersonalAmount());
      
       input.close();
   }

}

Output:

Program Screenshot:


Related Solutions

Program using java Take user input and give corresponding output. A user is considering different options...
Program using java Take user input and give corresponding output. A user is considering different options of operating air conditioning. Depending on room temperature (here, room temperature is given by user), this program should give different instructions. There are three scenarios. - If temperature is above 90, the program should output “cooling”. -If the temperature is below 70, the program should output “heating”. -Otherwise, the program should output “stopped”. For example, if user enters “95”, this is how the program...
JAVA Take in a user input. if user input is "Leap Year" your program should run...
JAVA Take in a user input. if user input is "Leap Year" your program should run exercise 1 if user input is "word count" your program should run exercise 2 Both exercises should run in separate methods Exercise 1: write a java method to check whether a year(integer) entered by the user is a leap year or not. Exercise 2: Write a java method to count all words in a string.
(JAVA) Create a program that prompts the user for an age input. The program defines the...
(JAVA) Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program. Age Age Group 0 Baby 1-3 Toddler 4-11 Child 12-17 Teenager 18-21 Young Adult 22-64 Adult 65+ Senior Negative Number Invalid Input Sample Input Enter an age: 18 Sample Output: You are a young adult. Sample Input Enter an age: 29 Sample Output: You are an adult. Sample...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
IN JAVA Create a program that asks the user to input the day, high and low...
IN JAVA Create a program that asks the user to input the day, high and low temperature. Display the day, high, and low. Use a While Loop to enter all seven days of the week and high temperatures. Inside the While Loop, the program will count, total, and average the highs. The following will be displayed:                         Day: (variable)                         High: (variable)                         Count High: (variable)                         Total High: (variable)                         Average High: (variable) After the seven days and highs...
create a program using IDLE where you will gather input from the user using a loop....
create a program using IDLE where you will gather input from the user using a loop. The user needs to provide you with a list of test scores for two categories (two different classrooms). Test scores must be integer values between 0 and 10. You need to process each score so that you can output the following: Number of test scores entered for classroom A. Number of test scores entered for classroom B. Average of test scores entered for classroom...
create a program using IDLE where you will gather input from the user using a loop....
create a program using IDLE where you will gather input from the user using a loop. The user needs to provide you with a list of test scores for two categories (two different classrooms). Test scores must be integer values between 0 and 10. You need to process each score so that you can output the following: Number of test scores entered for classroom A. Number of test scores entered for classroom B. Average of test scores entered for classroom...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles, and the class of journey (1,2, or 3, for first, second, and third class respectively), for a train journey. The program should then calculate and display the fare of journey based on the following criteria: Note: Use Switch...case and if...else construct First (1) Class Second (1) Class Third (3) Class First 100 mile $ 3 per mile $ 2 per mile $ 1.50...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Using C++ Create a program that asks the user to input a string value and then...
Using C++ Create a program that asks the user to input a string value and then outputs the string in the Pig Latin form. - If the string begins with a vowel, add the string "-way" at the end of the string. For “eye”, it will be “eye-way”. - If the string does not begin with a vowel, first add "-" at the end of the string. Then rotate the string one character at a time; that is, move the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT