hi im having a hard time fixing and identifying the problem. sorry abstraction really confuses me. the problem is I should write a weather prediction program using the random number generator. three outcomes should be possible: rain sun and cloud.
import java.util.Random;
public abstract class WeatherPredicMain
{
public static void main(String [] args)
{
public String Rain;
public String Sun;
public String Cloud;
public String Random;
public WeatherPredicMain()
{
}
public void setRain(String Rain)
{
this.Rain=Rain;
}
public void setSun(String Sun)
{
this.Sun=Sun;
}
public void setCloud(String Cloud)
{
this.Cloud=Cloud;
}
public String getRain()
{
return Rain;
}
public String getSun()
{
return Sun;
}
public String getCloud()
{
return Cloud;
}
public String getRandom()
{
int rand;
int num;
String outcome=" ";
//random generator
Random t= new Random();
for(rand=1; rand<=3;rand++)
{
num=t.nextInt(3)+1;
//random allocator
for(int x=0;x<3;x++)
{
if(num==x)
outcome=Rain+" ";
if(num==x)
outcome=Sun+" ";
if(num==x)
outcome=Cloud+" ";
}
}
return outcome;
}
}
}
public class Weather extends WeatherPredicMain
{
//public static void main(String [] args)
{
WeatherPredicMain outcome = new WeatherPredicMain();
outcome.setRain("Rain");
outcome.setSun("Sun");
outcome.setCloud("Cloud");
System.out.println(outcome.getRain());
System.out.println(outcome.getSun());
System.out.println(outcome.getRandom());
}