Question by ivan i: How to write a java program that..?
i need help to write a java program “In 1629 the Dutch bough Mangattan from the Indians for $ 24. Write a program that will print out the anount of money the indians would have if they invested 3% compounded quartely. The table should be printed out by the year until the year 2000.

Best answer:

Answer by Gizmo L
Your question is a little unclear. I interpreted it to mean 3% quarterly, which equates to a nominal interest rate of 12% anually. One could also interpret it to mean 3% annually, which would return a different result.

Here’s a java program:

/*
* cindians.java
*
* Created on November 6, 2007, 10:57 PM
*/
import java.util.*; // For Locale
import java.text.*; // For NumberFormat

/**
*
* @author David
*/
public class cindians {

/** Creates a new instance of cindians */
public cindians() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int year1 = 1629;
int endYear = 2000;
Double pv = new Double(24.00);
Double nominalInterest = new Double(0.12);

for (int x = 1; x <= endYear - year1; x++) { // Calculate the Future value at this point // fv = pv(1+i/n)^ Double fv = new Double(0.0); fv = pv * Math.pow(1 + (nominalInterest/4), (double)x * 4); NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US); System.out.println((year1 + x) + " value => ” + n.format(fv));
}
}
}

On one hand the effect of compound interest is impressive… on the other, it’s 371 years.

Results are:
1630 value => $ 27.01
1631 value => $ 30.40
1632 value => $ 34.22
1633 value => $ 38.51
1634 value => $ 43.35
1635 value => $ 48.79
1636 value => $ 54.91
1637 value => $ 61.80
1638 value => $ 69.56
1639 value => $ 78.29
1640 value => $ 88.11
1641 value => $ 99.17
1642 value => $ 111.62
1643 value => $ 125.63
1644 value => $ 141.40
1645 value => $ 159.15
1646 value => $ 179.12
1647 value => $ 201.60
1648 value => $ 226.90
1649 value => $ 255.38
1650 value => $ 287.43
1651 value => $ 323.51
1652 value => $ 364.11
1653 value => $ 409.81
1654 value => $ 461.25
1655 value => $ 519.14
1656 value => $ 584.29
1657 value => $ 657.63
1658 value => $ 740.17
1659 value => $ 833.06
1660 value => $ 937.62
1661 value => $ 1,055.30
1662 value => $ 1,187.75
1663 value => $ 1,336.82
1664 value => $ 1,504.61
1665 value => $ 1,693.45
1666 value => $ 1,905.99
1667 value => $ 2,145.21
1668 value => $ 2,414.45
1669 value => $ 2,717.49
1670 value => $ 3,058.55
1671 value => $ 3,442.43
1672 value => $ 3,874.48
1673 value => $ 4,360.77
1674 value => $ 4,908.08
1675 value => $ 5,524.09
1676 value => $ 6,217.41
1677 value => $ 6,997.75
1678 value => $ 7,876.03
1679 value => $ 8,864.54
1680 value => $ 9,977.12
1681 value => $ 11,229.33
1682 value => $ 12,638.71
1683 value => $ 14,224.98
1684 value => $ 16,010.34
1685 value => $ 18,019.78
1686 value => $ 20,281.43
1687 value => $ 22,826.92
1688 value => $ 25,691.90
1689 value => $ 28,916.46
1690 value => $ 32,545.73
1691 value => $ 36,630.51
1692 value => $ 41,227.96
1693 value => $ 46,402.43
1694 value => $ 52,226.35
1695 value => $ 58,781.22
1696 value => $ 66,158.78
1697 value => $ 74,462.29
1698 value => $ 83,807.96
1699 value => $ 94,326.60
1700 value => $ 106,165.41
1701 value => $ 119,490.11
1702 value => $ 134,487.17
1703 value => $ 151,366.49
1704 value => $ 170,364.32
1705 value => $ 191,746.55
1706 value => $ 215,812.43
1707 value => $ 242,898.79
1708 value => $ 273,384.73
1709 value => $ 307,696.92
1710 value => $ 346,315.59
1711 value => $ 389,781.25
1712 value => $ 438,702.23
1713 value => $ 493,763.23
1714 value => $ 555,734.86
1715 value => $ 625,484.48
1716 value => $ 703,988.30
1717 value => $ 792,345.03
1718 value => $ 891,791.31
1719 value => $ 1,003,718.98
1720 value => $ 1,129,694.55
1721 value => $ 1,271,481.17
1722 value => $ 1,431,063.26
1723 value => $ 1,610,674.31
1724 value => $ 1,812,828.12
1725 value => $ 2,040,354.02
1726 value => $ 2,296,436.43
1727 value => $ 2,584,659.43
1728 value => $ 2,909,056.96
1729 value => $ 3,274,169.24
1730 value => $ 3,685,106.32
1731 value => $ 4,147,619.63
1732 value => $ 4,668,182.44
1733 value => $ 5,254,080.46
1734 value => $ 5,913,513.84
1735 value => $ 6,655,711.93
1736 value => $ 7,491,062.41
1737 value => $ 8,431,256.74
1738 value => $ 9,489,453.74
1739 value => $ 10,680,463.79
1740 value => $ 12,020,956.09
1741 value => $ 13,529,691.99
1742 value => $ 15,227,787.53
1743 value => $ 17,139,009.02
1744 value => $ 19,290,105.64
1745 value => $ 21,711,183.85
1746 value => $ 24,436,128.70
1747 value => $ 27,503,078.13
1748 value => $ 30,954,956.74
1749 value => $ 34,840,076.52
1750 value => $ 39,212,813.07
1751 value => $ 44,134,366.57
1752 value => $ 49,673,618.40
1753 value => $ 55,908,095.13
1754 value => $ 62,925,053.62
1755 value => $ 70,822,702.22
1756 value => $ 79,711,575.30
1757 value => $ 89,716,080.25
1758 value => $ 100,976,238.73
1759 value => $ 113,649,646.29
1760 value => $ 127,913,678.15
1761 value => $ 143,967,971.68
1762 value => $ 162,037,220.48
1763 value => $ 182,374,319.20
1764 value => $ 205,263,902.97
1765 value => $ 231,026,331.17
1766 value => $ 260,022,171.08
1767 value => $ 292,657,244.34
1768 value => $ 329,388,306.82
1769 value => $ 370,729,441.23
1770 value => $ 417,259,252.23
1771 value => $ 469,628,964.44
1772 value => $ 528,571,536.91
1773 value => $ 594,911,921.51
1774 value => $ 669,578,608.83
1775 value => $ 753,616,623.23
1776 value => $ 848,202,148.81
1777 value => $ 954,658,991.14
1778 value => $ 1,074,477,105.08
1779 value => $ 1,209,333,447.91
1780 value => $ 1,361,115,449.85
1781 value => $ 1,531,947,430.23
1782 value => $ 1,724,220,329.18
1783 value => $ 1,940,625,170.88
1784 value => $ 2,184,190,726.73
1785 value => $ 2,458,325,905.66
1786 value => $ 2,766,867,464.67
1787 value => $ 3,114,133,707.59
1788 value => $ 3,504,984,923.41
1789 value => $ 3,944,891,410.21
1790 value => $ 4,440,010,036.68
1791 value => $ 4,997,270,412.78
1792 value => $ 5,624,471,875.53
1793 value => $ 6,330,392,647.51
1794 value => $ 7,124,912,695.53
1795 value => $ 8,019,152,009.30
1796 value => $ 9,025,626,235.20
1797 value => $ 10,158,421,843.48
1798 value => $ 11,433,393,280.54
1799 value => $ 12,868,384,865.44
1800 value => $ 14,483,480,536.52
1801 value => $ 16,301,284,943.32
1802 value => $ 18,347,239,818.02
1803 value => $ 20,649,980,054.37
1804 value => $ 23,241,734,477.52
1805 value => $ 26,158,776,914.13
1806 value => $ 29,441,933,875.67
1807 value => $ 33,137,155,960.51
1808 value => $ 37,296,160,971.90
1809 value => $ 41,977,157,753.05
1810 value => $ 47,245,660,869.81
1811 value => $ 53,175,407,543.25
1812 value => $ 59,849,389,665.27
1813 value => $ 67,361,015,341.38
1814 value => $ 75,815,416,217.27
1815 value => $ 85,330,918,886.35
1816 value => $ 96,040,700,971.98
1817 value => $ 108,094,655,062.54
1818 value => $ 121,661,486,586.80
1819 value => $ 136,931,074,991.14
1820 value => $ 154,117,131,265.30
1821 value => $ 173,460,189,011.03
1822 value => $ 195,230,970,916.17
1823 value => $ 219,734,177,751.01
1824 value => $ 247,312,752,916.87
1825 value => $ 278,352,682,233.29
1826 value => $ 313,288,396,140.69
1827 value => $ 352,608,849,927.12
1828 value => $ 396,864,367,076.94
1829 value => $ 446,674,341,520.17
1830 value => $ 502,735,906,581.90
1831 value => $ 565,833,691,961.27
1832 value => $ 636,850,805,297.23
1833 value => $ 716,781,192,017.63
1834 value => $ 806,743,546,458.15
1835 value => $ 907,996,968,949.29
1836 value => $ 1,021,958,588,005.72
1837 value => $ 1,150,223,394,255.60
1838 value => $ 1,294,586,563,702.78
1839 value => $ 1,457,068,582,755.10
1840 value => $ 1,639,943,526,665.08
1841 value => $ 1,845,770,887,164.02
1842 value => $ 2,077,431,394,744.62
1843 value => $ 2,338,167,336,955.66
1844 value => $ 2,631,627,936,997.83
1845 value => $ 2,961,920,427,733.19
1846 value => $ 3,333,667,535,932.67
1847 value => $ 3,752,072,181,303.21
1848 value => $ 4,222,990,295,812.68
1849 value => $ 4,753,012,782,481.68
1850 value => $ 5,349,557,760,725.75
1851 value => $ 6,020,974,389,300.70
1852 value => $ 6,776,659,719,942.31
1853 value => $ 7,627,190,217,167.21
1854 value => $ 8,584,469,784,967.50
1855 value => $ 9,661,896,372,159.73
1856 value => $ 10,874,549,488,172.82
1857 value => $ 12,239,401,253,719.50
1858 value => $ 13,775,553,940,186.34
1859 value => $ 15,504,507,322,309.94
1860 value => $ 17,450,459,585,969.35
1861 value => $ 19,640,646,002,557.46
1862 value => $ 22,105,720,109,969.71
1863 value => $ 24,880,182,735,165.08
1864 value => $ 28,002,864,862,838.19
1865 value => $ 31,517,471,108,363.83
1866 value => $ 35,473,191,401,383.96
1867 value => $ 39,925,389,441,073.90
1868 value => $ 44,936,377,558,609.66
1869 value => $ 50,576,288,831,701.47
1870 value => $ 56,924,058,657,184.61
1871 value => $ 64,068,529,519,618.06
1872 value => $ 72,109,694,418,075.20
1873 value => $ 81,160,096,353,951.47
1874 value => $ 91,346,403,466,821.25
1875 value => $ 102,811,181,863,721.88
1876 value => $ 115,714,890,954,131.20
1877 value => $ 130,238,129,217,063.98
1878 value => $ 146,584,161,831,723.94
1879 value => $ 164,981,765,548,071.06
1880 value => $ 185,688,430,613,708.47
1881 value => $ 208,993,964,570,802.62
1882 value => $ 235,224,548,361,266.25
1883 value => $ 264,747,301,508,876.25
1884 value => $ 297,975,420,271,966.50
1885 value => $ 335,373,960,679,550.94
1886 value => $ 377,466,347,389,428.25
1887 value => $ 424,841,699,465,322.00
1888 value => $ 478,163,075,603,592.25
1889 value => $ 538,176,754,208,539.25
1890 value => $ 605,722,678,198,915.50
1891 value => $ 681,746,210,729,674.40
1892 value => $ 767,311,366,360,365.20
1893 value => $ 863,615,702,851,728.80
1894 value => $ 972,007,082,013,963.00
1895 value => $ 1,094,002,534,189,108.00
1896 value => $ 1,231,309,490,392,167.50
1897 value => $ 1,385,849,679,272,994.80
1898 value => $ 1,559,786,023,357,430.20
1899 value => $ 1,755,552,911,003,653.50
1900 value => $ 1,975,890,267,755,758.50
1901 value => $ 2,223,881,903,952,365.20
1902 value => $ 2,502,998,675,297,961.00
1903 value => $ 2,817,147,060,466,185.00
1904 value => $ 3,170,723,835,620,294.00
1905 value => $ 3,568,677,611,067,633.00
1906 value => $ 4,016,578,091,306,375.00
1907 value => $ 4,520,694,027,818,310.00
1908 value => $ 5,088,080,955,623,894.00
1909 value => $ 5,726,679,941,547,912.00
1910 value => $ 6,445,428,726,262,460.00
1911 value => $ 7,254,386,815,635,478.00
1912 value => $ 8,164,876,272,145,578.00
1913 value => $ 9,189,640,176,859,806.00
1914 value => $ 10,343,020,979,785,672.00
1915 value => $ 11,641,161,234,763,604.00
1916 value => $ 13,102,229,528,356,916.00
1917 value => $ 14,746,674,764,807,856.00
1918 value => $ 16,597,512,365,995,924.00
1919 value => $ 18,680,646,392,012,360.00
1920 value => $ 21,025,232,090,704,624.00
1921 value => $ 23,664,083,950,382,776.00
1922 value => $ 26,634,134,966,735,420.00
1923 value => $ 29,976,953,551,789,776.00
1924 value => $ 33,739,325,319,500,184.00
1925 value => $ 37,973,907,890,553,528.00
1926 value => $ 42,739,967,880,946,520.00
1927 value => $ 48,104,210,389,122,344.00
1928 value => $ 54,141,712,591,050,736.00
1929 value => $ 60,936,974,509,715,536.00
1930 value => $ 68,585,101,665,430,272.00
1931 value => $ 77,193,136,159,187,456.00
1932 value => $ 86,881,554,818,695,040.00
1933 value => $ 97,785,955,374,939,232.00
1934 value => $ 110,058,954,268,760,976.00
1935 value => $ 123,872,322,648,877,584.00
1936 value => $ 139,419,390,456,474,288.00
1937 value => $ 156,917,752,243,591,744.00
1938 value => $ 176,612,312,595,559,776.00
1939 value => $ 198,778,713,780,776,512.00
1940 value => $ 223,727,193,600,732,416.00
1941 value => $ 251,806,927,434,199,968.00
1942 value => $ 283,410,915,246,222,816.00
1943 value => $ 318,981,481,959,787,140.00
1944 value => $ 359,016,468,172,596,480.00
1945 value => $ 404,076,197,863,341,950.00
1946 value => $ 454,791,320,606,494,660.00
1947 value => $ 511,871,638,054,144,320.00
1948 value => $ 576,116,038,219,070,780.00
1949 value => $ 648,423,676,597,860,860.00
1950 value => $ 729,806,560,623,483,390.00
1951 value => $ 821,403,713,577,529,730.00
1952 value => $ 924,497,116,198,226,300.00
1953 value => $ 1,040,529,649,100,697,600.00
1954 value => $ 1,171,125,287,129,043,970.00
1955 value => $ 1,318,111,828,277,518,590.00
1956 value => $ 1,483,546,475,291,554,560.00
1957 value => $ 1,669,744,627,985,092,100.00
1958 value => $ 1,879,312,289,247,393,790.00
1959 value => $ 2,115,182,538,289,210,370.00
1960 value => $ 2,380,656,581,602,668,500.00
1961 value => $ 2,679,449,956,178,287,600.00
1962 value => $ 3,015,744,531,632,777,200.00
1963 value => $ 3,394,247,039,062,015,000.00
1964 value => $ 3,820,254,945,780,711,900.00
1965 value => $ 4,299,730,597,922,264,100.00
1966 value => $ 4,839,384,668,588,077,100.00
1967 value => $ 5,446,770,079,474,810,900.00
1968 value => $ 6,130,387,710,493,300,700.00
1969 value => $ 6,899,805,376,875,939,800.00
1970 value => $ 7,765,791,738,959,241,200.00
1971 value => $ 8,740,467,018,823,847,900.00
1972 value => $ 9,837,472,633,200,677,000.00
1973 value => $ 11,072,162,116,801,262,000.00
1974 value => $ 12,461,816,008,208,070,000.00
1975 value => $ 14,025,883,705,837,220,000.00
1976 value => $ 15,786,255,678,955,237,000.00
1977 value => $ 17,767,569,843,576,656,000.00
1978 value => $ 19,997,556,391,235,846,000.00
1979 value => $ 22,507,425,896,807,756,000.00
1980 value => $ 25,332,306,137,279,283,000.00
1981 value => $ 28,511,733,735,124,906,000.00
1982 value => $ 32,090,207,507,257,287,000.00
1983 value => $ 36,117,811,264,146,223,000.00
1984 value => $ 40,650,914,775,713,820,000.00
1985 value => $ 45,752,962,714,625,080,000.00
1986 value => $ 51,495,362,618,912,050,000.00
1987 value => $ 57,958,484,301,730,185,000.00
1988 value => $ 65,232,784,695,844,040,000.00
1989 value => $ 73,420,073,876,005,630,000.00
1990 value => $ 82,634,939,978,295,200,000.00
1991 value => $ 93,006,352,959,392,460,000.00
1992 value => $ 104,679,469,641,765,800,000.00
1993 value => $ 117,817,665,307,934,950,000.00
1994 value => $ 132,604,820,277,712,190,000.00
1995 value => $ 149,247,893,471,031,720,000.00
1996 value => $ 167,979,818,975,587,730,000.00
1997 value => $ 189,062,766,159,229,160,000.00
1998 value => $ 212,791,808,955,182,300,000.00
1999 value => $ 239,499,055,674,894,580,000.00
2000 value => $ 269,558,297,148,774,380,000.00

Add your own answer in the comments!

One thought on “How to write a java program that..?”

  1. First of all, I would like to check if the formula for getting the compound interest is indeed as shown in the webpage http://math.about.com/library/weekly/aa042002a.htm as I am no good with stats. If this is correct then the following code works:

    public static void main(String[] args)
    {
    double originalAmount = 24; // The original amt of money
    int startYear = 1629;
    int endYear = 2000;
    int year = 0; // Number of years past
    double rate = 0.03; // Interest rate
    double result;
    DecimalFormat currency = new DecimalFormat(“$ #0.00”);

    for (int i = startYear; i<=endYear;i++) { // Formula: Interest = Original Amt * (1+ rate/4) to the power of the number of years result = originalAmount * Math.pow((1+rate/4),year); System.out.println("In year " + i + ": Money = " + currency.format(result); year++; // Number of years past to increment } } That is all to it!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.