Results 1 to 18 of 18
  1. #1
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Default [SOLVED] Code will not compile

    I'm not sure why I am getting this, this is my code.

    Java Code:
    //This is the main program, it calculates information using the class
    import javax.swing.JOptionPane;
    public class Project
    {  
     public static void main(String args[])
     {
      double width = 0;
      double length = 0;
      String firstAnswer;
      String secondAnswer = "yes";
      String lengthString;
      String widthString;
      String netSpeedString;
      double netSpeed = 0;
      DigitalPhoto photo = new DigitalPhoto();
      
      firstAnswer = JOptionPane.showInputDialog("Do you have a photo you would like us to scan (Yes or No)");
      if(firstAnswer.equalsIgnoreCase("Yes"))
      {
       netSpeedString = JOptionPane.showInputDialog("What is the speed of your Internet connection (in bits/second)? ");
    	netSpeed = Double.parseDouble.(netSpeedString);  
    	
    	while(secondAnswer.equalsIgnoreCase("Yes"))
    	{
        widthString = JOptionPane.ShowInputDialog("What is the width of your photo in inches?");
    	 width = Double.parseDouble.(widthString);
    	 
    	 while(width > 8)
    	 {
    	  System.out.println("Sorry, we cannot handle a photo of that size");
    	  widthString = JOptionPane.ShowInputDialog("What is the width of your photo in inches?");
    	  width = Double.parseDouble.(widthString);
    	 }
    	
    	 lengthString = JOptionPane.ShowInputDialog("What is the length of your photo in inches?");
    	 length = Double.parseDouble.(lengthString);
    	 
    	 while(length > 8)
    	 {
    	  System.out.println("Sorry, we cannot handle a photo of that size");
    	  lengthString = JOptionPane.ShowInputDialog("What is the length of your photo in inches?");
    	  length = Double.parseDouble.(widthString);
    	 }	
        	
    	 photo.showValues();
    	
    	} 
      }
      if(firstAnswer.!equalsIgnoreCase("Yes"))
      {
       System.out.println("Thanks for stopping by, come again soon");
      }
     }
    }
    Here are the error messages I am getting:

    Java Code:
    C:\Users\Jackson\Project.java:21: <identifier> expected
    	netSpeed = Double.parseDouble.(netSpeedString);  
    	                              ^
    C:\Users\Jackson\Project.java:26: <identifier> expected
    	 width = Double.parseDouble.(widthString);
    	                            ^
    C:\Users\Jackson\Project.java:32: <identifier> expected
    	  width = Double.parseDouble.(widthString);
    	                             ^
    C:\Users\Jackson\Project.java:36: <identifier> expected
    	 length = Double.parseDouble.(lengthString);
    	                             ^
    C:\Users\Jackson\Project.java:42: <identifier> expected
    	  length = Double.parseDouble.(widthString);
    	                              ^
    C:\Users\Jackson\Project.java:49: <identifier> expected
      if(firstAnswer.!equalsIgnoreCase("Yes"))
                     ^
    C:\Users\Jackson\Project.java:49: ';' expected
      if(firstAnswer.!equalsIgnoreCase("Yes"))
    Thank you for your help.
    Last edited by ShotGunRockets; 05-10-2009 at 03:43 AM.

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    You haven't declared the types of any of these variables.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Default

    Well I did initialize them at the top, am I missing what you mean?

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    No, my bad. What's actually wrong is all the dots before the brackets. And the randomly inserted !s.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  5. #5
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Default

    Okay thank you that cleared up some of the problem. But what exactly do you mean by the randomly inserted !s, where should they go?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    before the object.

    Java Code:
    if (!myString.equalsIgnoreCase("foo"))
    {
      //...
    }

  7. #7
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    You don't yet appear to have a grasp of Java syntax.

    if (expression) {code} --> executes "code" if "expression" evaluates to true
    !expression --> evaluates to true if "expression" evaluates to false, and vice versa

    The following are all expressions:
    Class.name --> The static field "name" in "Class"
    var.name --> The instance field "name" of the object in variable "var"
    var.name() --> Returns the result of the instance method "name()" of the object in variable "var"
    var.name(foo) --> As above but using the argument foo

    The . loosely means "inside" (reading the expression backwards)
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  8. #8
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Default

    Alright, I fixed that but now I get these errors:

    Java Code:
    C:\Users\Jackson\Project.java:25: cannot find symbol
    symbol  : method ShowInputDialog(java.lang.String)
    location: class javax.swing.JOptionPane
        widthString = JOptionPane.ShowInputDialog("What is the width of your photo in inches?");
                                 ^
    C:\Users\Jackson\Project.java:31: cannot find symbol
    symbol  : method ShowInputDialog(java.lang.String)
    location: class javax.swing.JOptionPane
    	  widthString = JOptionPane.ShowInputDialog("What is the width of your photo in inches?");
    	                           ^
    C:\Users\Jackson\Project.java:35: cannot find symbol
    symbol  : method ShowInputDialog(java.lang.String)
    location: class javax.swing.JOptionPane
    	 lengthString = JOptionPane.ShowInputDialog("What is the length of your photo in inches?");
    	                           ^
    C:\Users\Jackson\Project.java:41: cannot find symbol
    symbol  : method ShowInputDialog(java.lang.String)
    location: class javax.swing.JOptionPane
    	  lengthString = JOptionPane.ShowInputDialog("What is the length of your photo in inches?");
    And yes you're very right, I am not yet very familiar with Java syntax, bear with me :)
    Last edited by ShotGunRockets; 05-09-2009 at 10:46 PM.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

    Default

    Also note that Java is case sensitive. ShowInputDialog is not showInputDialog.

    For "not equal to (ignore case)" you need
    Java Code:
    (!firstAnswer.equalsIgnoreCase("Yes"))
    db

  10. #10
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Default

    Thank you very much Darryl.Burke, that was a very helpful hint and now that code compiles :D

    Now I have another question, I can now see that my class file has some errors. The program I am trying to make should produce an output like this:
    Java Code:
    Scanned Photo Details
    Resolution: 600.00 pixels per inch
    Compression Ratio: 3.50
    Required Storage: 2.06
    Cost of Scanning Photo: $2.40
    It does not properly calculate these values, here is my class code:

    Java Code:
    public class DigitalPhoto
    {
    	 //I will declare the variables here
    	 private double width;
    	 private double length;
    	 private double scanAccuracy = 360000;
    	 private double compression = 3.5;
        private double Mbytes = 0;  
    	 private double totalCost = 0.00;
    	 private double cost = 0.00;  
    	 private double transferTimeBits = 100000;
    	 private double netSpeed = 0;
    	 private double resolution = 600.00;
    	 private double storage = 0;
    	 private double totalStorage = 0;
        private final int DIVISOR = 60;
    	 
    	 //Here is my constructor methed
    	    DigitalPhoto()
          {
             width = 4;
             length = 4;
             compression = 3.5;
             cost = 0.00;      
    			storage = 2.06;    
    		   netSpeed = transferTimeBits / 8000000;	
    			totalStorage = Mbytes + totalStorage; 
    		   totalCost = totalCost + cost;
    		}
    	 	
    	    public void showValues()
          {
             System.out.println("Scanned Photo Details");
             System.out.println("Resolution: " + resolution + " pixels per inch");
             System.out.println("Compression Ratio: " + compression);
             System.out.println("Required Storage: " + storage);
             System.out.println("Cost of Scanning Photo: " + cost);    
    		}
       //Here I am getting the values that I will work with in this class
           public double getWidth()
    		{
    		 return width;
    		}
    
           public double getLength()
    		{
    		 return length;
    		}
    		
    		 public double getTransferTimeBits()
    		{
    		 return transferTimeBits;
    		}
    		
    		 public void setWidth(double thisWidth)
    		{
    		 width = thisWidth;
    		}
    
           public void setLength(double thisLength)
    		{
    		 length = thisLength;
    		}
    		
    		 public void setTransferTimeBits(double thisTime)
    		{
    		 transferTimeBits = thisTime;
    		}
    
    	  double area = width * length;
    	  
    	 //Below are my methods of how to get the correct information.
    	 double transferTimeSeconds = transferTime(totalStorage, netSpeed);
    	 int transferTimeSecondsInt = (int)transferTimeSeconds;
    
    	
    	 double transferTimeMinutes = transferTimeSecondsInt / DIVISOR;
    	 double leftOverTime = transferTimeSecondsInt % DIVISOR;
    	
    	//I created a special method for calculating the cost of a photo
    	public static double cost(double area)
       {
        double cost = .12 * area;
    	 return cost;
    	}
    	
       public static double datasize(double w, double L, double scanAccuracy, double compress)
       { 
        double bytes = (w * L * scanAccuracy) / compress;
        double Mbytes = bytes / 1000000;
        return Mbytes;
       }
    	
    	public static double transferTime(double totalStorage, double netSpeed)
    	{
    	 double transferTime = totalStorage / netSpeed;
    	 return transferTime;
       }
    
    }
    Thank you guys so much!
    Last edited by ShotGunRockets; 05-09-2009 at 10:46 PM.

  11. #11
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Read this Trail: Learning the Java Language (The Java™ Tutorials)

    You are assigning different constants to the same variable repeatedly eg:
    Java Code:
    private double storage = 0;
    ...
    storage = 2.06;
    You have code that looks like it should be in a method but it isn't
    Java Code:
    //Below are my methods of how to get the correct information.
    double transferTimeSeconds = transferTime(totalStorage, netSpeed);
    int transferTimeSecondsInt = (int)transferTimeSeconds;
    
    double transferTimeMinutes = transferTimeSecondsInt / DIVISOR;
    double leftOverTime = transferTimeSecondsInt % DIVISOR;
    Some code looks like it should be static maybe, or in the constructor or I don't know what.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  12. #12
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Default

    Thank you OrangeDog, I have read that tutorial but when I try to insert an object into my class like the tutorial says
    Java Code:
    photo.setLength(length);
    I get this error:


    Java Code:
    C:\Users\Jackson\Project.java:46: cannot find symbol
    symbol  : method setLength(double)
    location: class DigitalPhoto
    	 photo.setLength(length);
    Last edited by ShotGunRockets; 05-09-2009 at 10:49 PM.

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    The error message usually tells you exactly (or almost exactly) what's going wrong here. So, does your DigitalPhoto class have a setLength method that takes a double value as its parameter?

  14. #14
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Default

    Well I'm very new at this, but I believe it does which is why I'm confused, here is my latest DigitalPhoto class:

    Java Code:
    public class DigitalPhoto
    {
    	 //I will declare the variables here
    	 private double width;
    	 private double length;
    	 private double thisWidth;
    	 private double thisLength;
    	 private double scanAccuracy = 360000;
    	 private double compression;
        private double Mbytes = 0;  
    	 private double totalCost = 0.00;
    	 private double cost;  
    	 private double transferTimeBits = 100000;
    	 private double totalTimeMinutes;
    	 private double totalTimeSeconds;
    	 private double netSpeed = 0;
    	 private double resolution = 600.00;
    	 private double storage;
    	 private double totalStorage = 0;
        private final int DIVISOR = 60;
    	 
    	 private double thisWidth2 = setWidth(width);
    	 
    	 //Here is my constructor methed
    	   public DigitalPhoto()
          {
             width = thisWidth2;
             length = 0;
             compression = 3.5;
             cost = 0;      
    			storage = 0;    
    		   netSpeed = transferTimeBits / 8000000;	
    			totalStorage = Mbytes + totalStorage; 
    		   totalCost = totalCost + cost;
    			double transferTimeSeconds = transferTime(totalStorage, netSpeed);
    	      int transferTimeSecondsInt = (int)transferTimeSeconds;
    	      double transferTimeMinutes = transferTimeSecondsInt / DIVISOR;
    	      double leftOverTime = transferTimeSecondsInt % DIVISOR;
    		}
    	 	
    	    public void showValues()
          {
             System.out.println("Scanned Photo Details");
             System.out.println("Resolution: " + resolution + " pixels per inch");
             System.out.println("Compression Ratio: " + compression);
             System.out.println("Required Storage: " + storage);
             System.out.println("Cost of Scanning Photo: $" + cost);    
    		}
       
    	    public void showValues2()
    		{
    		   System.out.println("Your photos will cost $" + totalCost);
    			System.out.println("and will require " + totalStorage + " Mbytes of storage");
    			System.out.println("and " + totalTimeMinutes + "minutes, " + totalTimeSeconds + " seconds to transfer");
    			System.out.println();
    		}
    	
    	//Here I am getting the values that I will work with in this class
           public double getWidth()
    		{
    		 return width;
    		}
    
           public double getLength()
    		{
    		 return length;
    		}
    		
    		 public double getTransferTimeBits()
    		{
    		 return transferTimeBits;
    		}
    		
    		 public double setWidth(double thisWidth)
    		{
    		 width = thisWidth;
    		 return thisWidth;
    		}
    
           public double setLength(double thisLength)
    		{
    		 length = thisLength;
    		 return thisLength;
    		}
    		
    		 public double setTransferTimeBits(double thisTime)
    		{
    		 transferTimeBits = thisTime;
    		 return thisTime;
    		}
    
    	  double area = width * length;
    	  
    
    	
    	//I created a special method for calculating the cost of a photo
    	public static double cost(double area)
       {
        double cost = .12 * area;
    	 return cost;
    	}
    	
       public static double datasize(double w, double L, double scanAccuracy, double compress)
       { 
        double bytes = (w * L * scanAccuracy) / compress;
        double Mbytes = bytes / 1000000;
        return Mbytes;
       }
    	
    	public static double transferTime(double totalStorage, double netSpeed)
    	{
    	 double transferTime = totalStorage / netSpeed;
    	 return transferTime;
       }
    
    }
    Last edited by ShotGunRockets; 05-09-2009 at 10:48 PM.

  15. #15
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Firstly, you're using QUOTE tags instead of CODE tags.

    At this stage i would suggest chucking this class away and starting again. There appear to be far too many instance variables. As an example this
    Java Code:
    private double thisWidth2 = setWidth(width);
    achieves nothing. width hasn't even been initialised yet.

    Think about what properties an individual image might have, and only include those as fields. You don't need things the will be calculated from other fields.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  16. #16
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Default

    Thanks again OrangeDog, I have done exactly what you said and I am very close to completing this program! I only have one more problem, the time will not calculate, this is my output:
    Your photos will cost $3.00
    and will require 2.57 Mbytes of storage
    and will take 0 minutes, 0 seconds to transfer
    No matter what I do, I get 0 minutes and 0 seconds. Here is my code, first for the main program:

    Java Code:
    //This is the main program, it calculates information using the class
    import java.text.DecimalFormat;
    import javax.swing.JOptionPane;
    public class Project
    {  
     public static void main(String args[])
     {
      DecimalFormat dollarsAndCents = new DecimalFormat("0.00");
      DigitalPhoto photo = new DigitalPhoto();
      double width;
      double length;
      double area;
      double totalStorage = 0;
      double totalCost = 0;
      double scanAccuracy = 360000;
      double compress = 3.5;
      String firstAnswer;
      String secondAnswer = "yes";
      String lengthString;
      String widthString;
      String netSpeedString;
    
      
      //First I will determine whether the user wants to scan a photo or not.
      firstAnswer = JOptionPane.showInputDialog("Do you have a photo you would like us to scan (Yes or No)");
      if(firstAnswer.equalsIgnoreCase("Yes"))
      {
       netSpeedString = JOptionPane.showInputDialog("What is the speed of your Internet connection (in bits/second)? ");
    	double netSpeed = Double.parseDouble(netSpeedString);  
    	//Now I'll prompt the user for the values that are needed for calculation.
    	while(secondAnswer.equalsIgnoreCase("Yes"))
    	{
        widthString = JOptionPane.showInputDialog("What is the width of your photo in inches?");
    	 width = Double.parseDouble(widthString);
    	 //This ensures the user will enter a valid width
    	 while(width > 8)
    	 {
    	  System.out.println("Sorry, we cannot handle a photo of that size");
    	  System.out.println();
    	  widthString = JOptionPane.showInputDialog("What is the width of your photo in inches?");
    	  width = Double.parseDouble(widthString);
    	 }
    	
    	 lengthString = JOptionPane.showInputDialog("What is the length of your photo in inches?");
    	 length = Double.parseDouble(lengthString);
    	 //This ensures the user will enter a valid length
    	 while(length > 8)
    	 {
    	  System.out.println("Sorry, we cannot handle a photo of that size");
    	  System.out.println();
    	  lengthString = JOptionPane.showInputDialog("What is the length of your photo in inches?");
    	  length = Double.parseDouble(widthString);
    	 }	
        
    	 
    	 //I now am calling to my class, so I can display the values for the photo
    	 photo.datasize(width, length, scanAccuracy, compress);
    	 photo.cost(photo.area(width, length));
    	 photo.showValues();
    	 //Right here, I total up the values for the final statement of the program
    	 totalStorage = totalStorage + photo.datasize(width, length, scanAccuracy, compress);
    	 totalCost = totalCost + photo.cost(photo.area(width, length));
    	 secondAnswer = JOptionPane.showInputDialog("Do you have more photos you would like us to scan (Yes or No)");
    	 
    	 
    	}   
    	double transferTimeSeconds = photo.transferTime(totalStorage, netSpeed);
    	int transferTimeSecondsInt = (int)transferTimeSeconds;
       int transferTimeMinutes = transferTimeSecondsInt / 60;
    	int leftOverTime = transferTimeSecondsInt % 60;
    	
    	System.out.println("Your photos will cost $" + dollarsAndCents.format(totalCost));  
       System.out.println("and will require " + dollarsAndCents.format(totalStorage) + " Mbytes of storage");
       System.out.println("and will take " + transferTimeMinutes + " minutes, " + leftOverTime + " seconds to transfer");
      
      }
      if(!firstAnswer.equalsIgnoreCase("Yes"))
      {
       System.out.println("Thanks for stopping by, come again soon");
      }
     }
    }
    Here is my separate class:
    Java Code:
    //I imported the decimal format
    import java.text.DecimalFormat;
    public class DigitalPhoto
    {
    	 //Here are my variable declaratoins
    	 DecimalFormat dollarsAndCents = new DecimalFormat("0.00");
    	 double scanAccuracy = 360000;
    	 double compress = 3.5;
        double Mbytes;  
    	 double transferTimeBits;
    	 static double transferTimeSeconds;
    	 static double storage;
    	 static double cost;
    	 static double area;
    
        
    	
    
    	
    	//Here is my method to convert seconds to an integer value
    	public static double transferTime(double totalStorage, double netSpeed)
    	{
    	 double transferTime = totalStorage / netSpeed;
    	 return transferTime;  
    	}
    	 
    
       
    	//Here is how I calculate how much space the photo will require
    	public static double datasize(double width, double length, double scanAccuracy, double compress)
       { 
        double bytes = (width * length * scanAccuracy) / compress;
        double Mbytes = bytes / 1000000;
        storage = Mbytes;  
    	 return Mbytes;
       }
    	//I use both of the methods below together in the main program
    	public static double area(double width, double length)
    	{
    	 double area1 = width * length;
    	 area = area1;
    	 return area1;
    	}
    	
    	
    	public static double cost(double area)
    	{
    	 double cost1 = area * .12;
    	 return cost1;
    	}
    	
    	
    
    
       public void showValues()
    	{
    	 System.out.println("Scanned Photo Details");
        System.out.println("Resolution: 600.00 pixels per inch");
        System.out.println("Compression Ratio: " + dollarsAndCents.format(compress));
        System.out.println("Required Storage: " + dollarsAndCents.format(storage));
        System.out.println("Cost of Scanning Photo: $" + dollarsAndCents.format(cost(area)));
        System.out.println();  
    	}
    
    
    }

  17. #17
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    In your Project class, I want you to add one line of code where I show you:
    Java Code:
          double transferTimeSeconds = photo.transferTime(totalStorage, netSpeed);
          
          // add this: 
          System.out.println("transferTime: " + transferTimeSeconds);
    Now you will see what the transfer time is in double format. Take that number and use a calculator to calculate the minutes and seconds, and you'll see why 0 and 0 are being displayed.

    Moral: Sometimes, your code may be correct, but your expectations for the output wrong.
    Lesson: Use println statements generously when testing your code.

  18. #18
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Default

    I finally understand it, thank you so much guys, couldn't have done it without you!

Similar Threads

  1. Replies: 6
    Last Post: 02-06-2009, 08:05 PM
  2. Compile/Execute code in Java app
    By Doctor Cactus in forum New To Java
    Replies: 5
    Last Post: 12-16-2008, 09:58 AM
  3. doesn't compile?!
    By jon80 in forum New To Java
    Replies: 8
    Last Post: 06-14-2008, 05:42 PM
  4. simple problem - code wont compile
    By dirtycash in forum New To Java
    Replies: 1
    Last Post: 11-20-2007, 05:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •