Here's a question i got in my assignment...

Create a method with signature

public String testWindDirection()

that creates a local object of type WeatherReport using the constructor with no parameters,
and returns its initial wind direction, e.g "ESE"

I createrd it here...

public class Reporter
{
    private WeatherStation ws;
    private WeatherReport wr;
    private WeatherStation temperature;
    private WeatherReport winddir;
 
    /** Constructor for objects of class Report
     */
    public Reporter()
    {
        ws = new WeatherStation("Tropical");
        wr = new WeatherReport();
    }
    
    /** Returns initial temperature value
     */
    public int testTemperature()
    {
        temperature = ws;
        return temperature.getTemperature();
    }
    
    /** Comment...
     */
    public String testWindDirection()
    {
        this.winddir = wr;
        return winddir.getWindDirection();
    }
    
     /**
     * Constructor for objects of class Report
     * @param where Location?
     */
    public Reporter(String where)
    {
        ws = new WeatherStation(where);
        wr = new WeatherReport();
    }
}

This runs, but doesn't produce the exact result. Here is the error i get when it is tested...

The output should have been:
WeatherStation in TROPICAL zone created
WeatherReport for Mt Erebus created
Test 2
WeatherReport for Mt Erebus created
Default WeatherReport has wind direction of S

This is what was actually produced:
WeatherStation in TROPICAL zone created
WeatherReport for Mt Erebus created
Test 2
Default WeatherReport has wind direction of S

Can someone see something wrong in my code?

It doesn't produce another WeatherReport for Mt Erebus.

post your main method...

Well they are all relavent, but this is probably the important one...

public Reporter(String where)
    {
        ws = new WeatherStation(where);
        wr = new WeatherReport();
    }

No. I literally mean post the method that is declared as "public static void main(String[] args)"... this is the method that is executed when you run your program.

I don't know how to do that.

When i create a method i don't set it up like that.

Huh? The main method is the method that runs automatically when you run a .java file, or when you click 'run' (or the corresponding button) in Eclipse or Netbeans or whatever editor you use. If this isn't the case, then tell me what method is running first in your code...

Huh? The main method is the method that runs automatically when you run a .java file, or when you click 'run' (or the corresponding button) in Eclipse or Netbeans or whatever editor you use. If this isn't the case, then tell me what method is running first in your code...

I'm using BlueJ, there's no run button or anything like that.

I have to create a new object. The is done with the "Reporter()" method and it opens up a terminal window, that outputs this...

WeatherStation in TROPICAL zone created
WeatherReport for Mt Erebus created

In the first post, that's the whole class and the methods that are in it.

If you can't work out my program, then it's alright, i keep looking at it until i solve the problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.