Question

Design an application that declares an array of 20 AutomobileLoan objects. Prompt the user for data...

Design an application that declares an array of 20 AutomobileLoan objects. Prompt the user for data for each object, and then pass the array to a method that determines the sum of the balances.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class AutomobileLoan{

   private String username;
   private double loanAmount, repaid;
   private String carModel, color;
   private int yearMake;

   public AutomobileLoan(){

   }
  
   public AutomobileLoan(String username, double loanAmount, double repaid, String carModel, String color, int yearMake) {
       this.username = username;
       this.loanAmount = loanAmount;
       this.carModel = carModel;
       this.color = color;
       this.yearMake = yearMake;
       this.repaid = repaid;
   }

   public String getUsername() {
       return username;
   }


   public void setUsername(String username) {
       this.username = username;
   }


   public double getLoanAmount() {
       return loanAmount;
   }

   public void setLoanAmount(double loanAmount) {
       this.loanAmount = loanAmount;
   }

   public String getCarModel() {
       return carModel;
   }

   public void setCarModel(String carModel) {
       this.carModel = carModel;
   }

   public String getColor() {
       return color;
   }


   public void setColor(String color) {
       this.color = color;
   }

   public int getYearMake() {
       return yearMake;
   }

   public void setYearMake(int yearMake) {
       this.yearMake = yearMake;
   }
  
   public double getRepaid() {
       return this.repaid;
   }
  
   public static void totalLoan(AutomobileLoan[] cars, int count) {
       double amount = 0.0;
       for(int i = 0 ; i < count ; i++)
       {
           amount += (cars[i].getLoanAmount() - cars[i].getRepaid());
       }
       System.out.println("Total loan amount is: " + amount);
   }
  
   public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       AutomobileLoan[] loan = new AutomobileLoan[20];
      
       int count;
       String name, color, model;
       int year;
       double loanAmount, repaid;
      
       System.out.print("Enter the number of loan information you want to insert: ");
       count = scanner.nextInt();
      
       for(int i = 0 ; i < count ; i++)
       {
           System.out.println("Applicant " + (i+1));
          
           System.out.print("Enter applicant's name: ");
           name = scanner.next();
          
           System.out.print("Enter car model: ");
           model = scanner.next();
          
           System.out.print("Enter car color: ");
           color = scanner.next();
          
           System.out.print("Enter year make: ");
           year = scanner.nextInt();
          
           System.out.print("Enter loan amount: ");
           loanAmount = scanner.nextDouble();
          
           System.out.print("Enter amount repaid against loan: ");
           repaid = scanner.nextDouble();
          
           loan[i] = new AutomobileLoan(name, loanAmount, repaid, model, color, year);
          
           System.out.println("---------------------------");
       }
      
       AutomobileLoan.totalLoan(loan, count);
      
       scanner.close();
   }
}

Output:

<terminated> AutomobileLoan [Java Application] C\Program FilesJava\jdk-12.0.1\bin\javaw.exe (Aug 14, 2019, 10:46:20 PM) Enter

Add a comment
Know the answer?
Add Answer to:
Design an application that declares an array of 20 AutomobileLoan objects. Prompt the user for data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a class named StockTransaction that holds a stock symbol (typically one to four characters), stock...

    Design a class named StockTransaction that holds a stock symbol (typically one to four characters), stock name, and price per share. Include methods to set and get the values for each data field. Design an application that declares two StockTransaction objects and sets and displays their values. Design an application that declares an array of 15 StockTransaction objects. Prompt the user for data for each object, and then display all the values. Design an application that declares an array of...

  • Write a console application in c# that uses a one dimensional array; prompt the user to...

    Write a console application in c# that uses a one dimensional array; prompt the user to enter letters, ( a, b, c, … z). As each letter is input, store it in the array only if it is not a duplicate of previous letters entered. After 7 unique letters have been entered, display the unique values in the array. Be sure to test with duplicate values.

  • create a new Java application called "MinMax" (without the quotation marks) that declares an array of...

    create a new Java application called "MinMax" (without the quotation marks) that declares an array of doubles of length 5, and uses methods to populate the array with user input from the command line and to print out the max (highest) and min (lowest) values in the array.

  • create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array...

    create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...

  • a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number,...

    a. Create a class named Lease with fields that hold an apartment tenant's name, apartment Number, monthly rent amount, and term of the lease in months. Include a constructor that initializes the name. "XXX", the apartment number to O, the rent to 1000, and the term to 12. Also include methods to get and set each of the fields. Include a nonstatic method named addPetFee() that adds $10 to the monthly rent value and calls a static method named explainPetPolicy...

  • Three C Code Questions: 5. Write a C program that declares an array of 10 strings,...

    Three C Code Questions: 5. Write a C program that declares an array of 10 strings, each of max length 50 characters, and then reads an entire line of text from the keyboard into each string. 6. Write C code that finds the longest name in this array of strings that you read in Q5. Hint: find the position of the longest string, not the string itself. 7. Write a C program that creates a 4 x 6 two dimensional...

  • JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate...

    JAVA I. Using the Event Class created previously, create an array of objects;        II. Demonstrate passing array reference to a method;        III. Demonstrate creating array of objects that prints out only x 0.0 for all objects. PROJECT 5C - ARRAYS Create a new file called " EventArray5C". There are some "challenging" directions in this project. . 1.Prepare a document box (tell me that task(s) the application is to accomplish, how it will accomplish the tasks, the author of...

  • Create an application that instantiates a 20?20 two-dimensional array of Date objects, populates it with random...

    Create an application that instantiates a 20?20 two-dimensional array of Date objects, populates it with random dates drawn from the range of 1/1/1970 to 12/31/2020, and then outputs the index and actual date of the row with the most recent date (relative to today) among all the rows and the index and actual date of the column with the oldest date (closest to 1/1/1970) among all the columns.

  • Using Matlab Prompt the user for a number between 1 and 20. integers. Fill up each...

    Using Matlab Prompt the user for a number between 1 and 20. integers. Fill up each slot of the array with a random number from 1 to 100. Then display the contents of the array on the screen. You must use a loop. 7. Create an array that holds this number of

  • C++ Create an application named CarDemo that declares at least two Car objects and demonstrates how...

    C++ Create an application named CarDemo that declares at least two Car objects and demonstrates how they can be incremented using an overloaded ++ operator. Create a Car class that contains the following properties: Model - The car model (as a string) Mpg The car's miles per gallon (as a double) Include two overloaded constructors. One accepts parameters for the model and miles per gallon; the other accepts a model and sets the miles per gallon to 20. Overload a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT