Tilted Forum Project Discussion Community

Tilted Forum Project Discussion Community (https://thetfp.com/tfp/)
-   Tilted Technology (https://thetfp.com/tfp/tilted-technology/)
-   -   Java: Input line help (https://thetfp.com/tfp/tilted-technology/85392-java-input-line-help.html)

Kalibah 03-14-2005 09:32 PM

[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. :hmm:

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+);
          }
     
      }
 }


Chamaeleontidae 03-14-2005 10:14 PM

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");
      }
  }
 }


Kalibah 03-15-2005 01:00 AM

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 :thumbsup:


All times are GMT -8. The time now is 07:50 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2026, 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