Write a java project (applet) that has two classes. The driver class (has the init() method) should allow the user to enter into an Input Dialog Box, the mail type ("P" for Priority or "F" for First Class), a blank space, and the weight in ounces of the piece of mail. You may assume the user will enter this data correctly.

Next the init() method should construct a variable of type Postage. This class has two instance fields, a String representing the postage type and a double representing the constructor, which initializes both of the instance fields. The Postage class should also have a calculate() method. This method should return the cost (a double) to mail the item. This cost is determined using the following guidelines.

Priority mail costs $3.50 for 16 ounces or less, $3.95 for over 16 ounces but not more than 32 ounces, and $1.20 for each additional 16 ounces (or fraction) above above 32 ounces. First Class mail costs 34 cents for the first ounce and 21 cents for each additional ounce (or fraction), up to 13 ounces, after which Priority rates apply.

Lastly, the init() method should set the background color of the applet to yellow.

The paint(Graphics g) method, of the driver class, should draw right to the applet, in darkGray, the cost to mail the item.

This project should be exectuted 4 times with the following Test Data: 1) P 2) P 5 3) F 3.5 4) F 18

The ouptut for the first set of data can be found on the back of this page. All input annd output should be pasted to a Word document and turned in with your code.

Every time I try to run it, I get a large amount of errors. Here is what I have so far for both classes:

import java.awt.Color;

public class Postage
{
   private double cost;
   private String Packagetype;

        public Postage(double c)
        {
            cost = c;
            Packagetype = "";
        }

        public double calculate (double ounces)
        {
                cost = 0.0;
                if ( Packagetype.equals("P") && ounces <= 16)
                {
                        cost = 3.50;
                        System.out.println("The cost to mail this is:"+ cost);
                }
                else if ( Packagetype.equals("P") && ounces > 16 && ounces <= 32)
                {
                  cost = 3.90;
                  System.out.println("The cost to mail this item is: $" + cost);
                }
                else if (Packagetype.equals("P") && ounces > 32)
                {
                        cost = 3.90;
                        double additional = ounces/16;
                        additional = additional /2;
                        cost = 3.90 + (additional * 1.20);
                        System.out.println ("The cost to mail this item is: $" + cost);
                }
                else if (Packagetype.equals("F") && ounces > 1)
                {
                         int count = 0;
                        cost = .34;

                        if (ounces > 13  && ounces < 16)
                                  {
                                        cost = cost + 3.50;
                                  }
                                  else if (ounces > 16 && ounces <=32)
                                  {
                                        cost = cost + 3.90;
                                  }
                                  else if (ounces > 32)
                                  {
                                        double additional = ounces/16;
                                        additional = additional /2;
                                        cost = cost + (additional * 1.20);
                                  }
                        for (double i = 1.0; i <= ounces; i++)
                                {
                                        cost = cost + .21;

                                        count++;
                                   if (count == 13)
                                        {
                                                System.out.println ("The cost to mail this item is $" + cost);
                                                return cost;
                                        }
                                 }
                                System.out.println ("The cost to mail this item is $" + cost);
                }
                return cost;
        }

      setBackground(Color.YELLOW);
  }

The driver is horrible, I can't figure it out:

import java.applet.Applet;
import javax.swing.JOptionPane;
import java.awt.Color
import javax.swing.JOptionPane;
import java.awt.Graphics;


public class Driver
{

    public static void main (String[]args)
    {

            Postage panel = new DrawingPanel(height, width);
            Graphics g = panel.getGraphics();
            String s = JOptionPane.showInputDialog(null,
            "Enter priority packagin(P or F) and the weight in ounces.",
            "Enter Package information");
            Packagetype = sc.next();
              ounces = sc.nextDouble();
            String input = JOptionPane.QUESTION_MESSAGE;
            Scanner sc = new Scanner(s);
            String Packagetype = sc.next();
            int ounces = sc.nextInt();

            DrawingPanel panel = new DrawingPanel(650, 400);
            Graphics g = panel.getGraphics();
            g.setColor(Color.GRAY);
            g.drawString ("The cost to mail this item is: $ " + cost , 438,9);

  }

}

Please use "code" tag around your code... Not easy to read your code right now :( For applet samples, you may look at this link http://oreilly.com/catalog/javanut/examples/ (especially the 2nd applet example code).

I'm sorry that I late

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.