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
29 changes: 29 additions & 0 deletions labTwo_addressBreak.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package practicalClass;

import java.util.Scanner;
//program to break file address into file path, file name and its extension
//U16/FNS/CSC/2061
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);
}
}
30 changes: 30 additions & 0 deletions labTwo_emailBreak.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package practicalClass;

import java.util.Scanner;
//Program to break inputed email into username and domain name
//U16/FNS/CSC/2061
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]);
}
}

21 changes: 21 additions & 0 deletions labTwo_mathFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package practicalClass;

//program to carry out sin,cos,tan,abs,exp mathematical functions
//U16/FNS/CSC/2045
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);
}

}
25 changes: 25 additions & 0 deletions labTwo_one.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package practicalClass;

//program to print miles, values of X,Y,Z and also log of a value
// U16/FNS/CSC/2061
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);
}

}
14 changes: 14 additions & 0 deletions patternDisplay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package practicalClass;

//program to display a given pattern
//U16/FNS/CSC/2061
public class patternDisplay {
public static void main(String[] args) {
System.out.println("\n*\t*\n*\t*\n*\t*\n*\t*\n*\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*\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 *");
System.out.println("my name is MUAZU YAKUBU ALLAWA Matric number:U16/FNS/CSC/2061"
}

}