Question

In: Computer Science

write down the java code for garden sprinkler system.

write down the java code for garden sprinkler system.

Solutions

Expert Solution

package Base;

import java.util.Calendar;

import java.util.GregorianCalendar;

/**

*

* @author VINAY SAGAR GONABAVI and SHIVAM VARMA

*

*/

public class Sprinkler extends Group {

public String status = "OFF";

public String functional = "OK";

String name;

String groupId;

int duration, rate, day, hr, min;

int waterUsage=0;

GregorianCalendar gC = new GregorianCalendar();

int h=gC.get(Calendar.HOUR_OF_DAY);

int m=gC.get(Calendar.MINUTE);

int d=gC.get(Calendar.DAY_OF_WEEK);

public Sprinkler(String groupId, String name, int day, int hr, int min, int duration, int rate){

  

//super(groupId);

//this.nameString=name;

//this.groupId=id;

this.name = name;

this.groupId = groupId;

this.duration = duration;

this.rate = rate;

this.day = day;

this.hr = hr;

this.min = min;

  

}

/**

* @param null

*/

public void setStatus(){

status=name+" is on";

}

/**

* @param null

*/

@Override

public void setSprinklerOn(){

status = "ON";

}

/**

* @param null

*/

public void setSprinklerOff(){

status = "OFF";

}

/**

* @param null

*/

public String getStatus(){

return this.status;

}

/**

* @param null

*/

public void showStatus(){

System.out.println(name +" is " +status);

}

/**

* @param null

*/

public int getWaterUsage(){

  

if(d>day){

waterUsage = waterUsage + duration*rate;

}

  

  

  

  

if(d==day){

if(h>hr){

waterUsage = waterUsage + duration*rate;

}

if(h<=hr){

if(getStatus() == "ON"){  

if(min+duration<60){

if(h==hr && m>=min && m<=(min+duration)){

int x=m-min;

waterUsage = waterUsage + x*rate;

}

}

  

if(min+duration>60){

if(h==hr){

if(m>=min){

int x=m-min;

waterUsage = waterUsage + x*rate;

  

}

}

if(h==(hr+1)){

if(m<=(min+duration-60)){

int x=m-min+60;

waterUsage = waterUsage + x*rate;

}

}

}

}

else{

if(min+duration<60){

if(h==hr && m>=min && m<=(min+duration)){

//int x=m-min;

waterUsage = waterUsage + duration*rate;

}

}

  

if(min+duration>60){

if(h==hr){

if(m>=min){

//int x=m-min;

waterUsage = waterUsage + duration*rate;

  

}

}

if(h==(hr+1)){

if(m<=(min+duration-60)){

//int x=m-min+60;

waterUsage = waterUsage + duration*rate;

}

}

}

}

}

  

}

  

return waterUsage;

}

/**

* @param null

*/

public void showWaterUsage(){

System.out.println("Water usage by "+name+" is "+waterUsage);

}

/**

* @param null

*/

public void setSprinklerFunctional(){

this.functional="OK";

  

}

/**

* @param null

*/

public void setSprinklerDisFunctional(){

this.functional="NOT";

}

/**

* @param null

*/

public void showSprinklerFunctional(){

System.out.println(name +" is " +functional);

}

/**

* @param null

*/

public String getFunctional(){

return this.status;

}

}


Related Solutions

Green Manufacturing is considering to invest a sprinkler system which costs $150,000. The sprinkler system is...
Green Manufacturing is considering to invest a sprinkler system which costs $150,000. The sprinkler system is assumed to last 5 years. (Note: it should last longer. The reason for the assumption is for calculation simplicity.) The net cash flows associated with the sprinkler system (e.g., loss reduction, premium savings, and costs of upkeep) is $50,000 per year for 5 years.    The tax rate is 20% and opportunity cost is 10%. Show the cash flows associated with the new sprinkler system...
Write down the VERILOG code for an XOR gate and the testbench code to test it
Write down the VERILOG code for an XOR gate and the testbench code to test it
Write down your own verbal description for a dynamical system, and write down the equations for...
Write down your own verbal description for a dynamical system, and write down the equations for the dynamical system. (It is fine if this system is very simple! It is also fine if the scenario is not very realistic, as long as the equations match the description!)   
Sprinkler Corporation produces plastic garden sprinklers. The company is preparing its budget for 2015. The first...
Sprinkler Corporation produces plastic garden sprinklers. The company is preparing its budget for 2015. The first step is to plan for the first quarter of that coming year. Sprinkler has collected the following information from the managers. Sales: Sales for November 2014                              112,500 units Sales for December 2014                               102,100 units Expected sales for January 2015                   113,000 units Expected sales for February 2015                 112,500 units Expected sales for March 2015                     116,000 units Expected sales for April 2015                        125,000 units Expected sales for May 2015                         137,500 units Selling price...
Sprinkler Corporation produces plastic garden sprinklers. The company is preparing its budget for 2015. The first...
Sprinkler Corporation produces plastic garden sprinklers. The company is preparing its budget for 2015. The first step is to plan for the first quarter of that coming year. Sprinkler has collected the following information from the managers. Sales: Sales for November 2014                                     112,500 units Sales for December 2014                                     102,100 units Expected sales for January 2015                       113,000 units Expected sales for February 2015                     112,500 units Expected sales for March 2015                          116,000 units Expected sales for April 2015                             125,000 units Expected sales...
arduino c code only write a code that counts down a timer on serial monitor and...
arduino c code only write a code that counts down a timer on serial monitor and if A1 is typed into serial monitor prints the timer counting down and writes at 1 second hello and at 5 secs goodbye and repeats every 5 secs A2 is typed as above at 2 seconds writes hello and 3 seconds writes goodbye A3 same as above but at 3 seconds says hello and 2 seconds goodbye This continues until c is pressed to...
Analyze the following Verilog code and write down its output as pictured in the code. module...
Analyze the following Verilog code and write down its output as pictured in the code. module blocking; reg [0:7] A, B; initial begin: init1 A = last decimal digit of your ID; #1 A = A + 1; // blocking procedural assignment B = A + 1; $display("Output 1: A= %b B= %b", A, B ); A = last decimal digit of your ID; #1 A <= A + 1; B <= A + 1; #1 $display ("Output 2: A=...
You are tasked to code a software prototype of this feature in Java. The system will...
You are tasked to code a software prototype of this feature in Java. The system will be provided the course code, course name, CRN, the total number of students, course credit hours.   The system should calculate and display the following statistics: Total student credit hours, which is the total number of students times course credit hours. FTE for the course, which is the total student credit hours divided by 40. Total amount of tuition generated in USD from the course....
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text...
URGENT!! DO THIS CODE IN JAVA Write a complete Java FX program that displays a text label and a button.When the program begins, the label displays a 0. Then each time the button is clicked, the number increases its value by 1; that is each time the user clicks the button the label displays 1,2,3,4............and so on.
Java Problem: Please answer both parts of the question fully: (a). Write Java code for a...
Java Problem: Please answer both parts of the question fully: (a). Write Java code for a method to test if a LinkedList<Long> has Long values that form a Fibonacci sequence from the beginning to the end and return true if it is and false otherwise. A sequence of values is Fibonnaci if every third value is equal to sum of the previous two. Eg., 3,4,7,11,18,29 is a Fibonacci sequence whereas 1,2,3,4 is not, because 2+3 is not equal to 4....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT