Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lab 1/a.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package practicalClass;

//program to display mathematical table
public class displayTable {
public static void main(String[] args) {
int mulOne=1,mulTwo=2,mulThree=3,mulFour=4;
System.out.println("\t"+mulOne+"\t"+mulTwo+"\t"+mulThree+"\t"+mulFour);
for(int i=1;i<5;i++) {
System.out.println(mulOne*i+"\t"+mulOne*i+"\t"+mulTwo*i+"\t"+mulThree*i+"\t"+mulFour*i);
}
}
}
28 changes: 28 additions & 0 deletions Lab 1/b.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package practicalClass;

import java.util.Scanner;
//program to break file address into file path, file name and its extension
public class labTwo_addressBreak {
public static void main(String[] args) {
Scanner file=new Scanner(System.in);
String path;
boolean check=false;
do {
System.out.println("Please enter File path: ");
path=file.nextLine();
if (path.contains("\\") && path.contains(".")) {
int index=path.lastIndexOf("\\");
int ext=path.lastIndexOf(".");
String fileName=path.substring(index+1, ext);
String filePath=path.substring(0, index);
String fileExt=path.substring(ext+1);
System.out.println("\nFor the full name: "+path);
System.out.println("Directory: "+filePath+" \nFile name: "+fileName+" \nExtension: "+fileExt);
check=true;
}
else {
System.out.println("Invalid Path ");
}
}while(!check);
}
}
29 changes: 29 additions & 0 deletions Lab 1/c.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package practicalClass;

import java.util.Scanner;
//Program to break inputed email into username and domain name
public class labTwo_emailBreak {
public static void main(String[] args) {
Scanner userInput=new Scanner(System.in);
String testString,emailAddress;
boolean check;
do {
System.out.println("Please enter your email e.g: example@mail.com");
emailAddress=userInput.nextLine();
//String email_regex="[A-Z]+[a-zA-Z_]+@\b([a-zA-Z]+.) {2}\b?.[a-zA-Z]+";
String email_regex="^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"+"[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
testString=emailAddress;
check=testString.matches(email_regex);
if(!check) {
System.out.println("The email : \""+emailAddress+ "\" is Invalid\n");
//return;
}

}while(!check);

String[] parts= emailAddress.split("@");
System.out.println("\nFor the email address: "+emailAddress);
System.out.println("The user name is : "+parts[0]+"\nThe domain name is : "+parts[1]);
}
}

20 changes: 20 additions & 0 deletions Lab 1/d.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package practicalClass;

//program to carry out sin,cos,tan,abs,exp mathematical functions
public class labTwo_mathFunction {
public static void main(String[] args) {
double k;
k=2/4*4%3;
//converting from degrees to radian
double cos=Math.cos(Math.toRadians(30));
double sin=Math.sin(Math.toRadians(30));
double tan=Math.tan(Math.toRadians(30));
//********* output ***********
System.out.println("The value of cos 30: "+cos);
System.out.println("The value of exp(15): "+Math.exp(15));
System.out.println("The value of sin 30: "+sin);
System.out.println("The absolute value of k is "+Math.abs(k));
System.out.println("The value of tan 30: "+tan);
}

}
24 changes: 24 additions & 0 deletions Lab 1/e.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package practicalClass;

//program to print miles, values of X,Y,Z and also log of a value
public class labTwo_one {
public static void main(String[] args) {
//Lab2 question 1(a)
double miles=10.5;
miles++;
System.out.println("The current value of miles is now: "+miles);
//Lab2 question 1(b)
double X,Y,Z,d=1.0;
int a=1;
X=d+ 43 % 5*(23*3%2);
Y=1.5 *3 +(++a);
Z=3 +(d*d)+4;
System.out.println("\n\nX ="+X+"\nY ="+Y+"\nZ ="+Z);

//Lab2 question 1(c)
double R,p=3.758;
R=Math.log(p); //R=log(3.758)
System.out.println("\n\nR=log(p) \nR ="+R);
}

}
11 changes: 11 additions & 0 deletions Lab 1/f.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package practicalClass;

//program to display a given pattern
public class patternDisplay {
public static void main(String[] args) {
System.out.println("\t*\n\n *\t *\n\n*\t*\t*\n\n*\t\t*");
System.out.println("\n\n\n*\t*\n\n*\t*\t*\n\n*\t*\n\n*\t*\t*\n\n*\t*");
System.out.println("\n\n\n*\t\t*\n\n*\t\t*\n\n*\t\t*\n\n*\t\t*\n\n * \t *");
}

}
64 changes: 64 additions & 0 deletions Lab3/Lab3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

/**
* Write a description of class Lab3 here.
*
* @author (MUSA ABUSUFYAN YUSUF)
* @U15/FNS/CSC/003
*/
import java.util.Scanner;
public class Lab3
{
public static void main(String[]arg){
System.out.println("\nEXERCISES 01 Volume&Surface-area");
Scanner scann = new Scanner(System.in);
System.out.println("Enter the length:");
double l = scann.nextDouble();
System.out.println("Enter the width:");
double w = scann.nextDouble();
System.out.println("Enter the heigth:");
double h = scann.nextDouble();
double volume = (h*w*l);
double surface = 2*(l*w+l*h+w*h);
System.out.println("The volume of the box: "+volume);
System.out.println("The surface area of the box: "+surface);
System.out.println("\nEXERCISES 02 USERNAME&DOMAIN");
Scanner scan = new Scanner(System.in);
String domain,username;
System.out.println("Please enter a valid email address");
String email = scan.nextLine();
username = email.split("@")[0];
domain = email.substring(email.indexOf("@")+1);
//username = email.substring(email.indexOf("@")-1);
System.out.println("\nUsername:"+ username);
System.out.println("Domain:"+ domain);

System.out.println("\nEXERCISES 03 Perimeter&Area");
Scanner scan1 = new Scanner(System.in);
System.out.println("Enter the 1st sides:");
int a = scan1.nextInt();
System.out.println("Enter the 2nd sides:");
int b = scan1.nextInt();
System.out.println("Enter the 3rd sides:");
int c = scan1.nextInt();
double s =(a+b+c)/2;
double area = Math.sqrt(s*(s-a)*(s-b)*(s-c));
System.out.println("The Perimeter of triangle is: "+s);
System.out.println("The area of the triangle with the input sides is "+ area+"unit square");
if(a>b && a>c){
System.out.println("The longest side is: "+a);
}else if(b>c){
System.out.println("The longest side is: "+b);
}else{
System.out.println("The longest side is: "+c);
}

if(a<b && a<c){
System.out.println("The smallest side is: "+a);
}else if(b<c){
System.out.println("The smallest side is: "+b);
}else{
System.out.println("The smallest side is: "+c);
}

}
}
39 changes: 39 additions & 0 deletions Lab4/BankAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Write a description of BankAccount here.
*
* @author (MUSA ABUSUFYAN YUSUF)
* @U15/FNS/CSC/003
*/
public class BankAccount
{
// instance variables - replace the example below with your own
private int accountNumber;
private String customerName;
private double balance;

/**
* Constructor for objects of class BankAccount
*/
public BankAccount(int acctNumber, String custName, double bal)
{
accountNumber=acctNumber;
customerName=custName;
balance=bal;
}

//method deposit
public void deposit(double deposit)
{
balance+=deposit;
}
//method withdraw
public double withdraw(double withdraw)
{
balance-=withdraw;
return balance;
}
public double getBalance()
{
return balance;
}
}
37 changes: 37 additions & 0 deletions Lab4/BankAccountDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Write a description of class BankAccountDemo here.
*
* @author (MUSA ABUSUFYAN YUSUF)
* @U15/FNS/CSC/003
*/
import java.util.Scanner;
public class BankAccountDemo
{
public static void main(String[] args){
Scanner bank= new Scanner(System.in);
int accountNumber;
double balance,withdraw,deposit;
String accountName;

System.out.print("\nEnter Account Number: ");
accountNumber=bank.nextInt();
bank.nextLine();
System.out.print("Enter Customer name: ");
accountName=bank.nextLine();
System.out.print("Enter initial balance: ");
balance=bank.nextDouble();
bank.nextLine();
BankAccount account= new BankAccount(accountNumber,accountName,balance);
// BankAccount account= new BankAccount(accountNumber,accountName,balance);


System.out.print("\nEnter amount to deposit: ");
deposit=bank.nextDouble();
account.deposit(deposit);
System.out.print("New balance is: "+account.getBalance());
System.out.print("\n\nEnter amount to withdraw: ");
withdraw=bank.nextDouble();
account.withdraw(withdraw);
System.out.print("New balance is: "+account.getBalance());
}
}
20 changes: 20 additions & 0 deletions Lab4/Box.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Write a description of class Box here.
*
* @author (MUSA BUSUFYAN YUSUF)
* @U15/FNS/CSC/003
*/
public class Box {
private double length , width , height; //instance variables
public Box(double boxLength , double boxWidth , double boxHeight) { //constructor
length = boxLength;
width = boxWidth;
height = boxHeight;
}
public double volume() { //instant methods
return length * width * height;
}
public double surfaceArea() {
return 2*(length*width + length*height + width*height);
}
}
22 changes: 22 additions & 0 deletions Lab4/BoxDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Write a description of class BoxDemo here.
*
* @author (MUSA ABUSUFYAN YUSUF)
* @U15/FNS/CSC/003
*/
public class BoxDemo {
public static void main(String[] args) {
// Create two Box objects
Box box1 = new Box(20.0, 10.0, 15.0);
Box box2 = new Box(6.0, 4.0, 2.0);
double volume, area;
// Get and display volume and surface area of box1
volume = box1.volume();
area = box1.surfaceArea();
System.out.println("The volume of box1 is " + volume + " cubic cm");
System.out.println("The surface area of box1 is "+area+" square cm\n");
// Get and display volume of surface area box2
System.out.println("The volume of box2 is " + box2.volume() + " cubic cm");
System.out.println("The surface area of box2 is "+area+" square cm\n");
}
}
25 changes: 25 additions & 0 deletions Lab4/Circle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

/**
* Write a description of class Circle here.
*
* @author (MUSA ABUSUFYAN YUSUF)
* @U15/FNS/CSC/003
*/
public class Circle
{
private static int numberOfCircles = 0;
private double radius;
public Circle(double circleRadius) {
numberOfCircles++;
radius = circleRadius;
}
public double area() {
return Math.PI * radius * radius;
}
public double circumference() {
return 2.0 * Math.PI * radius;
}
public static int getNumberOfCircles() {
return numberOfCircles;
}
}
20 changes: 20 additions & 0 deletions Lab4/CircleDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

/**
* Write a description of class CircleDemo here.
*
* @author (MUSA ABUSUFYAN YUSUF)
* @U15/FNS/CSC/003
*/
public class CircleDemo {
public static void main(String[] args) {
System.out.println("The number of circles is " + Circle.getNumberOfCircles());
Circle circle1 = new Circle(8.5);
System.out.println("The number of circles is " + Circle.getNumberOfCircles());
Circle circle2 = new Circle(5.0);
System.out.println("The number of circles is " + Circle.getNumberOfCircles());
System.out.println("The area of the first circle is \t" + circle1.area() + "square cm");
System.out.println("The circumference of the first circle is\t" +circle1.circumference() + " cm");
System.out.println("The area of the second circle is\t" + circle2.area() + "square cm");
System.out.println("The circumference of the second circle is\t" +circle2.circumference() + " cm\n\n");
}
}
31 changes: 31 additions & 0 deletions Lab4/Rectangle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

/**
* Write a description of class Rectangle here.
*
* @author (MUSA ABUSUFYAN YUSUF)
* @U15/FNS/CSC/003
*/
class Rectangle {
private double length , width;
public Rectangle(double rectangleLength , double rectangleWidth) {
length = rectangleLength;
width = rectangleWidth;
}
public double area() {
return length * width;
}
// Accessor methods
public double getLength() {
return length;
}
public double getWidth() {
return width;
}
// Mutator methods
public void setLength(double newLength) {
length = newLength;
}
public void setRectangleWidth(float newWidth) {
width = newWidth;
}
}
Loading