Write a class named Averager containing: An instance variable named sum of type integer , initialized to 0. An instance variable named count of type integer , initialized to 0.

java

LANGUAGE: JAVA CHALLENGE: Write a class named Averager containing: An instance variable named sum of type integer , initialized to 0. An instance variable named count of type integer , initialized to 0. A method named getSum that returns the value of sum . A method named add that accepts an integer parameter . The value…

Read More

Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006. Given a variable modelYear write a statement that prints the message “RECALL” to standard output if the value of modelYear falls within those two ranges.

java

LANGUAGE: JAVA CHALLENGE: Clunker Motors Inc. is recalling all vehicles from model years 1995-1998 and 2004-2006. Given a variable modelYear write a statement that prints the message “RECALL” to standard output if the value of modelYear falls within those two ranges.

Read More

Given a int variable named callsReceived and another int variable named operatorsOnCall write the necessary code to read values into callsReceived and operatorsOnCall and print out the number of calls received per operator (integer division with truncation will do).

java

LANGUAGE: JAVA CHALLENGE: NOTE: in mathematics, division by zero is undefined. So, in Java, division by zero is always an error. Given a int variable named callsReceived and another int variable named operatorsOnCall write the necessary code to read values into callsReceived and operatorsOnCall and print out the number of calls received per operator (integer…

Read More

Assume that a boolean variable workedOvertime has been declared , and that another variable , hoursWorked has been declared and initialized . Write a statement that assigns the value true to workedOvertime if hoursWorked is greater than 40 and false otherwise.

java

LANGUAGE: JAVA CHALLENGE: Assume that a boolean variable workedOvertime has been declared , and that another variable , hoursWorked has been declared and initialized . Write a statement that assigns the value true to workedOvertime if hoursWorked is greater than 40 and false otherwise.

Read More

Assume that a boolean variable isQuadrilateral has been declared , and that another variable , numberOfSides has been declared and initialized . Write a statement that assigns the value true if numberOfSides is exactly 4 and false otherwise.

java

LANGUAGE: JAVA CHALLENGE: Assume that a boolean variable isQuadrilateral has been declared , and that another variable , numberOfSides has been declared and initialized . Write a statement that assigns the value true if numberOfSides is exactly 4 and false otherwise.

Read More

Write the definition of a class Clock. The class has three instance variables : One of type int called hours, another of type boolean called isTicking, and the last one of type Integer called diff. You should also write a constructor that takes three parameters — an int , a boolean , and another int . The constructor should set the instance variables to the values provided.

java

LANGUAGE: JAVA CHALLENGE: Write the definition of a class Clock. The class has three instance variables : One of type int called hours, another of type boolean called isTicking, and the last one of type Integer called diff. You should also write a constructor that takes three parameters — an int , a boolean ,…

Read More

Write a loop that reads positive integers from standard input, printing out those values that are greater than 100, each followed by a space, and that terminates when it reads an integer that is not positive. Declare any variables that are needed.

java

LANGUAGE: JAVA CHALLENGE: Write a loop that reads positive integers from standard input, printing out those values that are greater than 100, each followed by a space, and that terminates when it reads an integer that is not positive. Declare any variables that are needed. ASSUME the availability of a variable , stdin, that references…

Read More

Write a loop that reads positive integers from standard input, printing out those values that are even, each followed by a space, and that terminates when it reads an integer that is not positive. Declare any variables that are needed.

java

LANGUAGE: JAVA CHALLENGE: Write a loop that reads positive integers from standard input, printing out those values that are even, each followed by a space, and that terminates when it reads an integer that is not positive. Declare any variables that are needed. ASSUME the availability of a variable , stdin, that references a Scanner…

Read More