it gives me one error


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: it gives me one error

  1. #1
    Join Date
    Nov 2005
    Posts
    68

    it gives me one error

    the code im about to enter gives me one error the error is

    \tuition.java:26: illegal start of expression
    public static void displaywelcome()
    ^
    1 error

    Code:
     /*___________________*/
    /* By- Elias Donahue */
    /*___________________*/
    
    
    
    import java.io.*;
    import java.text.DecimalFormat;
    
    
    public class tuition
    {
    	public static void main(String[] args) throws IOException
    	{
    	int hours;
    	double fees, rate, tuition, total;
    	BufferedReader datain = new BufferedReader(new InputStreamReader(System.in));
    
    	displaywelcome();
    	hours = gethours();
    	rate = getrate(hours);
    	tuition = calctuition(hours, rate);
    	fees = calcfees(tuition);
    	total = displaytotal(tuition + fees);
    
     public static void displaywelcome()
    {
    	System.out.println("\t\tWelcome Friend");
    }
    
    public static int gethours()
    {
    	String strhours;
    	int hours = 0;
    	try
    	{
    	System.out.println("Enter the amount of hours worked");
    	strhours = datain.readLine();
    	hours = Integer.parseInt(strhours);
    	}
    	catch(NumberFormatException e)
    	{
    		System.out.println("Please enter a valid number");
    	}
    }
    public static double getrate(int hours)
    {
    	 String strrate;
    	 double temp;
    	 double rate;
    	 try
    	 {
    	 strrate = datain.readLine();
    	 rate = Double.parseDouble(strrate);
    	 if(strrate > 15)
    	 {
    		temp = rate * 1.5;
    	 }
    	 rate = temp;
    	 }
    	 catch(NumberFormatException e)
    	 {
    		System.out.println("Please enter a valid number");
    	 }
    }
    
    
    public static double calctuition(int hours, double rate)
    {
    	double number1,tuition;
    	String strone;
    
    	System.out.println("Enter the rate at which you worked");
    	strone = datain.readLine();
    	number1 = Double.parseDouble(strone);
    
    
    
    	tuition = number1 * hours;
    	return tuition;
    }
    
    public static double calcfees(double tuition)
    {
    	double fees;
    
    
    	fees = tuition * .08;
    	return fees;
    }
    public static double displaytotal(double total)
    {
    	DecimalFormat twodigits = new DecimalFormat("$#,000.00");
    	System.out.println("This is the total of fees and tuition" + total);
    
    };
    }
    }

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    In looking at your code, the only thing I can suggest is to take the semi-colon out at the end of the definition of displaytotal

    AND

    have the definition of your various static methods be outside of the body of your method main.

    Code:
    public class tuition
    {
        public static void main(String[] args) throws IOException
        {
    	int hours;
    	double fees, rate, tuition, total;
    	BufferedReader datain = new BufferedReader(new InputStreamReader(System.in));
    
    	displaywelcome();
    	hours = gethours();
    	rate = getrate(hours);
    	tuition = calctuition(hours, rate);
    	fees = calcfees(tuition);
    	total = displaytotal(tuition + fees);
       } <-----
    
       public static void displaywelcome()
       {
    	System.out.println("\t\tWelcome Friend");
       }
    
    etc.
    As a sidebar ... do you have a design purpose in having all of your methods declared public and static?
    Last edited by nspils; 04-06-2007 at 08:36 AM.

  3. #3
    Join Date
    Nov 2005
    Posts
    68
    i fixed the code following your post but now it still doesnt compile properly. now when i compile it it gives me these four errors

    Code:
    F:\java\chapter 4\programs\tuition.java:40: cannot find symbol
    symbol  : variable datain
    location: class tuition
    	strhours = datain.readLine();
                       ^
    F:\java\chapter 4\programs\tuition.java:55: cannot find symbol
    symbol  : variable datain
    location: class tuition
    	 strrate = datain.readLine();
                       ^
    F:\java\chapter 4\programs\tuition.java:57: operator > cannot be applied to java.lang.String,int
    	 if(strrate > 15)
                        ^
    F:\java\chapter 4\programs\tuition.java:76: cannot find symbol
    symbol  : variable datain
    location: class tuition
    	strone = datain.readLine();
                     ^
    4 errors
    this is the changed code

    Code:
     /*___________________*/
    /* By- Elias Donahue */
    /*___________________*/
    
    
    
    import java.io.*;
    import java.text.DecimalFormat;
    
    
    public class tuition
    {
    	public static void main(String[] args) throws IOException
    	{
    
    	int hours;
    	double fees, rate, tuition, total;
    	BufferedReader datain = new BufferedReader(new InputStreamReader(System.in));
    
    	displaywelcome();
    	hours = gethours();
    	rate = getrate(hours);
    	tuition = calctuition(hours, rate);
    	fees = calcfees(tuition);
    	total = displaytotal(tuition + fees);
    
    }
    public static void displaywelcome()
    {
    	System.out.println("\t\tWelcome Friend");
    }
    
    public static int gethours()
    {
    	String strhours;
    	int hours = 0;
    	try
    	{
    	System.out.println("Enter the amount of hours worked");
    	strhours = datain.readLine();
    	hours = Integer.parseInt(strhours);
    	}
    	catch(NumberFormatException e)
    	{
    		System.out.println("Please enter a valid number");
    	}
    }
    public static double getrate(int hours)
    {
    	 String strrate;
    	 double temp;
    	 double rate;
    	 try
    	 {
    	 strrate = datain.readLine();
    	 rate = Double.parseDouble(strrate);
    	 if(strrate > 15)
    	 {
    		temp = rate * 1.5;
    	 }
    	 rate = temp;
    	 }
    	 catch(NumberFormatException e)
    	 {
    		System.out.println("Please enter a valid number");
    	 }
    }
    
    
    public static double calctuition(int hours, double rate)
    {
    	double number1,tuition;
    	String strone;
    
    	System.out.println("Enter the rate at which you worked");
    	strone = datain.readLine();
    	number1 = Double.parseDouble(strone);
    
    
    
    	tuition = number1 * hours;
    	return tuition;
    }
    
    public static double calcfees(double tuition)
    {
    	double fees;
    
    
    	fees = tuition * .08;
    	return fees;
    }
    public static double displaytotal(double total)
    {
    	DecimalFormat twodigits = new DecimalFormat("$#,000.00");
    	System.out.println("This is the total of fees and tuition" + total);
    
    }
    }

  4. #4
    Join Date
    Nov 2005
    Posts
    68
    i have to write this program with guidlines from the book and thats what the book told me to write them with ... public static.

  5. #5
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Re static: I understand. But this is not the usual way of writing a program.

    where you have "datain" : is that supposed to be "data.in" (notice the "dot" between "a" and "i")?

    as to the "strrate > 15" issue: since you have already parsed strrate to be the double "rate", will your program work as planned if you replace the condition with "rate > 15"?

    your next lines are going to give you trouble: if you never enter the loop you have no value for "temp". My suggestion is that you have "rate = rate * 1.5" as the statement within the if-clause, and remove the "rate = temp" statement - unless it is your intent to have some other value be the value of temp ... if so, then assign that value to temp when you declare it.

  6. #6
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    I went back and looked at your code, again. I see where datain is declared.

    Right now, the "scope" of your datain BufferedReader is solely within the confines of your method main. It is not available inside any other of your methods. Therefore, you will either have to declare datain outside of main, or else pass your datain object to each of the methods which will be extracting data from the file. Since all of your methods are static, if you declare the object outside of method main it (datain) will also need to be static.

Similar Threads

  1. Replies: 5
    Last Post: 01-17-2007, 02:37 PM
  2. 'On Error Goto' versus 'Try, Catch, Fail'
    By clarence_rollins in forum .NET
    Replies: 21
    Last Post: 09-11-2002, 12:32 PM
  3. Returning errors from SQL Server Stored Procs
    By Khalizan in forum VB Classic
    Replies: 1
    Last Post: 11-28-2001, 02:32 AM
  4. WinForm Compile Error
    By Robert in forum .NET
    Replies: 1
    Last Post: 10-24-2000, 12:38 PM
  5. Replies: 0
    Last Post: 04-07-2000, 10:19 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center