i am trying to develop java class for the following UML class i am trying to dev
ID: 3811667 • Letter: I
Question
i am trying to develop java class for the following UML class
i am trying to develop java class for the following UML class
Out Door Lights
dayTimeSaving: int
standardTimeSaving: int
on: boolean
__________________________________________________________________
+OutDoorLights()
+timeOn() : void
+timeOff() : void
+setDayTimeSaving(newDayTimeSaving: int) : void
+setStandardTimeSaving(newStandardTimeSaving: int) : void
+dayTimeSavingOn(): void
+dayTimeSavingOff(): void
+standardTimeSavingOn(): void
+standardTimeSavingOff(): void
this is what i did
public class OutDoorLights {
public static void main(String[] args) {
// Declare int
int dayTimeSaving = 2030; // military time = 8:30pm
int standardTimeSaving = 1730; // military time = 5:30pm
int hour = 24;
boolean on = false; // OutDoorLights off
int x = (int)(Math.random() * 24); // code to create time
}
public int newStandardTimeSaving;
public OutDoorLights(){ // OutDoorLights constructor object of the class
}
public void turnOn() { // turn on OutDoorLights
boolean on = true;
}
public void turnOff(){ //turn off OutDoorLights
boolean on = false;
}
public void setDaytimeSaving(int dayTimeSaving) { // set daytime saving
boolean on = false;
int newDayTimeSaving = 0;
if ( on && dayTimeSaving >=2030 && dayTimeSaving <= 24)
// create object of the dayTimeSaving class
dayTimeSaving = newDayTimeSaving;
}
public void setStandardtimeSaving(int standardTimeSaving) { // set daytime saving
boolean on = false;
int x = (int)(Math.random() * 24); // code to create time
if ( on && standardTimeSaving >=1730 && standardTimeSaving <= 24)
// create object of the standardTimeSaving
standardTimeSaving = newStandardTimeSaving;
Explanation / Answer
This is how the class declaration from the given UML should look like:
class OutDoorLights
{
int dayTimeSaving;
int standardTimeSaving;
boolean on;
public OutDoorLights()
{
dayTimeSaving = 0;
standardTimeSaving = 0;
on = false;
}
public void timeOn()
{
on = true;
}
public void timeOff()
{
on = false;
}
public void setDayTimeSaving(int newDayTimeSaving)
{
dayTimeSaving = newDayTimeSaving;
}
public void setStandardTimeSaving(int newStandardTimeSaving)
{
standardTimeSaving = newStandardTimeSaving;
}
public void dayTimeSavingOn()
{
//You didn't specified on what is to be done here...
}
public void dayTimeSavingOff()
{
//You didn't specified on what is to be done here...
}
public void standardTimeSavingOn()
{
//You didn't specified on what is to be done here...
}
public void standardTimeSavingOff()
{
//You didn't specified on what is to be done here...
}
}
You didn't specified on what is to be done for each method. That is why I was able to fill only the default constructor, and getter and setters. If you need further refinements, just give the description on what each method is for...