Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 03-14-2005, 09:32 PM   #1 (permalink)
Insane
 
Kalibah's Avatar
 
Location: Padded Playhouse
[Java] Input line help

First off I'm a complete newbie
Now that we have that taken care of:
The program has to be part of a problem we have, and then we solve it. I'm taking physics- and were on power and currents so voila - thats my problem!

At my system.out.println I'm getting illegal start of expression and ")" expected.

I'd appreciate any help or corrections anyone could offer. I'm not going to be a programmer- this was just sort of a fun course. I'm sorry if these are newb mistakes ( often I forget the simplest thing!).
I'm really winging it here.


Code:
/*
 This program will find the current and power if you have reistance and voltage, OR it will find voltage and power if you have current and reistance. 
*/
import java.io.*;
public class Phyiscs
{
	double current;
	double power;
	double voltage;
	public static void	main(String args[])
	{
	
  		System.out.println("This program will help you find the current and power if you have the reistance and voltage. OR It will find the voltage and power if you have  the current and reistance.");   
  		System.out.println("Please type 0 if you have the resistance and voltage, or type 1 if you have the current and resistance");
     


 		String inputLine = keyboard.readLine();
        if ( inputLine == 0 ) {
         System.out.println(" Please enter the Resistance: ");	
         double resistance = keyboard.readLine();
         System.out.println(" Please enter the voltage: ");
         double voltage = keyboard.readLine();
         current=voltage/resitance;
         System.out.println( " The current is:"+current+);
         power=current*voltage;
         System.out.println( "The power is:"+power+);
          }
          else 
          {
           System.out.println(" Please enter the current: ");
           double current = keyboard.readLine();
           System.outprintln(" Please enter the resistance: ");
           double resistance = keyboard.readLine();
           voltage=current*resistance;
           System.out.println("The voltage is: " +voltage+);
           power=current*voltage;
           System.out.println("The Power is:" +power+);
          }
      
      }
 }

Last edited by Kalibah; 03-14-2005 at 09:57 PM..
Kalibah is offline  
Old 03-14-2005, 10:14 PM   #2 (permalink)
aka: freakylongname
 
Chamaeleontidae's Avatar
 
Location: South of the Great While North
try this... Keep in mind that you will need to check for bad entries etc... but I got what you had to compile and run with some changes... you can't assign a string to a double, you had extra + chars in the print lines... to name a few...

Code:
import java.io.*;
import java.lang.Double.*;

public class Phyiscs
{
   static double current;
   static double power;
   static double voltage;
   static double resistance;
    
   public static void   main(String args[])
   {
   
      System.out.println("This program will help you find the current and power if you have the reistance and voltage. OR It will find the voltage and power if you have  the current and reistance.");   
      System.out.println("Please type 0 if you have the resistance and voltage, or type 1 if you have the current and resistance");
     
      BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); 
      
      try{        
          String inputLine = keyboard.readLine();
          if ( Double.parseDouble(inputLine) == 0 ) {
            System.out.println(" Please enter the Resistance: "); 
            resistance = Double.parseDouble(keyboard.readLine());
            System.out.println(" Please enter the voltage: ");
            voltage = Double.parseDouble(keyboard.readLine());
            current=voltage/resistance;
            System.out.println( " The current is:"+current);
            power=current*voltage;
            System.out.println( "The power is:"+power);
          }
          else 
          {
            System.out.println(" Please enter the current: ");
            current = Double.parseDouble(keyboard.readLine());
            System.out.println(" Please enter the resistance: ");
            resistance = Double.parseDouble(keyboard.readLine());
            voltage=current*resistance;
            System.out.println("The voltage is: " +voltage);
            power=current*voltage;
            System.out.println("The Power is:" +power);
          }
      
      } catch(Exception e){
          System.out.println("error");
      }
   }
 }
__________________
"Reality is just a crutch for people who can't cope with drugs."
Robin Williams.
Chamaeleontidae is offline  
Old 03-15-2005, 01:00 AM   #3 (permalink)
Insane
 
Kalibah's Avatar
 
Location: Padded Playhouse
Finally got it working thanks for help

After furthur reading of assignment
yes yes I know I should read it ALL before I started- but I took one look at it and said OMG i will never be able to do this- put it down. Went to work on some physics and bam it hit me what to do. Next thing I know I start working it out - only to find out I HAVE TO USE EasyReader for user input, as well as having multiple methods

So after some tweaking I got it figured out

thanks for help
Kalibah is offline  
 

Tags
input, java, line

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 08:59 AM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57