Results 1 to 2 of 2
  1. #1
    jnicholas2012 is offline Member
    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    Default When compiled and ran program isn't displaying a name and address

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author OWNER
    */
    public final class Address {
    private String street;
    private String city;
    private String state;
    private String zip;

    /** Create an address with street, city, state and zip */
    public Address(String street, String city, String state, String zip) {
    this.street = street;
    this.city = city;
    this.state = state;
    this.zip = zip;
    }

    /** Return street */
    public String getStreet() {
    return street;
    }

    /** Return city */
    public String getCity() {
    return city;
    }

    /** Return state */
    public String getState() {
    return state;
    }

    /** Return state */
    public String getZip() {
    return zip;
    }

    /** Get full address */
    public String getFullAddress() {
    return street + '\n' + city + '\n' + state + '\n' + zip + '\n';
    }

    }


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author OWNER
    */
    public class Loan {
    private double annualInterestRate;
    private int numberOfYears;
    private double loanAmount;
    private java.util.Date loanDate;

    /** Default constructor */
    public Loan() {
    this(2.5, 1, 1000);
    }

    /** Construct a loan with specified annual interest rate,
    * number of years and loan amount */
    public Loan(double annualInterestRate, int numberOfYears, double loanAmount)
    {
    this.annualInterestRate = annualInterestRate;
    this.numberOfYears = numberOfYears;
    this.loanAmount = loanAmount;
    loanDate = new java.util.Date();
    }

    /**Return annual interest rate */
    public double getAnnualInterestRate() {
    return annualInterestRate;

    }

    //** Set a new annualInterestRate */
    public void setAnnualInterestRate(double annualInterestRate) {
    this.annualInterestRate = annualInterestRate;
    }

    //** return number of years */
    public int getNumberOfYears() {
    return numberOfYears;
    }

    //** Set a new numberOfYears */
    public void setNumberOfYears(int numberOfYears) {
    this.numberOfYears = numberOfYears;
    }

    //** Return loanAmount */
    public double getLoanAmount() {
    return loanAmount;
    }

    //** Set a new loanAmount */
    public void setLoanAmount(double loanAmount) {
    this.loanAmount = loanAmount;
    }

    //** Find monthly payment */
    public double getMonthlyPayment() {
    double monthlyInterestRate = annualInterestRate / 1200;
    double monthlyPayment = loanAmount * monthlyInterestRate / (1 -
    (Math.pow(1 / (1 + monthlyInterestRate), numberOfYears * 12
    )));
    return monthlyPayment;
    }

    /** Find total payment */
    public double getTotalPayment() {
    double totalPayment = getMonthlyPayment() * numberOfYears * 12;
    return totalPayment;
    }

    /** Return loan date */
    public java.util.Date getLoanDate() {
    return loanDate;
    }




    }




    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author OWNER
    */
    public final class Name implements Comparable {
    private String firstName;
    private char mi;
    private String lastName;

    /** Construct a name with firstName, mi, and lastName */
    public Name(String firstName, char mi, String lastName) {
    this.firstName = firstName;
    this.mi = mi;
    this.lastName = lastName;
    }

    /** Return firstName */
    public String getFirstName() {
    return firstName;
    }

    /** Return mi */
    public char getMi() {
    return mi;
    }

    /** Return lastName */
    public String getLastName() {
    return lastName;
    }

    /** Return full name */
    public String getFullName() {
    return firstName + ' ' + mi + ' ' + lastName;
    }

    /** Implement compareTo in the Comparable interface */
    public int compareTo(Object o) {
    if (!lastName.equals(((Name)o).lastName)) {
    return lastName.compareTo(((Name)o).lastName);
    }
    else if (!firstName.equals(((Name)o).firstName)) {
    return firstName.compareTo(((Name)o).firstName);

    }
    else {
    return mi - ((Name)o).mi;
    }
    }

    }



    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author OWNER
    */
    public class Borrower extends Person1 {
    private Loan loan;

    /** Construct a borrower with default properties */
    public Borrower() {
    super();
    }

    /** Create a borrower with specified name and address */
    public Borrower(Name name, Address address) {
    super(name, address);
    }

    /** Return loan */
    public Loan getLoan() {
    return loan;
    }

    /** Set a new loan */
    public void setLoan(Loan loan) {
    this.loan = loan;
    }

    /** String representation for borrower */
    public String toString() {
    return super.toString() +
    "Monthly payment is " + loan.getMonthlyPayment() + '\n' +
    "Total payment is " + loan.getTotalPayment();
    }


    }





    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author OWNER
    */
    public class Person1 implements Comparable {
    private Name name;
    private Address address;

    /** Construct a person with default properties */
    public Person1() {
    this(new Name("Jill", 'S', "Barr"),
    new Address("100 Main", "Savannah", "GA", "31411"));
    }

    /** Construct a person with specified name and address */
    public Person1(Name name, Address address) {
    this.name = name;
    this.address = address;
    }

    /** Return name */
    public Name getName() {
    return name;
    }

    /** Set a new name */
    public void setName(Name name) {
    this.name = name;
    }

    /** Return address */
    public Address getAddress() {
    return address;
    }

    /** Set a new address */
    public void setAddress(Address address) {
    this.address = address;
    }

    /** Override the toString method */
    public String toSting() {
    return '\n' + name.getFullName() + '\n' + address.getFullAddress() +
    '\n';
    }

    /** Implement compareTo in the Comparable interface */
    public int compareTo(Object o) {
    return name.compareTo(((Person1)o).name);
    }

    }


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author OWNER
    */
    public class BorrowLoan {

    /** Main method */
    public static void main(String[] args) {
    //Create a name
    Name name = new Name("John", 'D', "Smith");

    //Create an address
    Address address = new Address("100 Main Street", "Savannah",
    "GA", "31419");

    //Create a loan
    Loan loan = new Loan(5.5, 15, 250000);

    //Create a borrower
    Borrower borrower = new Borrower(name, address);

    borrower.setLoan(loan);

    //Display information
    System.out.println(borrower);
    }
    }




    The BorrowLoan class when ran should produce an output that displays a person's name and address. When I run the file I'm getting correct output for the loan amount, and etc. However, in place of a name and address I'm getting something similar to the following:

    Borrower88eeikdccccc2


    I apologize that I couldn't just upload the java files as attachments. However, they should be easy to copy and past into a notepad doc. for compilation. the comment blocks should make it easy to tell when the separate classes begin.

    Thanks
    Last edited by jnicholas2012; 10-01-2012 at 09:37 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Please have a look at the following and tell me what I've done wrong

    Forum Rules -- particularly the third paragraph.
    Guide For New Members
    BB Code List - Java Programming Forum

    Edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 02:37 AM
  2. I can't find anything wrong with this but somehow it's wrong.
    By Biscuit Tickler in forum New To Java
    Replies: 2
    Last Post: 09-12-2012, 10:28 PM
  3. What am I doing wrong?
    By javajen in forum New To Java
    Replies: 3
    Last Post: 04-11-2011, 06:35 PM
  4. Please help, what am I doing wrong?
    By mmac1218 in forum New To Java
    Replies: 2
    Last Post: 09-02-2009, 12:21 AM
  5. what is wrong?
    By pinguxxx in forum Advanced Java
    Replies: 3
    Last Post: 07-15-2009, 01:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •