Need help with java program!
I am very new to java and was wondering if I can get some help with an assignment. Here is the description of what needs to be done.
1. Create a Java program with proper documentation and indentation.
2. Give a brief description to the user.
3. Mary suggests creating a class named ‘CarTracker’ with two String variables (first and last names of the driver), a double variable to track the fares paid to the driver; a double variable to track the gasoline purchased by the driver; a double variable to track the gasoline used.
4. Display for the user the following and enter the data (use the Scanner class) exactly to test your program:
(type the name in exactly as shown):
Please enter the Driver's first name:
john
Please enter the Driver's Last name:
betterDriver
Please enter the amount paid to the Driver (fares):
121.45
Please enter the amount the Driver paid for gas:
36.50
Please enter the distance the Driver travelled:
525
Please enter the amount of gasoline the Driver used:
35.5
5. Create a green panel using a JPanel and JLabels. With the given input (above).
6. Mary suggests using these formulas to determining the output and the client agreed:
mpg = miles-travelled / gas-Used
fares-per-mile = fare / miles-travelled
gas-paid-per-mile = gas-purchased / miles- travelled
profit = fare – gas-purchased;
7. Joe (the IS person) suggests (because of his many years of experience with clients) better looking output by using these Java classes:
DecimalFormat dfmt = new DecimalFormat("0.##");
NumberFormat cfmt = NumberFormat.getCurrencyInstance();
8. Add a driver so you can track two drivers. Use any input for the second driver, however, keep using the same input for the first driver. Create a JPanel for each driver. Have one JPanel be a green color and the other a blue color.
9. Have the name (first and last) appear using the following format: all letters are lower case except for the first letter of the first and last name: (e.g., John Betterdriver). The input for driver one should be exactly as shown above, for example enter in the name: john ‘betterDRIVER’. The output should have the name appear as ‘John Betterdriver’.
10. Also create an icon for each driver. The image you use is up to you, however, use a different image for each driver and place the icon inside the JPanels. Make the output look good.
So those are the guidelines and here is what I have come up with so far. I need help with what i'm mssing and what I still need to have in my program. Any and all help is greatly appreciated.
// This program will Calculate the mileage statistics for a cab company in Allendale
//
import Java.awt.Color;
import Java.awt.Dimension;
import Java.text.NumberFormat;
import Java.text.DecimalFormat;
import Java.util.Scanner;
import Javax.swing.JFrame;
import Javax.swing.JLabel;
import Javax.swing.JPanel;
import Javax.swing.SwingConstrants;
public class CarTracker
{
public static void main(String[ ] args )
{
Scanner reader;
double fares1;
double gas1;
double distance1;
reader = new Scanner( System.in );
System.out.println("Enter the driver's first name");
firstname1= scan.nextline();
System.out.println("Enter the driver's last name");
lastname1= scan.nextline();
System.out.println("Enter the amount paid to the driver");
fares1= scan.nextdouble();
System.out.println("Enter the amount the driver paid for gas");
gas1= scan.nextdouble();
System.out.println("Enter the distance the driver traveled");
distance1= scan.nextdouble();
// Presents two colored panels nested within a third.
JFrame frame = new JFrame ("Nested Panels");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
JPane1 subPanel1 = new JPane1();
subPanel1.setPreferredSize (new dimension(175, 175));
subPanel1.setBackground (Color.green);
JLabel label1 = new JLabel ("name " + firstname1 + " " + lastname1);
subPanel1.add (label1);
//Set up primary pane
JPanel1 primary = new JPanel();
primary.setBackground (Color.blue);
primary.add (subPanel1);
frame.getContentPane().add(primary);
frame.pack();
frame.setVisable(true);
}
}