Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java Homework

Name: Anonymous 2011-11-08 22:24

Hey guys, I know this is homework and if you don't feel like helping that's fine. I'm just getting stumped by this code and I'm getting a little desperate.


import java.util.*;
import java.text.DecimalFormat;

public class WeatherStation {    

    static int HowMany = 0;
    static Scanner input = new Scanner(System.in);
    private static double[] Weather, Celsius = new double[HowMany];
    private static double WeatherFSum = 0, WeatherCSum = 0;
    private static double FMean = WeatherFSum / HowMany;
    private static double CMean = WeatherCSum / HowMany;
    public static String Command = "";
   
    private static class WeatherData {
        public String StationDesignation;
        public double Temperature;
       
        public WeatherData(String ID, double Temp) {
            StationDesignation = ID;
            Temperature = Temp;
        }
        };
       
        public static void main(String[] args) {
                System.out.print("What is your command? ");
                Command = input.nextLine();
                if(Command.equals("Fill"))
                    Fill();
                else if(Command.equals("Display"))
                    Display();
            }
       
        public static void Fill() {
            int X;
            String Item;
            double Entry;
            System.out.print("Hello!\n\nHow many weather stations will we be checking on? ");
            HowMany = input.nextInt();
            WeatherData[] Weather = new WeatherData[HowMany];
            for(X = 0; X < HowMany ; X++) {
               
            System.out.println("Please enter the name for WeatherStation" + X + ": ");
            Item = input.next();
            if(Item.equals("Stop")) break;
            System.out.println("Please enter temp in fahreinheit: " );
            Entry = input.nextDouble();
            WeatherData[X] Weather = new WeatherData(Item, Entry);
            }
        }




I know that the last line with WeatherData[X] and all that other stuff is complete crap. I get errors upon errors with that. But I'm trying to work out how to make an array of this datatype that I created, and then assign values from the keyboard to instances of that datatype.

Can anyone help? I've googled and searched around but none of the explanations seem to click.

Name: Anonymous 2011-11-08 22:37

wow, there are awful amount of homeworks on /prog/ today. did we got popular on /g/ or what?

Name: Anonymous 2011-11-08 22:39

I haven't seen anyone mention you guys on /g/. I'm guessing that it's just the nature of the academic term. I'm guessing these threads are less common during the summer and around August/September when classes are just getting started.

Anyway...

Name: Anonymous 2011-11-08 22:41

well, the problem is you are accessing your array. try
Weather[X] = new WeatherData(Item, Entry);

Name: Anonymous 2011-11-08 22:41

Let's say you come upon a cretin asking for help. The language is VB, Java, PHP, or basic C. He's too much of a dolt to use the [code] tags. His code is offensively bad and his question is easily answered by a quick google search. Add some imageboard vocabulary and lack of any punctuation whatsoever for good measure.

Why do you help people like these?

Name: Anonymous 2011-11-08 22:45

>>5
why are you bumping this thread?

Name: Anonymous 2011-11-08 23:14

>>6
What?

Name: HAXUS THE REAL 2011-11-08 23:41

>>1 this ain't dis.4chan.homework ``FAGSTORM''
split and do not return until mootles chnages the DNS for this board to be more relevant to your basement dwellingf 1%er needs

Name: Anonymous 2011-11-08 23:42

>>4
That's really helpful! Thank you!

>>5
Didn't know about the [code] tags, but thanks for the passing reference to it, I'll look into using that in the future.

Also I pointed out that the code was a mess and that it was perfectly fine if you didn't want to help. I don't know what else I could have said in this case. Just because you look down on this code doesn't mean I'm *not* going to ask for help.

I've still got some stuff I'm trying to figure out, but I won't bother you guys over this apparently contentious issue any longer. Thanks to those of you who helped.

Name: Anonymous 2011-11-09 16:31

Try the BeanWeatherDataInjectorFactorySingleton

Don't change these.
Name: Email:
Entire Thread Thread List