ProgramWindowJava

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.

Replay:My first program.
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

Replay:My first program.
Quote:
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..

[Previous] Threads
[Next] memory address?

Google


Java

memory address?
executable java file
Bitwise comparison?
Can't figure out Static Error?
Help!! using recursion to search an array
Encrypt / Decrypt homework help
Menus
help!!!!!!!!!!!!!!!
How to access JSpinner's JTextField?
easy questions
recursion/iterator problem
repainting the whole frame??
Help Wih Chessboard Problem
Format US currency
Applet:How do I get a background image.
ArrayList printout?
Get rid of that comma in my JSpinner!!!
calling other classes
Variables not visable?
return statement trouble