shadowls
07-30-2009, 07:04 PM
I'm using jGrasp and new at Java programming.
My code is:
/* CIS 406 – Section 3016 – Java Programming I
Program 3 – Java Loops and Switch Statement
Olivia Riggs
July 27, 09
*/
import javax.swing.*;
import java.text.*;
class Program3 {
public static void main (String[] args) {
Program3 prog = new Program3( );
prog.start();
}
public void start( ) {
int prod;
int quan;
double price;
double lineAmount = (price*quan);
double orderAmount = (lineAmount+orderAmount);
prod = JOptionPane.showInputDialog(null, "Enter Product No.(1-5) or -1 to Quit:");
switch (prod) {
case 1: price = 2.98;
break;
case 2: price = 4.50;
break;
case 3: price = 9.98;
break;
case 4: price = 4.49;
break;
case 5: price = 6.87;
break;
}
while (prod != -1) {
quan = JOptionPane.showInputDialog(null, "Enter Quantity (1-5) or -1 to Quit:");
}
if (prod == -1) {
JOptionPane.showMessageDialog("Total", "Your total is" + orderAmount);
}
while (quan != -1) {
DecimalFormat df = new DecimalFormat("0.00");
JOptionPane.showMessageDialog("Order Subtotal Amount", "Product No" + "Quantity" + "Line Amount" + "Order Amount" + "\n\n"
+ prod + " " + quan + " " + df.format(lineAmount) + " " + df.format(orderAmount) );
}
if (quan == -1) {
JOptionPane.showMessageDialog("Total", "Your total is" + orderAmount);
}
prod = JOptionPane.showInputDialog(null,"Enter Product No.(1-5) or -1 to Quit:");
{
System.exit( 0 );
}
}
}
These are the errors I'm getting when I compile the code:
----jGRASP exec: javac -g C:\Users\Shadow\Desktop\CIS406\Program3.java
Program3.java:26: incompatible types
found : java.lang.String
required: int
prod = JOptionPane.showInputDialog(null, "Enter Product No.(1-5) or -1 to Quit:");
^
Program3.java:48: incompatible types
found : java.lang.String
required: int
quan = JOptionPane.showInputDialog(null, "Enter Quantity (1-5) or -1 to Quit:");
^
Program3.java:54: cannot find symbol
symbol : method showMessageDialog(java.lang.String,java.lang.String)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog("Total", "Your total is" + orderAmount);
^
Program3.java:61: cannot find symbol
symbol : method showMessageDialog(java.lang.String,java.lang.String)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog("Order Subtotal Amount", "Product No" + "Quantity" + "Line Amount" + "Order Amount" + "\n\n"
^
Program3.java:69: cannot find symbol
symbol : method showMessageDialog(java.lang.String,java.lang.String)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog("Total", "Your total is" + orderAmount);
^
Program3.java:73: incompatible types
found : java.lang.String
required: int
prod = JOptionPane.showInputDialog(null,"Enter Product No.(1-5) or -1 to Quit:");
^
6 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
I know these may be simple errors, but I have no idea how to fix them. Any help or information on what I'm doing wrong would be wonderful. Thanks in advance.
My code is:
/* CIS 406 – Section 3016 – Java Programming I
Program 3 – Java Loops and Switch Statement
Olivia Riggs
July 27, 09
*/
import javax.swing.*;
import java.text.*;
class Program3 {
public static void main (String[] args) {
Program3 prog = new Program3( );
prog.start();
}
public void start( ) {
int prod;
int quan;
double price;
double lineAmount = (price*quan);
double orderAmount = (lineAmount+orderAmount);
prod = JOptionPane.showInputDialog(null, "Enter Product No.(1-5) or -1 to Quit:");
switch (prod) {
case 1: price = 2.98;
break;
case 2: price = 4.50;
break;
case 3: price = 9.98;
break;
case 4: price = 4.49;
break;
case 5: price = 6.87;
break;
}
while (prod != -1) {
quan = JOptionPane.showInputDialog(null, "Enter Quantity (1-5) or -1 to Quit:");
}
if (prod == -1) {
JOptionPane.showMessageDialog("Total", "Your total is" + orderAmount);
}
while (quan != -1) {
DecimalFormat df = new DecimalFormat("0.00");
JOptionPane.showMessageDialog("Order Subtotal Amount", "Product No" + "Quantity" + "Line Amount" + "Order Amount" + "\n\n"
+ prod + " " + quan + " " + df.format(lineAmount) + " " + df.format(orderAmount) );
}
if (quan == -1) {
JOptionPane.showMessageDialog("Total", "Your total is" + orderAmount);
}
prod = JOptionPane.showInputDialog(null,"Enter Product No.(1-5) or -1 to Quit:");
{
System.exit( 0 );
}
}
}
These are the errors I'm getting when I compile the code:
----jGRASP exec: javac -g C:\Users\Shadow\Desktop\CIS406\Program3.java
Program3.java:26: incompatible types
found : java.lang.String
required: int
prod = JOptionPane.showInputDialog(null, "Enter Product No.(1-5) or -1 to Quit:");
^
Program3.java:48: incompatible types
found : java.lang.String
required: int
quan = JOptionPane.showInputDialog(null, "Enter Quantity (1-5) or -1 to Quit:");
^
Program3.java:54: cannot find symbol
symbol : method showMessageDialog(java.lang.String,java.lang.String)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog("Total", "Your total is" + orderAmount);
^
Program3.java:61: cannot find symbol
symbol : method showMessageDialog(java.lang.String,java.lang.String)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog("Order Subtotal Amount", "Product No" + "Quantity" + "Line Amount" + "Order Amount" + "\n\n"
^
Program3.java:69: cannot find symbol
symbol : method showMessageDialog(java.lang.String,java.lang.String)
location: class javax.swing.JOptionPane
JOptionPane.showMessageDialog("Total", "Your total is" + orderAmount);
^
Program3.java:73: incompatible types
found : java.lang.String
required: int
prod = JOptionPane.showInputDialog(null,"Enter Product No.(1-5) or -1 to Quit:");
^
6 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
I know these may be simple errors, but I have no idea how to fix them. Any help or information on what I'm doing wrong would be wonderful. Thanks in advance.