// Cash program
// This contains different kinds of errors
// Try to put them right
// syntax errors, runtime errors, logic errors, errors in the layout of the output
// Finally improve the look of the program by adding comments and improving the layout
import java.awt.*;
//import java.applet.*;
public class CashErrors extends Applet
{
d0uble billsCash;
double bensCash;
iny jillsCash;
int Totalcash
double averageCash;
public void init()
{
billsCash = 67.02;
bensCash == 3.54;
jillsCash= 33.48;
public void paintGraphics g)
{
g.setcolor(Color.black);
g.drawString("Bill has £" + billsCash, 50);
g.drawString("Ben has £" + bensCash, 50, 75 );
g.drawString("Jill has £" + jillsCash, 50, 90 );
averageCash = totalCash/0;
totalCash = billsCash + bensCash + jillsCash;
g.drawString("Between them they have £" + totalCash, 50,105);
g.drawString("Here is a graph of their money:", 50,120);
g.setColor(Color.red);
g.drawString ("Bill", 0, 140;
g.fillRect(50, 130, (int)billsCash*4, 15);
g.setColor(Colour.blue)
g.drawString ("Ben", 0, 170);
g.fillRect(50, 145, 15, (int)bensCash*4);
g.setColor(color.magenta);
g.drawstring ("Jill", 0, 155);
g.fillRect(50, 160, (int)jillsCash*4, 15);
f.drawString("Average cash is £" + averageCash, 50,190);
g.DrawString("If Bill gives Ben £ + (billsCash - averageCash), 50,205);
g.drawString("and Ben gives Jill £" + (averageCash - jillsCash), 220,50,);
g.drawString("They will each have £" + averageCash, 50,235);
g.drawString("They can earn more by resizing the applet",265);
billsCash = billsCash + (billsCash*0.05);
bensCosh = bensCash + (bensCash*0.05);
jillsCash = bensCash + (jillsCash*0.05);
g.drawString("Look how inaccurate doubles are!!", 50,290);
}
}
|