Thanks to you guys...look what I can do!

ShinRa

Companion Cube
Joined
Jun 23, 2003
Messages
5,044
Reaction score
84
import java.awt.*;
import javax.swing.*;

public class ExpectedCost
{
public static void main(String[] args)
{

// this is where variable are declared
int confirm; // confirm dialog box
double cost; // original cost of item
double years; // years until item is bought
double Totalrate; // total inflation amount in dollars
double inflateamt; // inflation amount in dollars per year
double inflaterateDec; // inflation rate in decimal form
double inflateratePerc; // inflation rate in percent form
double TotalCost; // total cost of item after inflation
String costStr; // cost in string format
String yearsStr; // years in string format
String inflateStr; // inflation rate in string format

do {

costStr = JOptionPane.showInputDialog(null, "Please type in the cost of the item.");
cost = Double.parseDouble(costStr);
while (cost <= 0)
{
JOptionPane.showMessageDialog(null, "Please enter a number that is more than zero");
costStr = JOptionPane.showInputDialog(null, "Please type in the cost of the item.");
cost = Double.parseDouble(costStr);
}
yearsStr = JOptionPane.showInputDialog(null, "Please enter the number of years until you buy the item.");
years = Double.parseDouble(yearsStr);
while (years <=0)
{
JOptionPane.showMessageDialog(null, "Please enter a number that is more than zero");
yearsStr = JOptionPane.showInputDialog(null, "Please enter the number of years until you buy the item.");
years = Double.parseDouble(yearsStr);
}
inflateStr = JOptionPane.showInputDialog(null, "Please type in the inflation rate percent.");
inflateratePerc = Double.parseDouble(inflateStr);
while (inflateratePerc <= 0)
{
JOptionPane.showMessageDialog(null, "Please enter a number that is more than zero");
inflateStr = JOptionPane.showInputDialog(null, "Please type in the inflation rate percent.");
inflateratePerc = Double.parseDouble(inflateStr);
}


inflaterateDec = inflateratePerc / 100;
inflateamt = cost * inflaterateDec;
Totalrate = inflateamt * years;
TotalCost = Totalrate + cost;


JOptionPane.showMessageDialog(null, "The Total Cost of the item you are buying is $" + TotalCost);
confirm = JOptionPane.showConfirmDialog(null, "Would you like to use this calculator again?");
}while (confirm == JOptionPane.YES_OPTION);

System.exit(0);

}
}

Compile it (if you use java) and try it out. It was the second program I had to do. ALL ON MY OWN!!! :D
 
guinny said:
Compile it (if you use java) and try it out. It was the second program I had to do. ALL ON MY OWN!!! :D
Congratulations, dude. See, it's not that hard.. :)
 
I got 12 compiler errors :p
Some of the "null" values changed to "nu ll"
Works once I changed them.
 
I consider that a bug... If you type too many characters in code tags, it makes a scroll bar. There is no need to put spaces in long words then...
 
Yay!, I' learning the same kind of programs but in c ++ ! Congrats !
 
MFC scares me I prefer working in C# myself, even if it does away with my beloved pointers, oh pointers how I love thee let me count the ways!

void pWalk = ways;
while(*pWalk != void)
{
pWalk++;
}
int count = pWalk - ways;
 
C# rocks - my housemate stepped me through this windows program I wanted to do, but would have taken too long in C++. I was amazed at how easy it is, and how much stuff there is in .NET. You can download a file in 2 lines, parse it with regular expressions in another 2 lines - quite amazing. Micrsoft rock!
 
Heh yeah though there are times when I want to create simple data-structures, or do some more low level work, that all the managed code makes difficult. But for rapid application development C# and .NET is great. I can imagine it now 30 years down the road when somebody says they are a CS major, I'll sagely say, "Just learn pointers, the rest is easy once you get that" and they will look at me blankly and respond "What's a pointer ?".
 
we11er said:
C# rocks - my housemate stepped me through this windows program I wanted to do, but would have taken too long in C++. I was amazed at how easy it is, and how much stuff there is in .NET. You can download a file in 2 lines, parse it with regular expressions in another 2 lines - quite amazing. Micrsoft rock!

Someone that actually thinks Microsoft rocks?
Well... I'll get my VS.NET student license then.
 
Code:
import java.awt.*;
import javax.swing.*;

public class ExpectedCost
{
    public static void main(String[] args)
    {
	int confirm;              // confirm dialog box
	double cost;              // original cost of item
	double years;             // years until item is bought
	double Totalrate;         // total inflation amount in dollars
	double inflateamt;        // inflation amount in dollars per year
	double inflaterateDec;    // inflation rate in decimal form
	double inflateratePerc;   // inflation rate in percent form
	double TotalCost;         // total cost of item after inflation
	String costStr;           // cost in string format
	String yearsStr;          // years in string format
	String inflateStr;        // inflation rate in string format

	do 
	{
	    costStr = JOptionPane.showInputDialog( null, "Please type in the cost of the item.");
	    cost = Double.parseDouble(costStr);
	    
	    while (cost <= 0)
	    {
		JOptionPane.showMessageDialog( null, "Please enter a number that is more than zero");
		costStr = JOptionPane.showInputDialog( null, "Please type in the cost of the item.");
		cost = Double.parseDouble(costStr);
	    }
	    yearsStr = JOptionPane.showInputDialog( null, "Please enter the number of years until you buy the item.");
	    years = Double.parseDouble(yearsStr);
	   
	    while (years <=0)
	    {
		JOptionPane.showMessageDialog( null, "Please enter a number that is more than zero");
		yearsStr = JOptionPane.showInputDialog( null, "Please enter the number of years until you buy the item.");
		years = Double.parseDouble(yearsStr);
	    }
		
	    inflateStr = JOptionPane.showInputDialog( null, "Please type in the inflation rate percent.");
	    inflateratePerc = Double.parseDouble(inflateStr) ;
	    
	    while (inflateratePerc <= 0)
	    {
		JOptionPane.showMessageDialog( null, "Please enter a number that is more than zero");
		inflateStr = JOptionPane.showInputDialog( null, "Please type in the inflation rate percent.");
		inflateratePerc = Double.parseDouble(inflateStr) ;
	    }


	    inflaterateDec = inflateratePerc / 100;
	    inflateamt = cost * inflaterateDec;
	    Totalrate = inflateamt * years;
	    TotalCost = Totalrate + cost;


	    JOptionPane.showMessageDialog( null, "The Total Cost of the item you are buying is $" + TotalCost);
	    confirm = JOptionPane.showConfirmDialog( null, "Would you like to use this calculator again?");

	}while (confirm == JOptionPane.YES_OPTION);

	System.exit(0);

    }
}

there i cleaned it up for ya :)

sorry, im a perfectionist, couldn't resist
 
D looks very cool. I haven't tried it yet, but it's supposed to be _close_ to stable...

has anyone here tried it?
 
D huh? first time I hear of it. sounds pretty cool :D
 
has garbage collection, OOP, inheritance, operator overloading (hate not having that in java :x), lots and lots of features, compatible with C/C++ binaries I guess, but not backward compatible (code wise) so it is supposed to be rid of all that messy shit in c++
Edit: Messy shit like includes and header files, bad syntax, bad string support, 'pseudo'-typedefs, etc. etc.
 
wow looks very interesting..

might be the new programming language of the future ?

who knows
 
I heard about D a while back. I'm not sure how much support it has, but to be honest C++ has some major improvements coming up so I wonder weather it will ever be picked up.
 
Back
Top