PDA

View Full Version : Java == PWNED!1!!



Soulpieced
03-24-2004, 04:15 PM
Did the expansion to this project in < 2 hours. Take that java!

.

import java.text.DecimalFormat;
public class Loan {
private double principal;
private double APR;
private int term;
private double monthlyPayment;
static DecimalFormat df = new DecimalFormat("0.##");

public static void main(String[] args) throws Exception {
Loan a = new Loan(30000, .04, 60, 0); //Principal, APR, Term. Calculate: Payment
Loan b = new Loan(30000, .04, 0, 552.4956616579792); //Principal, APR, Payment. Calculate: Term
Loan c = new Loan(0, .04, 60, 552.4956616579792); //APR, Payment, Term. Calculate: Principal
Loan d = new Loan(30000, 0, 60, 552.4956616579792); //Principal, Term, Payment. Calculate: APR
Loan e = new Loan(30000, .05, 60, 552.4956616579792); //All Available. Calculate: Validate
Loan f = new Loan(30000, .04, 60, 552.4956616579792); //All Available. Calculate: Validate
System.out.println(df.format(a.getMonthlyPayment() ));
System.out.println(b.getTerm());
System.out.println(c.getPrincipal());
System.out.println(df.format(d.getAPR()));
}

private Loan() { }

/*
public Loan(double a, double b, int c) {
setPrincipal(a);
setAPR(b);
setTerm(c);
setMonthlyPayment(calculatePayment(a, b, c));
}
*/

// Principal APR Term Payment
public Loan(double a, double b, int c, double d) {
if (a == 0) {
//Calculate: Principal
setPrincipal(calculatePrincipal(b, c, d));
setAPR(b);
setTerm(c);
setMonthlyPayment(d);
}
else if (b == 0) {
//Calculate: APR
setPrincipal(a);
setAPR(calculateAPR(a, c, d));
setTerm(c);
setMonthlyPayment(d);
}
else if (c == 0) {
//Calculate: Term
setPrincipal(a);
setAPR(b);
setTerm(calculateTerm(a, b, d));
setMonthlyPayment(d);
}
else if (d == 0) {
//Calculate: Payment
setPrincipal(a);
setAPR(b);
setTerm(c);
setMonthlyPayment(calculatePayment(a, b, c));
}
else {
//Verify input
setPrincipal(a);
setAPR(b);
setTerm(c);
setMonthlyPayment(d);
if (calculatePayment(a, b, c) != getMonthlyPayment()) System.out.println("ERROR, your input numbers do not validate.");
else System.out.println("Your loan application was processed correctly!");
}
}

public void setPrincipal(double a) {
principal = a;
}

public void setAPR(double b) {
APR = b;
}

public void setTerm(int c) {
term = c;
}

public void setMonthlyPayment(double mp) {
monthlyPayment = mp;
}

public double getPrincipal() {
return principal;
}

public double getAPR() {
return APR;
}

public int getTerm() {
return term;
}

public double getMonthlyPayment() {
return monthlyPayment;
}

//Calculate the APR with all other values known
public static double calculateAPR(double principal, int term, double monthlyPayment) {
double first = .00001;
double last = .25;
double middle;
while (last > first) {
middle = ((first + last) / 2);
if (calculatePayment(principal, middle, term) == monthlyPayment) return middle;
if (calculatePayment(principal, middle, term) < monthlyPayment) first = middle;
else last = middle;
}
return 0;
}

//Calculate the Payment with all other values known
public static double calculatePayment(double principal, double APR, int term) {
double monthlyIR = APR / 12;
double monthlyPayment = (monthlyIR * principal) * (1 + (1 / (Math.pow(1 + monthlyIR, term) - 1)));
return monthlyPayment;
}

//Calculate the Principal with all other values known
public static double calculatePrincipal(double APR, int term, double monthlyPayment) {
double monthlyIR = APR / 12;
double newPrincipal = monthlyPayment / (monthlyIR * (1 + (1 / (Math.pow(1 + monthlyIR, term) - 1))));
return newPrincipal;
}

//Calculate the Term with all other values known
public static int calculateTerm(double principal, double APR, double monthlyPayment) {
double monthlyIR = APR / 12;
String term = Math.round(Math.log(1 / (monthlyPayment / (monthlyIR * principal) - 1) + 1) /
Math.log(1 + monthlyIR)) + "";
int newTerm = Integer.parseInt(term);
return newTerm;
}

//Print out an amortization schedule based on the loan
public static void amortize(double principal, double APR, int term, double monthlyPayment) {
double monthlyInterestRate = APR / 12;
double totalPayment = monthlyPayment * term;
int payment = 1;
double balance = principal;

//Print information
System.out.println("Loan Amount: $" + principal);
System.out.println("Number of Payments: " + term);
System.out.println("Interest Rate: " + APR + "%");
System.out.println("Monthly Payment: $" + df.format(monthlyPayment));
System.out.println("Total Payment: $" + df.format(totalPayment));
System.out.println();
System.out.println("Payment#\tInterest\tPrincipal\ tBalance");

do {
double monthlyInterest = monthlyInterestRate * balance;
principal = monthlyPayment - monthlyInterest;
balance -= principal;

//Show Amortization Schedule
System.out.print(df.format(payment));
System.out.print("\t ");
System.out.print(df.format(monthlyInterest));
System.out.print("\t ");
System.out.print(df.format(principal));
System.out.print("\t ");
System.out.print(df.format(balance));
System.out.println();
payment++;
}
while (payment <= term);
}
}

[Edited on 3-24-2004 by Soulpieced]

Soulpieced
03-24-2004, 04:17 PM
That's object orientation for you.

Latrinsorm
03-24-2004, 04:38 PM
Originally posted by Soulpieced
That's object orientation for you. Is that what it is? All I see is a lot of stuff I hope I never have to learn. :D

TheEschaton
03-24-2004, 04:39 PM
Java is teh suck. Any two bit moron can code in Java, if you memorize the Sun API website. Muahahaha.


-TheE-

Soulpieced
03-24-2004, 04:41 PM
I hate the API, too basic and they don't give enough plain examples. Object orientation is the theory of separation of classes such that each thing is a separate entity, and performs just one thing. Or something along those lines.

TheEschaton
03-24-2004, 04:45 PM
Yeah, I like OOP. Inheritence and threading alone do it for me.

Do you know how hard it is to mimic those two things in C? Ugh.

-TheE-

J-Tech
03-24-2004, 04:48 PM
Nice man, i'm attempting to teach myself VBScript and SQL right now. I need to pick up some books on it tho.

J.T.

imported_Kranar
03-24-2004, 08:37 PM
<< Yeah, I like OOP. Inheritence and threading alone do it for me. >>

Threading has nothing to do with OOP. It's done the same way in C as in C++.

Skirmisher
03-24-2004, 10:24 PM
Now thats the Kranar I know and love. :love:

Fengus
03-24-2004, 11:19 PM
I hate worthless programming course projects.

TheEschaton
03-24-2004, 11:43 PM
But java (the only OOP language I know) makes it so simple, Kranar!

-TheE-

Lord Deprav
03-24-2004, 11:53 PM
Originally posted by Soulpieced
That's object orientation for you.

Heh I tryed to run it and didn't realize you had all those cute little smiley faces in it. Anyways of course after fixing it I didn't have import java.text.DecimalFormat;
Cause I didn't think about it and couldn't run it anyways. Yah know reading over your works, I don't understand quite a bit of it mainly because my studies (in the public education system) have not quite reached in that point. I wish I would have sent an e-mail to myself tonight. Because I am a little lost on what to do with the latest project I am working on. Its a simple banking/accounting program. Although I am making a mistake in it somewhere and am not sure. I am just curious. What word processor do you use to type your projects in? Also, if you have reched the points of applets, let me know because I wrote a basic program I would like to put on the web. Unfortunately, my book sucks.

Deprav

Lord Deprav
03-24-2004, 11:55 PM
Originally posted by J-Tech
Nice man, i'm attempting to teach myself VBScript and SQL right now. I need to pick up some books on it tho.

J.T.

Don't waste your time on VB. Every programmer I have met says it is worthless. Its nice if you want to make a juke box. I thought it was dumb personally. Java is so much better. Teach yourself HTML too (or XML cause its the way of today) because it is always a good language to be able to read.

Deprav

Soulpieced
03-25-2004, 12:38 AM
I use a program called Forte.

Lord Deprav
03-25-2004, 12:52 AM
Originally posted by Soulpieced
I use a program called Forte.

Hmm Ill have to give it a try. I have only used Textpad and Netbeans. Netbeans is good but no room for any type of fault.

Deprav

TheEschaton
03-25-2004, 07:41 AM
CodeWarrior is where it's at.


-TheE-

Parkbandit
03-25-2004, 08:10 AM
Ha... you guys are fools.

The BEST java is from Dunkin Donuts. Extra large, regular cream, regular sugar.

Galleazzo
03-25-2004, 10:01 AM
Dunkin' Donuts has okay java, but the best java around is from Stuckley's Egg House in Jackson Square in East Weymouth.

Word.

MaryJane
03-25-2004, 02:18 PM
Ok, I'm goin to have to check out that shack cause I got a friend moving there in a few weeks. Ya, I'll drive your junk around in the tahoe IF you buy me breakfast!

Starbucks > Dunkin Donuts

Venti carmel machiatto anytime.

J-Tech
03-25-2004, 02:58 PM
Ya, i know HTML, was gonna pick up XML, when i go back to school i'm takeing classes for C++, i have Visual Studio 6.0 Enterprise, and i downloaded a C++ tutorial but i just didnt understand, i know my math is no where up to where it needs to be, thats why i'm going back to school, i plan to make programming my profession, it's my one dream i have in life, is to be an excellent programmer...i'm just starting out tho (and a lil late i belive at the age of 21).

J.T.

Latrinsorm
03-25-2004, 04:13 PM
Originally posted by J-Tech
Ya, i know HTML, was gonna pick up XML, when i go back to school i'm takeing classes for C++, i have Visual Studio 6.0 Enterprise, and i downloaded a C++ tutorial but i just didnt understand, i know my math is no where up to where it needs to be, thats why i'm going back to school, i plan to make programming my profession, it's my one dream i have in life, is to be an excellent programmer...i'm just starting out tho (and a lil late i belive at the age of 21).Dude, C++ is hella easy. So long as you, you know, have a good teacher/book. It's very intuitive. The problem is it'll whine about the slightest thing you do wrong, so having a good debugger is also key. Just learn the basics and it's gravy.

Galleazzo
03-25-2004, 04:25 PM
Originally posted by MaryJane
Ok, I'm goin to have to check out that shack cause I got a friend moving there in a few weeks.
It's a good breakfast place. Nothing fancy, just the neighborhood joint. Whereabouts on the South Shore you live?

TheEschaton
03-25-2004, 05:02 PM
Starbucks > Dunkin Donuts

Blasphemy.


-TheE-

imported_Kranar
03-25-2004, 05:33 PM
<< i plan to make programming my profession, it's my one dream i have in life, is to be an excellent programmer...i'm just starting out tho >>

Learn how to program first, then decide what language to program in.

Learning how to program is not the same as learning how to code in C++ or Java or VisualBASIC. Programming is done purely on a theoretical level, independent of any language. Once the theoretical level is completed, then you can decide what language to implement your theory in.

That last aspect, sitting infront of your computer typing in some code, be it C++, C, or Java, is supposed to be the easiest, and shortest step on the path to making a program.

Read about Turing Machines, pseudocode, design techniques, data structures, complexity, object oriented theory, aspect oriented theory, modular programming, how software interacts with hardware, and other theoretical aspects of programming before you decide to sit and start typing.

None of those concepts have anything to do with any particular language, and unless you have a firm understanding of them, you'll be in for a long... painful... ride.

In the end, instead of saying "I can code in C++, and Java, and XML" you'll be saying "I am a language independent programmer, you pick the language, and I'll do the rest."

[Edited on 3-25-2004 by Kranar]

Lord Deprav
03-25-2004, 06:53 PM
Just to add to Kranar, yes don't just sit down and start typing. I found out through all the introductory courses I have had...they all are actually similar to eachother. Java is based of C with a little different coding and from what I understand it has much more. Most programming you will learn in school is looping, then developing basic calculation programs. There is so much more design that you can do beyond the basics, just keep your mind open. When I am just messing around with Java, I try to look through some java websites and see what people have created and base some of my ideas off their basic ones. I think its a good way to learn is to practice what someone else is doing (I try and just look at the program running and then duplicate it...but its not always that easy.)

Deprav