Java Program - Forecast

Can anyone help? Below is my program and I am getting 1error message when compiling and I can't figure it out.
* WeatherForecast.java
* Created on November 7, 2006, 9:38 AM
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
package weatherforecast;
* Cynthia Castillo 1385177
* COP2250, Java Programming, Section 6
* Assignment #4
public class WeatherForecast
private double temperature; // in Fahrenheit
private String sky;
* Default constructor:
* initializes temperature to 70.0 and sky to "sunny"
* calls mutator methods to validate these default values
public WeatherForecast( )
temperature = 70;
sky = "sunny";
* Overloaded constructor:
* Allows client to set beginning values for temperature and sky
public WeatherForecast( double newTemperature, String newSky )
temperature = newTemperature;
sky = newSky;
//Accessor Method:
//returns temperature
public double getTemperature() //return temperature
return temperature;
//Accessor Method:
//returns sky conditions
public String getSky( ) //return the sky conditions
return sky;
* Mutator method:
* Allows client to set value of temperature
* setTemperature sets the value of temperature
* to 70.0 if newTemperature is less than -50 or greater than 150
public void setTemperature( double newTemperature )
if(temperature >= 0)
temperature = newTemperature;
else
System.err.println( "Temperature cannot be below -32." );
System.err.println( "Temperature not changed.");
* Mutator method:
* Allows client to set value of sky
* setSky sets the value of sky
* to "sunny" if newSky is neither "sunny", "snowy",
* "cloudy", nor "rainy"
public void setSky( String newSky )
newSky = newSky();
if(newSky <=0)
sky = newSky;
else
System.err.println( "Illegal value for sky." );
System.err.println( "Sky set to sunny." );
//The toString Method:
public String toString( )
return( "temperature: " + temperature + "; sky: " + sky );
/* Equals method:
* Compares two WeatherForecast objects for the same field values
* wf used as another WeatherForecast object
* return a boolean, true if this object
public boolean equals( WeatherForecast wf )
return ( Math.abs( temperature - wf.temperature ) < 0.0001
&& sky.equals( wf.sky ) );
* fahrenheitToCelsius method
* Computes the degrees Celsius temperature
* return a double, the temperature value in degrees Celsius
public double fahrenheitToCelsius( )
temperature = temperature - 32;
temperature = temperature * 5;
temperature = temperature / 9;
return temperature;
public static void main (String [] args)
double celsius;
double fahrenheit;
double fahrenheit = Double.parseDouble(args[0]);
double celsius = (5.0 / 9.0)*(fahrenheit -32);
* isConsistent method
* Checks if the temperature value and the sky conditions are compatible
* return a boolean, false if the temperature is below 32 and the sky is not snowy,
* or if the temperature is greater than 100 and the sky is not sunny, true otherwise
public boolean isConsistent()
return !( ( temperature < 32 && !sky.equals( "snowy" ) )
|| ( temperature > 100 && !sky.equals( "sunny" ) ) );
/* WeatherForecast Client*/
public class WeatherForecastClient
public static void main( String [] args )
WeatherForecast wf1 = new WeatherForecast( 23,"sunny" );
WeatherForecast wf2 = new WeatherForecast( 200, "rainy" );
System.out.print( "The temperature of weather forecast #1 is " + wf1.getTemperature( ) );
System.out.println( "F or " + wf1.fahrenheitToCelsius( ) + "C");
System.out.println( "The sky condition of weather forecast #1 is " + wf1.getSky( ) );
System.out.println( "Weather forecast #2 is " + wf2.toString( ) + "\n" );
if ( wf1.isConsistent( ) )
System.out.println( "weather forecast " + wf1 + " is consistent" );
else
System.out.println( "weather forecast " + wf1 + " is not consistent" );
if ( wf2.isConsistent( ) )
System.out.println( "weather forecast " + wf2 + " is consistent" );
else
System.out.println( "weather forecast " + wf2 + " is not consistent" );
System.out.println( );
if ( wf1.equals( wf2 ) )
System.out.println( "Original weather forecasts #1 and #2 are identical" );
else
System.out.println( "Original weather forecasts #1 and #2 are different" );
wf2.setTemperature( 23 );
wf2.setSky( "sunny" );
if ( wf1.equals( wf2 ) )
System.out.println( "Original weather forecast #1 and modified weather forecast #2 are identical" );
else
System.out.println( "Original weather forecast #1 and modified weather forecast #2 are different" );
}

Where exactly is the error occurring?
When you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. It makes it much easier to read.

Similar Messages

  • Error while running a Java Program

    Can anyone help me,
    I am getting the following error while running a Java program, Below is the exception thrown, please help.
    java.nio.BufferOverflowException
    at java.nio.Buffer.nextPutIndex(Buffer.java:425)
    at java.nio.DirectByteBuffer.putChar(DirectByteBuffer.java:463)
    at org.jetel.data.StringDataField.serialize(StringDataField.java:295)
    at org.jetel.data.DataRecord.serialize(DataRecord.java:283)
    at org.jetel.graph.DirectEdge.writeRecord(DirectEdge.java:216)
    at org.jetel.graph.Edge.writeRecord(Edge.java:288)
    at com.tcs.re.component.RESummer1.run(RESummer1.java:505)
    java.nio.BufferOverflowException
    at java.nio.Buffer.nextPutIndex(Buffer.java:425)
    at java.nio.DirectByteBuffer.putChar(DirectByteBuffer.java:463)
    at org.jetel.data.StringDataField.serialize(StringDataField.java:295)
    at org.jetel.data.DataRecord.serialize(DataRecord.java:283)
    at org.jetel.graph.DirectEdge.writeRecord(DirectEdge.java:216)
    at org.jetel.graph.Edge.writeRecord(Edge.java:288)
    at com.tcs.re.component.RECollectCont.run(RECollectCont.java:304)

    Ok, let's see. Write the following class:
    public class Grunt {
      public static void main(String[] args) {
        System.out.println("Hello Mars");
    }Save it as "C:\Grunt.java", compile by typing:
    javac c:\Grunt.javaRun by typing:
    java -classpath "C:\" GruntDoes it say "Hello Mars"? If yes, go back to your program and compare for differences (maybe you used the "package" statement?).
    Regards

  • Running a java program a set number of times

    This is a general question. Is it possible to make a java program run only 5 times for the sake of arguement.
    Basically I want to write a program that will give the user some flexibility when it will actually run another Java program, but I only want them to be able to say "not now' for a set number of times. When the last time comes the other program will launch. I was initially thinking of the Do Whilw loop, but this needs to work when the program is restarted.
    Program starts, it has 5 times it will run before it does something else(doesn't really matter now I think). User takes option "Not Now" and the program ends, but warns the user this will run 4 more times before you will need to do something.
    This process will repeat until the user takes the option "Ok install now" or the time limit expires and the install occurs anyway. Can someone point me in the right direction.

    ok I see so it's like one those programs that you download for free on the internet and they give you a set amount times to use it before you have to pay for it. but in this case when the number of times you use it equals 5 (or when the user clicks ok) a different java app will open automatically.
    My first thought would be to Write a Serialized object to disk using objectOutputStream that stores the number of times the application has been opened. and each time the program runs it checks for the serialized object and then you can do something like what I posted before. of course if were worried about security the user could always look for the object and erase it, if so then I guess we would have to come up with another plan of attack
    Hope this helps

  • Running a java program

    This shows how dumb i am.
    I have a java program all wrote. How can i run it without using the compiler? Can i have a .exe file or something that I just have to click on to run??
    Thanks again
    Agdude

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.
    C:\Documents and Settings\awaguespack>cd jbproject\untitled1\classes\untitled1
    C:\Documents and Settings\awaguespack\jbproject\untitled1\classes\untitled1>java
    form
    Exception in thread "main" java.lang.NoClassDefFoundError: form (wrong name: unt
    itled1/form)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    C:\Documents and Settings\awaguespack\jbproject\untitled1\classes\untitled1>dir
    Volume in drive C has no label.
    Volume Serial Number is C065-81CA
    Directory of C:\Documents and Settings\awaguespack\jbproject\untitled1\classes\
    untitled1
    07/24/2003 02:21 PM <DIR> .
    07/24/2003 02:21 PM <DIR> ..
    07/24/2003 02:21 PM 7,655 form.class
    1 File(s) 7,655 bytes
    2 Dir(s) 36,031,016,960 bytes free
    C:\Documents and Settings\awaguespack\jbproject\untitled1\classes\untitled1>echo
    %classpath%
    %classpath%
    C:\Documents and Settings\awaguespack\jbproject\untitled1\classes\untitled1>

  • Running a java program at "Start Up"

    Besides running an html file with an applet in it. Are there any simple ways to launch a java program every time the computer is turned on.
    I am not asking for specific directions, but rather just an idea, and i will go find my own guide.

    Well two ideas (if ur on windows) u could try are -
    one, if you had a class file you could simply create a
    batch file on windows that says java <class> and then
    put that batch file in your startup so that the class
    is run at startup or else you could think of modifying
    the registry keys on windows to run this class at
    startup - whichever works for you.Or you could just jar the program up, adding a Main-Class indicator in the manifest, and then add a shortcut to the jar to the startup folder, as someone else stated. Theres little need to go messing around with DOS batch in modern windows.

  • Running a java program from an icon

    I want to run my program from an icon on my desktop. I have a .bat file that I've built a shortcut to and it works.MY GUI program does display and run when I click on the icon. The problem is that the DOS window also shows up behind my GUI.
    Is there anyway to prevent the DOS window from showing? Or is there another way to run a Java program without resorting to a DOS command line or running it through FORTE or another IDD?

    Chris's solution worked well, with one small problem. Once my GUI starts, it takes up the whole screen. Normally when I run it, it appears as a small window.
    not a big problem, I can reduce it easily after it starts. But does anyone know a way to make it come up in the reduced size it norally comes up in when I run it from my IDE?

  • Running a java program via a batch file

    I am unable to run a java program from a batch file that I created.
    spiderpackage.EntryPoint is a class file which I am trying to run with a -v option to output something.What should I do to get the output?
    echo ^<html^>^<body^>
    echo hello^<br^>
    call java spiderpackage.EntryPoint -v
    echo ^</body^>^</html^>

    This has nothing to do with java programming. Have a look at the windows help for the call command.
    The echo <html> stuff doesn't make sense. What's it for?
    The command in you batch file should be:
    java -cp . spiderpackage.EntryPoint -v
    assuming that java is in the system path, and the EntryPoint.class is in a directory called spiderpackage which is a subdirectory of your current working directory

  • Running a Java program at startup in Linux

    Hello
    How do I run a Java program at startup in Linux? I know in Windows I can put a .bat file in C:\Windows\Start Menu\Programs\StartUp\ directory, but in Linux I have no idea how it is done.
    Thank you,
    Mihai

    This is really a Linux question, not Java.
    And then it depends on the version of Linux you are using.
    Maybe this will help, otherwise you should try on a forum for your version of Linux.

  • Running a java program in a directory other than the current directory

    How do I run a java program that's located in a directory other than the current directory?
    There is a file Test.java in /dir1/subdir1. If my current directory is anywhere other than that directory, say /dir2/subdir2, I can compile Test.java by using:
    javac -classpath /dir1/subdir1 /dir1/subdir1/Test.java
    But when I try to run it with:
    java -classpath /dir1/subdir1 /dir1/subdir1/Test
    I get a java.lang.NoClassDefFoundError: \dir1\subdir1\Test
    Any thoughts?

    You need to specify just the name of the class you want to run. So java -classpath /dir1/subdir1 Test

  • Running a java program outside eclipse...!

    Hi guys...!
    I wrote a java program that uses different classes. The program deals with xml documents and creates a new xml document. The problem is, the program works fine in eclipse, but when I run through the command line in windows, it complains that it can't see the different classes that I created. Here is one of the error messages:
    Test.java:44:cannont find symbol
    symbol : class Circuit
    location : class src.Test
    Circuit cir = new Circuit ();
    Note: Test.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details
    Does anyone know how to resolve this...?
    Any help from you guys will be very appreciated.
    Thanks..

    I think the problem is probably something like this:
    You have a path thus:
    C:\blahblahblah\With a subdirectory thus:
    C:\blahblahblah\srcIn which you have declared classes thus:
    package src;
    public class Foo {
    }And you have then used a classpath something like the
    following:
    javac -classpath C:\blahblahblah\src Foo.javaThis is incorrect. Your classpath needs to point to
    the root of the package hierarchy. If it's like the
    above, it will look in C:\blahblahblah\src for a
    package src, which results in a path like
    C:\blahblahblah\src\src which does not exist.
    You should set it to:
    C:\blahblahblah\Where that is the root from which your packages
    stem.
    Dave.Thanks Dave. It works man. I really appreciate your help.

  • Running a Java Program for every shut down of system

    Hi
    I have a java program that sends an email to the Admin of my network.
    But this is program i just want to execute for every shutdown and on of my system
    Please Tell me how to execute my java program at system shutdown time and on time..
    Thanks

    Despite your objective, this is not a Java issue. The real question is "How does one run a program just before system shutdown?"
    How you execute such an application is system dependent. Java doesn't know when the system shuts down, only when the JVM shuts down. Unless you're willing to have JVM running the entire time the system is up, you'll need native code to detect system shutdown & launch the notification app.

  • Running a java program over network

    Hi,
    How a java program on a machine can be run without having JRE on the same machine, rather interpreting bytecode over network having JRE on another machine?

    Rahul.Kumar wrote:
    well, so my java program is running on x. Initialy X had JRE and on invoking java program from command prompt, it had looked for JRE at path, set in environmental settings. Now I moved JRE to another machine Y and connected these two machines (X and Y). You have two machines X and Y.
    "Connected" or not has nothing to do with this discussion.
    In X path is set to the JRE on Y. The path on X has absolutely nothing to do with anything on Y.
    Now execute java program on X, theoretically it should work or what is wrong with this?This makes no sense. Presuming you meant Y in the above then the following must be true.
    1. You must have a JRE on Y.
    2. You must have a java application on Y (or one accessible via the file system on Y.)
    3. You must be on Y and start the JRE passing the java application that is on Y to it.
    Notice in the above there is no mention of X. There can be no mention of X.

  • Running a Java program on HP UX

    Hi everyone
    First time in life i have to make a Java program run on HP UX... the program is running perfectly in windows environment..... but when i copy the program to HP-UX and try to run it gives me following error
    -----------------End Configuration-------------------------
    Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Savepoint
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$1(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
    va:468)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:314)
    at java.sql.DriverManager.getConnection(DriverManager.java:517)
    at java.sql.DriverManager.getConnection(DriverManager.java:177)
    at StatInterface.main(StatInterface.java:58)
    I can guess that this has something to do with Class path or java home... i even don't know how to set paths in HP-UX
    can u ppl help me?
    Following are the details
    OS Version = HP-UX rpsvr02 B.11.11 U 9000/800 (ta)
    JVM = java version "1.3.1.02" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1.02-011206-02:17) Java HotSpot(TM) Server VM (build 1.3.1 1.3.1.02-JPSE_1.3.1.02_20011206 PA2.0, mixed mode)
    $PATH value
    .:/home/express/bin:/home/express/bin:/home/express/BIN:/usr/local/bin:/opt/java1.3/bin:/home/oracle/product/9.2.0.1.0/bin:/usr/bin:/usr/ccs/bin:/usr/contrib/bin:/opt/mx/bin:/opt/hparray/bin:/opt/nettladm/bin:/opt/upgrade/bin:/opt/fcms/bin:/opt/pd/bin:/opt/resmon/bin:/usr/bin/X11:/usr/contrib/bin/X11:/opt/graphics/common/bin:/opt/scr/bin://opt/perl/bin:/usr/sbin/diag/contrib:/opt/hpnpl//bin:/usr/bin/X11:/usr/sbin:/opt/java1.3/bin
    I really need your help.. and it is really urgent.. plz
    Thanx in advance

    In the documentation for Savepoint it states "since 1.4"
    You need a more recent version of java. I suggest using asupported version like 1.4.2_08 or 1.5.0_04 if you can get them.
    If not try getting the source for 1.6.0 and compiling it for HPUX.

  • Error while executing HelloWorld.java program

    Hi All,
    I am trying to execute the samples(HelloWorld.java) program from Jdeveloper and provided the following details in runtime.defaults:
    CONTENT_DB_URL
    ADMIN_USER_NAME
    ADMIN_USER_PASSWORD
    however getting the following exception:
    FdkException:
    Error Code: ORACLE.FDK.UnexpectedError
    Detailed Error Code: ORACLE.FDK.FeatureNotEnabled
    Trace Id:
    info (NamedValue[]): null
    can any one please help me to resolve this issue.
    Thanks
    Krrish.

    See the Cleartext Authentication note in the running_client_samples.html file of the CDB devkit.
    The default configuration for an out-of-box Oracle Content DB installation allows Cleartext Authentication only if SSL has been enabled (and the Web Services connection string begins with https). See the authentication topic for details.
    To allow Cleartext Authentication to take place over standard (non-SSL) HTTP, set the Oracle Content DB domain property IFS.DOMAIN.WS.CleartextAuthenticationRequiresHttps to false using Enterprise Manager (Application Server Control). See the Content DB Administration Guide for details.
    If the domain property above is not modified to false and Cleartext Authentication is attempted using using standard HTTP, an FdkException will be thrown:
    ORACLE.FDK.UnexpectedError : ORACLE.FDK.FeatureNotEnabled
    cheers
    Matt.

  • High CPU usage while running a java program

    Hi All,
    Need some input regarding one issue I am facing.
    I have written a simple JAVA program that lists down all the files and directories under one root directory and then copies/replicates them to another location. I am using java.nio package for copying the files. When I am running the program, everything is working fine. But the process is eating up all the memories and the CPU usage is reaching upto 95-100%. So the whole system is getting slowed down.
    Is there any way I can control the CPU usage? I want this program to run silently without affecting the system or its performance.

    Hi,
    Below is the code snippets I am using,
    For listing down files/directories:
            static void Process(File aFile, File aFile2) {
              spc_count++;
              String spcs = "";
              for (int i = 0; i < spc_count; i++)
              spcs += "-";
              if(aFile.isFile()) {
                   System.out.println(spcs + "[FILE] " + aFile2.toURI().relativize(aFile.toURI()).getPath());
                   String newFile = dest + aFile2.toURI().relativize(aFile.toURI()).getPath();
                   File nf = new File(newFile);
                   try {
                        FileCopy.copyFile(aFile ,nf);
                   } catch (IOException ex) {
                        Logger.getLogger(ContentList.class.getName()).log(Level.SEVERE, null, ex);
              } else if (aFile.isDirectory()) {
                   //System.out.println(spcs + "[DIR] " + aFile2.toURI().relativize(aFile.toURI()).getPath());
                   String newDir = dest + aFile2.toURI().relativize(aFile.toURI()).getPath();
                   File nd = new File(newDir);
                   nd.mkdir();
                   File[] listOfFiles = aFile.listFiles();
                   if(listOfFiles!=null) {
                        for (int i = 0; i < listOfFiles.length; i++)
                             Process(listOfFiles, aFile2);
                   } else {
                        System.out.println(spcs + " [ACCESS DENIED]");
              spc_count--;
    for copying files/directories:public static void copyFile(File in, File out)
    throws IOException {
    FileChannel inChannel = new
    FileInputStream(in).getChannel();
    FileChannel outChannel = new
    FileOutputStream(out).getChannel();
    try {
    inChannel.transferTo(0, inChannel.size(),
    outChannel);
    catch (IOException e) {
    throw e;
    finally {
    if (inChannel != null) inChannel.close();
    if (outChannel != null) outChannel.close();
    Please let me know if any better approach is there. But as I already said, currently it's eating up the whole memory.
    Thanks in advance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for