What is the default value for HashMap in Java?

Did I do this Java program right?

  • Java program using clients? Java program encapsulating? How do start this Java Program? Write a class encapsulating the concept of an investment, assuming that the investment has the following attributes: the name of the investor, the amount of the investment, and the static interest rate at which the investment will be compounded. Include a default constructor, an overloaded constructor, the accessors and mutators, and methods, toString() and equals(). Also include a method returning the future value of the investment depending on how many years we hold it before selling it, which can be calculated using the formula: Future value = investment(1 + interest rate)year We will assume that the interest rate is compounded annually. Write a client class to test all the methods in your class and print out the future value for 5, 10, and 20 years. I am using java unlimited Third edition import java.text.DecimalFormat; public class Investment { // instance variables private String model; private int investmentAmount; private double interestRate; private static int countInvestment = 0; // static class variable //Constructors public Investment( ) { model = "unknown"; countInvestment++; // increment static count of Investment objects } // allows client to set beginning values for // model, investmentAmount, and interestRate; // increments countInvestments public Investment( String startModel, int startInvestmentAmount, double startInterestRate ) { model = startModel; setInvestmentAmount( startInvestmentAmount ); setInteretRate( startInvestmentRate ); countInvestment++; // increment static count of Investment objects } // Accessor Methods // returns current value of model public String getModel( ) { return model; } // returns current value of milesDriven public int getInvestmentAmount( ) { return investmentAmount; } // returns current value of gallonsOfGas public double getInterestRate( ) { return interestRate; } // returns countAutos public static int getCountInvestment( ) { return countInvestments; } // Mutator Methods: // allows client to set model public void setModel( String newModel ) { model = newModel; } // allows client to set value of InvestmentAmount; // prints an error message if new value is less than 0 public void setInvestmentAmount( int newInvestmentAmount ) { if ( newInvestmentAmount >= 0 ) investmentAmount = newInvestmentAmount; else { System.err.println( "Amount cannot be negative." ); System.err.println( "Value not changed." ); } } // allows client to set value of InterestRate; // prints an error message if new value is less than 0.0 public void setInterestRate( double newInterestRate ) { if ( newGallonsOfGas >= 0.0 ) interestRate = newInterestRate; else { System.err.println( "Interest rate cannot be negative." ); System.err.println( "Value not changed." ); } } public double calculateAmount/Rate( ) { if ( interestrate != 0.0 ) return investmentAmount / interestRate; else return 0.0; } // toString: returns a String with values of instance variable public String toString( ) { DecimalFormat rateFormat = new DecimalFormat( "#0.0" ); return "Model: " + model + "\n investment amount: " + investmenAmount + "\n interest rate: " + rateFormat.format( interestRate ); } public boolean equals( Object o ) { if ( ! ( o instanceof Investment ) ) return false; else { Investment objInvestment = ( Investment ) o; if ( model.equals( objInvestment.model ) && investmentAmount == objInvestment.investmentAmount && Math.abs( interestRate - objInvestement.interestRate ) < 0.0001 ) return true; else return false; } } }

  • Answer:

    Yes, I believe you performed the right codings for your Java program! I don't think there are any mistakes for your work! Good luck!

KnightHu... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.