Bit 2204a Bbit 310 Bac 2201 BSD 2107 Bisf 2201 Java Programming Rayfrankmuriithi
Bit 2204a Bbit 310 Bac 2201 BSD 2107 Bisf 2201 Java Programming Rayfrankmuriithi
KIBAARA
REGISTRATION NUMBER: 20/03618
MODE OF STUDY: DAY
CAMPUS: MAIN CAMPUS
UNIVERSITY EXAMINATIONS: 2020/2021
EXAMINATION FOR DEGREE IN BACHELOR OF SCIENCE IN
INFORMATION TECHNOLOGY/ BUSINESS I.T/APPLIED
COMPUTING/ SOFTWARE DEV./INFO. SECURITY& FORENSICS
BIT 2204A/ BBIT 310 /BAC 2201/ BSD 2107/BISF 2201:
JAVA PROGRAMMING
PART TIME/FULL TIME/DISTANCE LEARNING
ORDINARY EXAMINATIONS
DATE: AUGUST, 2021 TIME: 3 HOURS
class Num4
{
private double db1;
private long lg;
public Num4 ()
{
db1 = 108.0d;
lg = 249;
}
public Num4(double d, long l)
{
db1 = d;
lg = 1;
}
public boolean isZero()
{
if (db1 == 0.0)
return true;
else
return false;
}
public boolean isPositive()
{
if (db1 > 0.0)
return true;
else
return false;
}
public boolean isNegative()
{
if (db1 < 0.0)
return true;
else
return false;
}
public boolean isodd()
{
if (db1 % 2 != 0.0)
return true;
else return false;
}
public boolean isEven()
{
if (db1 % 2 == 0.0)
return true;
else return false;
}
public boolean isPrime()
{
int i, lastn;
double a;
boolean flag;
a = Math.sqrt(lg);
lastn = (int)a;
flag = true;
for (i = 2; i < lastn; i++)
{
if (lg != i)
{
if (lg % i == 0)
{
flag = false;
break;
}
}
}
if (flag)
return true;
else return false;
}
public boolean isAmstrong()
{
if (db1 == 0.0)
return true;
else return false;
}
public double getFactorial()
{
double d = 1;
for (int i = 1; i < lg; i++)
d *= i;
return d;
}
public double getSqrt()
{
double d;
d = (double)lg;
d = Math.sqrt(d);
return d;
}
public double getSqr()
{
double d;
d = (double)lg;
d = d * d;
return d;
}
public double sumDigits()
{
double d = 0;
while (lg > 9)
{
d += lg % 10;
lg = lg / 10;
}
d += lg;
return d;
}
public double getReverse()
{
double d = 0;
double temp;
while (lg > 9)
{
temp = lg % 10;
d = d * 10 + temp;
lg = lg / 10;
System.out.println("\n" + temp + "\t" + d + " \t " + lg);
}
d = d * 10 + lg;
System.out.println("Inside class" + d);
return d;
}
public void dispBinary()
{
System.out.println("ByteValue of lg :" + Long.toBinaryString(lg));
}
public static void main(String args [ ])
{
Num4 mynum = new Num4();
double d = 199;
System.out.println(" The given numbers are 108.0d and 249");
System.out.println("isZero " + mynum.isZero());
System.out.println("isPositive " + mynum.isPositive());
System.out.println("isNegative " + mynum.isNegative());
System.out.println("isOdd " + mynum.isodd());
System.out.println("isEven " + mynum.isEven());
System.out.println(" isPrime " + mynum.isPrime());
System.out.println("getFactorial " + mynum.getFactorial());
System.out.println("getSqrt " + mynum.getSqrt());
System.out.println("getSqr " + mynum.getSqr());
System.out.println("sumDigits " + mynum.sumDigits());
System.out.println("getReverse " + mynum.getReverse());
mynum.dispBinary();
System.out.println(" isPrime " + mynum.isPrime());
}
}
(8 Marks)
import java.util.*;
class Student
int RegNo,Total=0,subjects;
String name;
int marks[];
Student()
RegNo=sc.nextInt();
name=sc.next();;
getDisMarks();
}
public void getDisMarks()
marks=new int[3];
marks[0]=sc.nextInt();
marks[1]=sc.nextInt();
marks[2]=sc.nextInt();
for(int i=0;i<3;i++)
Total+=marks[i];
class StudentDemo
for(int i=0;i<5;i++)
s[i]=new Student();
}
}
Required:
a). Develop a class diagram for this case
Reference: https://www.researchgate.net/figure/Class-diagram-for-a-management-
employee-system_fig1_320246921
b). Write a java program to implement the design above. (7 Marks)
public class Employee {
super();
this.firstName = firstName;
this.lastName = lastName;
if(monthlySalary <= 0)
{
this.monthlySalary = 0.0;
else
this.monthlySalary = monthlySalary;
}
import java.util.Scanner;
scanner.nextLine();
System.out.println(Math.round(employee2.getMonthlySalary()*12*100)/100.00);
System.out.println(Math.round(employee1.getMonthlySalary()*12*100)/100.00);
scanner.close();