1 / 2100%
public class Geek
{
//instance variables
private String name;
private static int numQuestions;
//Constructor
public Geek(String name, int numQuestions)
{
name = name;
numQuestions = numQuestions;
}
//Method to return geek name
public String getName()
{
return name;
}
//method to get number of questions asked
public int getNumberOfQuestions()
{
return numQuestions;
}
//method to determine if numbers sum is even or odd
public boolean isEven(int num1, int num2)
{
numQuestions++;
boolean even;
if ((num1 + num2)%2 == 0)
even = true;
else
even = false;
return even;
}
//method to return sum
public int sum(int num1, int num2)
{
numQuestions++;
if (num1 == num2)
{
return num2;
}
int total = 0;
while (num1 <= num2)
{
total += num1;
num1++;
}
return total;
}
//method to determine if year is leap year
public boolean leapYear(int year)
//**************************************************
//Filename: Geek.java
//Specifications:
//For:CSE 110- Assignment 5
//Time Spent: 2 hours
//**************************************************
{
numQuestions++;
if ((year % 4 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
{
return true;
}
else
{
return false;
}
}
}
Powered by TCPDF (www.tcpdf.org)
Students also viewed