My first program.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: My first program.

  1. #1
    Join Date
    Oct 2004
    Posts
    12

    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.

  2. #2
    Join Date
    Sep 2004
    Posts
    26
    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

  3. #3
    Join Date
    Feb 2004
    Posts
    808

    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..
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

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