Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

WANJAU MARTIN GITHINJI.

C027-01-1382/2019.

BBIT.

A.) Middleware is a software that lies between an operating system and the applications running on
it. It enables communication and data management for distributed applications.
B.) Public class Rectangle{
Private double length;
Private double width;

Public Rectangle(){
setLength(1.0);
setWidth(1.0);
}
Public Rectangle(double theLength, double theWidth ){
setLength(theLength);
setWidth(theWidth);
}
Public void setLength(double theLength){
length=(theLength>0.0&&thelength<20?theLength:1.0);
}
Public void setWidth(double thewidth){
length=(theWidth0.0&&theWidth<20?theWidth:1.0);
}
public double getLength(){
return length;
}
public double getWidth(){
return width;
}
Public double perimeter(){
Return 2*length+2*width;
}
public double area(){
return width*length;
}
public String toString(){
return String.format(“%s:%f\n%s: %f\n%s: %f\n%s:%f”,”length”,
”length”,”width”,”width”,”Perimeter”,perimeter(),”Area”,area());
}
}
C.) package ExceptionHandling{
import java.util.scanner;
class DivideByZeroExeptionHandling{
public static void main(string[]arg){
try{
int a,b,c;
Scanner scan= new Scanner (System.in);
System.out.println(“enter first number:”)
a=scan.nextInt();
System.out.println(“enter second number:”)
b=scan.nextInt();
c=a/b;
System.out.println(“result”+c);
}
catch(ArithmeticException e){
System.out.println(“error:”+e.getMessage());
System.out.println(“error:’+e);
}
System.out.println(“program completed”)
}
}
D.) import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class CreateFile{
public static void main(string[]args){
file file = new file(“C:\\Desktop\input.txt”);
if(result){
System.out.println(“file created”+file.getCanonicalPath());
}
else{
System.out.println(“file already exists at location”+file.getCanonicalPath());
}
}
catch(IOException e){
e.printStackTrace();
}
}
public class FileWriter{
public static void main (string[]args){
try{
FileWriter fw = new FileWriter(“c:\\Desktop\testout.txt”);
fw.write(“martin githinji wanjau”);
fw.close();
}
Catch(Exception e){System.out.println(e);
}
}
}

You might also like