I am now taking Java classes and I have worked this program out, but it is giving me a "illegal start of type" on my code and I do not know why please help. Thanks for your help.

// Displaying multiple strings
import javax.swing.*;  // to use JOptionPane.show InputDialog box
 
public class a3 
{
 public static void main( String args[] )
 {
  final double taxes = 0.0795;     // rate for taxes calculation (constant)
 
  int 
       moreInt = 1;                // loop control variable
 
  double
    totalPrice = 0,             // the sum of calculated devices
    devices = 0,                // the number of devices wanted
    salesTax = 0,               // the calculated sales tax
    cost = 0,                   // fixed cost on the amount of devices sold
    totalAmount = 0;            // the total amount for devices
 
  String numberDevices;            // number of devices
 
 
 // process unknown number of devices, boolean controled loop
    while ( moreInt == 1 ) {
         numberDevices = JOptionPane.showInputDialog(
                "Enter the number of SuperX Devices" );
 
         // convert numbers from type String to type double       
              devices = Double.parseDouble( numberDevices );      
 
This is where I am getting the "illegal start of type:
 
         // to determine the cost on the devices
              if( devices < 30 )
                   cost = "46.00";
                    else if( devices >= 30 && < 70 )
                          cost = "43.00";
                               else if( devices > 70)
                                          cost = "40.00";
 
 
         // calculations
              totalAmount = devices * cost;
              salesTax = totalAmount * taxes;
              totalPrice = totalAmount + salesTax;
 
         // display message total
              JOptionPane.showMessageDialog( null, "The number of Devices" + devices, "@" + cost, "ea" +totalAmount, "Sales taxes @ 7.95%" + taxes, "Total Price" + totalPrice, output);
 
 
         // display the "Thank you" message
              if (totalPrice < 1000)
                  output ="Thank you - We hope to see you again!";
              else if (totalPrice > 1000)
                  output = "Thank you - Call us if you need help installing the SuperX Devices.";
 
         input = JOptionPane.showInputDialog(
                  "Another order?\n   1 - yes\n   2 - no\n" );
 
         moreInt = Integer.parseInt( input );
 
      }  //while loop ends
 
 }  // end method main
 
 
}  // end method a3

if( devices < 30 )
cost = "46.00";
else if( devices >= 30 && devices< 70 )
cost = "43.00";
else if( devices > 70)
cost = "40.00";

Thank you, Now it is showing in the same area "incompatible types" am I doing something wrong or is this how it will be for Java.

countrygirl

double
    totalPrice = 0,             // the sum of calculated devices
    devices = 0,                // the number of devices wanted
    salesTax = 0,               // the calculated sales tax
    cost = 0,                   // fixed cost on the amount of devices sold
   
            if( devices < 30 )
                   cost = "46.00";
                   else if( devices >= 30 && < 70 )
                          cost = "43.00";
                               else if( devices > 70)
                                          cost = "40.00";

cost is a double. Remember Double is a number with a decimal place ie:3.14 and you dont put quotes around a number unless itis in a String.
:-)
peace
m

Thank you, Now it is showing in the same area "incompatible types" am I doing something wrong or is this how it will be for Java.

countrygirl

double
totalPrice = 0, // the sum of calculated devices
devices = 0, // the number of devices wanted
salesTax = 0, // the calculated sales tax
cost = 0, // fixed cost on the amount of devices sold
totalAmount = 0; // the total amount for devices
----You have defined "cost" as double ------------

if( devices < 30 )
cost = "46.00";
else if( devices >= 30 && devices < 70 )
cost = "43.00";
else if( devices > 70)
cost = "40.00";

---------Here you are allocating a String to a variable that has been defined as a double-----
Therefore your incompatible types error

Another observation in the code that you pasted
You have not defined the variables input and output in your class anywhere....

Try this one

// to determine the cost on the devices
if( devices < 30 )
cost = 46.00;
else if( devices >= 30 &&devices < 70 )
cost = 43.00;
else if( devices > 70)
cost = 40.00;

What will happen if devices = 70?

Thank you all for helping me out. I was able to fix those areas. Now I am getting an error on something else that shouldn't get one . I will get with my instructor to find out what I am doing wrong.

Thanks again.

// Displaying multiple strings
import javax.swing.*;                // to use JOptionPane.show InputDialog box
public class a3 
{
 public static void main( String args[] )
 {
  final double taxes = 0.0795;     // rate for taxes calculation (constant)
   
  int 
       moreInt = 1;                // loop control variable
           
  double
    totalPrice = 0,             // the sum of calculated devices
    devices = 0,                // the number of devices wanted
    salesTax = 0,               // the calculated sales tax
    cost = 0,                   // fixed cost on the amount of devices sold
    totalAmount = 0;            // the total amount for devices
          
  String numberDevices;            // number of devices
  String output;                   // Thank you message
  String input = "";               // users input       
      
 // process unknown number of devices, boolean controled loop
    while ( moreInt == 1 ) {
         numberDevices = JOptionPane.showInputDialog(
                "Enter the number of SuperX Devices" );
                
         // convert numbers from type String to type double       
              devices = Double.parseDouble( numberDevices );      
     
         
         // to determine the cost on the devices
               if( devices < 30.0 )
               {
                  cost = 46.00;
          }
          else if( devices >= 30.0 && devices <= 70.0 )
          {
                cost = 43.00;
          }
          else if( devices > 70.0)
          {
            cost = 40.00;
          }
                
                
         // calculations
              totalAmount = devices * cost;
              salesTax = totalAmount * taxes;
              totalPrice = totalAmount + salesTax;
               
         // message total output
         System.out.println ( devices + "Devices @" + cost + "ea." + totalAmout + "Sales taxes @ 7.95%" + taxes + "Total Price" + totalPrice +);
         
              
              
         // display the "Thank you" message
              if (totalPrice < 1000)
                  output ="Thank you - We hope to see you again!";
              else if (totalPrice > 1000)
                  output = "Thank you - Call us if you need help installing the SuperX Devices.";
                  
         input = JOptionPane.showInputDialog(
                  "Another order?\n   1 - yes\n   2 - no\n" );
                    
         moreInt = Integer.parseInt( input );
         
      }  //while loop ends
      
      // display message total
         JOptionPane.showMessageDialog( null, output );
  
 }  // end method main
 
   
}  // end method a3

if you get any error msg, you should not loose your hope... getting error msg is good as you can know what is going wrong.

Just a personal rule here: In my opinion you should never initiate a variable while using comma's, i.e.

double
   price = 0,
   total = 0,
   blah...

It should be done like so:

double total, price, count;
total = 0;
price = 0;
count = 0;

or like so:

double total = 0;
double price = 0;
double count = 0;

also isnt the main methos suppose to be
main(String[] args)

// Displaying multiple strings
import javax.swing.*;                // to use JOptionPane.show InputDialog box
public class a3 
{
 public static void main( String[] args )//args is an array. to define an array you put brackets after type
 {
  final double taxes = 0.0795;     // rate for taxes calculation (constant)
   
  int 
       moreInt = 1;                // loop control variable
           
  double
    totalPrice = 0,             // the sum of calculated devices
    devices = 0,                // the number of devices wanted
    salesTax = 0,               // the calculated sales tax
    cost = 0,                   // fixed cost on the amount of devices sold
    totalAmount = 0;            // the total amount for devices
          
  String numberDevices;            // number of devices
  String output="";                   // Thank you message init variable
  String input = "";               // users input       
      
 // process unknown number of devices, boolean controled loop
    while ( moreInt == 1 ) {
         numberDevices = JOptionPane.showInputDialog(
                "Enter the number of SuperX Devices" );
                
         // convert numbers from type String to type double       
              devices = Double.parseDouble( numberDevices );      
     
         
         // to determine the cost on the devices
               if( devices < 30.0 )
               {
                  cost = 46.00;
          }
          else if( devices >= 30.0 && devices <= 70.0 )
          {
                cost = 43.00;
          }
          else if( devices > 70.0)
          {
            cost = 40.00;
          }
                
                
         // calculations
              totalAmount = devices * cost;
              salesTax = totalAmount * taxes;
              totalPrice = totalAmount + salesTax;
               
         // message total output
         System.out.println ( devices + "Devices @" + cost + "ea." + totalAmount + "Sales taxes @ 7.95%" + taxes + "Total Price" + totalPrice +);//delete that
         
              
              
         // display the "Thank you" message
              if (totalPrice < 1000)
                  output ="Thank you - We hope to see you again!";
              else if (totalPrice > 1000)
                  output = "Thank you - Call us if you need help installing the SuperX Devices.";
                  
         input = JOptionPane.showInputDialog(
                  "Another order?\n   1 - yes\n   2 - no\n" );
                    
         moreInt = Integer.parseInt( input );
         
      }  //while loop ends
      
      // display message total
         JOptionPane.showMessageDialog( null, output );
  
 }  // end method main
 
   
}  // end method a3

:-)

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.