Java
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.
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 MoreGiven the integer variables x and y, write a fragment of code that assigns the larger of x and y to another integer variable max.
LANGUAGE: JAVA CHALLENGE: Given the integer variables x and y, write a fragment of code that assigns the larger of x and y to another integer variable max.
Read MoreGiven the integer variables x, y, and z, write a fragment of code that assigns the smallest of x, y, and z to another integer variable min.
LANGUAGE: JAVA CHALLENGE: Given the integer variables x, y, and z, write a fragment of code that assigns the smallest of x, y, and z to another integer variable min. Assume that all the variables have already been declared and that x, y, and z have been assigned values .
Read MoreClunker 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.
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 MoreGiven 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).
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 MoreAssume 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.
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 MoreAssume 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.
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 MoreWrite a class named ParkingMeter containing: An instance variable named timeLeft of type int , initialized to 0.
LANGUAGE: JAVA CHALLENGE: Write a class named ParkingMeter containing: An instance variable named timeLeft of type int , initialized to 0. A method named add that accepts an integer parameter . If the value of the parameter is equal to 25, the value of timeLeft is increased by 30; otherwise no increase is performed. add…
Read MoreWrite 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.
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 MoreWrite the definition of a method dashedLine, with one parameter , an int.
LANGUAGE: JAVA CHALLENGE: Write the definition of a method dashedLine, with one parameter , an int. If the parameter is negative or zero, the method does nothing. Otherwise it prints a complete line terminated by a newline to standard output consisting of dashes (hyphens) with the parameter ‘s value determining the number of dashes. The…
Read MoreWrite 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.
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 MoreWrite 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.
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