Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
import java.util.Random;
class WeatherReport {
private int temperature;
private int windSpeed;
private String windDirection;
private static int weatherReportStationNumber = 0;
public WeatherReport(int temperature, int windSpeed, String windDirection){
this.temperature = temperature;
this.windSpeed = windSpeed;
this.windDirection = windDirection;
}
public void setTemperature(int temperature)
{
this.temperature = temperature;
}
public int getTemperature()
{
return temperature;
}
public void setWindSpeed(int windSpeed){
this.windSpeed = windSpeed;
}
public int getWindSpeed(){
return windSpeed;
}
public void setWindDirection()
{
Random x = new Random();
int check = x.nextInt(4);
switch(check){
case 0:
this.windDirection = "NORTH";
break;
case 1:
this.windDirection = "EAST";
break;
case 2:
this.windDirection = "WEST";
break;
case 3:
this.windDirection = "SOUTH";
break;
}
}
public String getWindDirection()
{
return windDirection;
}
public String methodOne(int temperature, int windSpeed, String windDirection){
String dressCode = "";
int product = temperature + windSpeed;
if(windDirection == "NORTH" && temperature <= -20){
if(temperature< -20){
dressCode = "stay inside";
}
}
else {
if(product<=0)
dressCode = "winter coat";
else if(product<=15)
dressCode = "light coat";
else if(product>15)
dressCode = "shorts";
}
return dressCode;
}
public static void randomWeatherReportStationVariable(){
Random x = new Random();
int assignment = x.nextInt(51) + 100;
weatherReportStationNumber = assignment;
System.out.println(assignment);
}
public String methodTwo(String name)
{
String interleavedString = "";
if(name.length() == windDirection.length())
{
for(int x = 0; x<name.length();x++){
interleavedString += name.charAt(x);
interleavedString += windDirection.charAt(x);
}
}
else{
interleavedString = "ERROR";
}
return interleavedString;
}
public int methodThree(int factor){
int windFactor = 0;
windFactor = windSpeed/factor;
return windFactor;
}
}
public class WeatherReportTestHarness{
public static void main(String []args){
WeatherReport[][] testArray = new WeatherReport[7][3];
//randomWeatherReportStationVariable();
int z = 0;
for(int x = 0;x<3;x++){
for(int i = 0;i<7;i++){
z += 2;
testArray[i][x] = new WeatherReport((-24 + z), (0 + z), "");
testArray[i][x].setWindDirection();
}
}
for(int x = 0;x<3;x++){
for(int i = 0;i<7;i++){
System.out.println("Temperature at index " + i + x + " is " + testArray[i][x].getTemperature());
System.out.println("----------------------------------");
System.out.println("Wind Speed at index " + i + x + " is " + testArray[i][x].getWindSpeed());
System.out.println("----------------------------------");
System.out.println("Wind Direction at index " + i + x + " is " + testArray[i][x].getWindDirection());
System.out.println("----------------------------------");
System.out.println("Dress Code at index " + i + x + " is " + testArray[i][x].methodOne(testArray[i][x].getTemperature(), testArray[i][x].getWindSpeed(), testArray[i][x].getWindDirection()));
//System.out.println("----------------------------------");
//System.out.println("The Weather Report Station Number is " + weatherReportStationNumber);
System.out.println("----------------------------------");
System.out.println(testArray[i][x].methodTwo("HELLO"));
System.out.println("----------------------------------");
if(testArray[i][x].getWindDirection().contains("TH") == true){
System.out.println("index " + i + x + "contains th");
System.out.println("Temperature at index " + i + x + " is " + testArray[i][x].getTemperature());
System.out.println("----------------------------------");
System.out.println("Wind Speed at index " + i + x + " is " + testArray[i][x].getWindSpeed());
System.out.println("----------------------------------");
System.out.println("Wind Direction at index " + i + x + " is " + testArray[i][x].getWindDirection());
System.out.println("----------------------------------");
}
}
}
}
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more