From 9f9f4122d189bf5ae6225985837a721692b7ce17 Mon Sep 17 00:00:00 2001 From: allawa30 <48866165+allawa30@users.noreply.github.com> Date: Thu, 18 Apr 2019 19:39:02 +0800 Subject: [PATCH] LAB1,LAB2, LAB3 U16/FNS/CSC/2061 --- labTwo_addressBreak.java | 29 +++++++++++++++++++++++++++++ labTwo_emailBreak.java | 30 ++++++++++++++++++++++++++++++ labTwo_mathFunction.java | 21 +++++++++++++++++++++ labTwo_one.java | 25 +++++++++++++++++++++++++ patternDisplay.java | 14 ++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 labTwo_addressBreak.java create mode 100644 labTwo_emailBreak.java create mode 100644 labTwo_mathFunction.java create mode 100644 labTwo_one.java create mode 100644 patternDisplay.java diff --git a/labTwo_addressBreak.java b/labTwo_addressBreak.java new file mode 100644 index 0000000..208cbd9 --- /dev/null +++ b/labTwo_addressBreak.java @@ -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); + } +} diff --git a/labTwo_emailBreak.java b/labTwo_emailBreak.java new file mode 100644 index 0000000..964625f --- /dev/null +++ b/labTwo_emailBreak.java @@ -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]); + } +} + diff --git a/labTwo_mathFunction.java b/labTwo_mathFunction.java new file mode 100644 index 0000000..a48261e --- /dev/null +++ b/labTwo_mathFunction.java @@ -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); + } + +} diff --git a/labTwo_one.java b/labTwo_one.java new file mode 100644 index 0000000..1fa0291 --- /dev/null +++ b/labTwo_one.java @@ -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); + } + +} diff --git a/patternDisplay.java b/patternDisplay.java new file mode 100644 index 0000000..3f2d960 --- /dev/null +++ b/patternDisplay.java @@ -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" + } + +}