-
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);
};
}
}
-
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 07:36 AM.
-
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);
}
}
-
i have to write this program with guidlines from the book and thats what the book told me to write them with ... public static.
-
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.
-
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
-
By Chris H Baker in forum C++
Replies: 5
Last Post: 01-17-2007, 01:37 PM
-
By clarence_rollins in forum .NET
Replies: 21
Last Post: 09-11-2002, 11:32 AM
-
By Khalizan in forum VB Classic
Replies: 1
Last Post: 11-28-2001, 01:32 AM
-
Replies: 1
Last Post: 10-24-2000, 11:38 AM
-
By Tom Shreve in forum Enterprise
Replies: 0
Last Post: 04-07-2000, 09: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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks