-
My first program.
This is the best I can do. Can someone tell what is wrong with it, when I try to compile it, I get wierd errors.
Code:
public class calltime
{
public static void main(String[] args)
{
KeyboardReader reader = new KeyboardReader();
double calllength = reader.readDouble(" Enter the total time that you talked: "),
talk;
}else
if(calltime > 2){
talk = 1.15
calllength -= 2;
talk += calllength * 0.5;
}else{
talk = 1.15
}
}
The original problem is -
A 2-minute telephone call to Lexington, Virginia, costs $1.15. Each additional minute costs $0.50. Write a program that takes the total length of a class in minutes as input and calculates and displays the cost.
-
Hi there.
Did you write KeyboardReader or is it a class that you are allowed to use for the assignment?
You are probably getting an error from the line where you are trying to do reader.readDouble because you are doing this
reader.readDouble(" bla "), talk;
In most instances you would go class.method(parameter, parameter); The , talk is comfusing the compiler because it's not a valid format.
Can you give us the source for the KeyboardReader and I'll show you how to correct this.
Cheers,
Rachel
-
Re: My first program.
Originally posted by akamjballar
This is the best I can do. Can someone tell what is wrong with it, when I try to compile it, I get wierd errors.
Code:
public class calltime
{
public static void main(String[] args)
{
KeyboardReader reader = new KeyboardReader();
double calllength = reader.readDouble(" Enter the total time that you talked: "),
talk;
}else
if(calltime > 2){
talk = 1.15
calllength -= 2;
talk += calllength * 0.5;
}else{
talk = 1.15
}
}
The original problem is -
A 2-minute telephone call to Lexington, Virginia, costs $1.15. Each additional minute costs $0.50. Write a program that takes the total length of a class in minutes as input and calculates and displays the cost.
just sit down and read your program.. pretend to be a dumb robot, who operates on simple rules like "cannot encounter an ELSE without an IF first"..
you'll see that big chunks of code is missing,a nd your code doesnt actually make sense..
if it were a recipe for making mashed potato, it would look like this:
boil potatoes;
drain water;
butter and milk,
otherwise:
allow to cool slightly;
add to plate;
could you actually follow that LITERALLY and make mashed potato, without using your imagination? at what stage of the process did i actually tell you to mash the potatoes? i didnt.. you could guess, but you might wonder why i was suddenly saying "butter and milk" to you.. butter and milk what?
see how missing info is a bif problem for a computer..
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