From 3c8409191c3a84fae50817849638609d8007ebcc Mon Sep 17 00:00:00 2001 From: maisule <48871145+maisule@users.noreply.github.com> Date: Thu, 18 Apr 2019 14:20:38 +0100 Subject: [PATCH] Lab1,lab2 u15/fns/csc/016 --- displayTable.java | 12 ++++++++++++ labTwo_addressBreak.java | 29 +++++++++++++++++++++++++++++ labTwo_emailBreak.java | 29 +++++++++++++++++++++++++++++ labTwo_mathFunction.java | 20 ++++++++++++++++++++ labTwo_one.java | 24 ++++++++++++++++++++++++ patternDisplay.java | 11 +++++++++++ 6 files changed, 125 insertions(+) create mode 100644 displayTable.java 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/displayTable.java b/displayTable.java new file mode 100644 index 0000000..14af825 --- /dev/null +++ b/displayTable.java @@ -0,0 +1,12 @@ +package practicalClass; +//U15/FNS/CSC/016 +//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); + } + } +} diff --git a/labTwo_addressBreak.java b/labTwo_addressBreak.java new file mode 100644 index 0000000..06c7446 --- /dev/null +++ b/labTwo_addressBreak.java @@ -0,0 +1,29 @@ +package practicalClass; + +import java.util.Scanner; +//U15/CSC/016 +//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); + } +} diff --git a/labTwo_emailBreak.java b/labTwo_emailBreak.java new file mode 100644 index 0000000..d029bb5 --- /dev/null +++ b/labTwo_emailBreak.java @@ -0,0 +1,29 @@ +package practicalClass; +//U15/FNS/CSC/016 +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]); + } +} + diff --git a/labTwo_mathFunction.java b/labTwo_mathFunction.java new file mode 100644 index 0000000..eac560f --- /dev/null +++ b/labTwo_mathFunction.java @@ -0,0 +1,20 @@ +package practicalClass; +//U15/FNS/CSC/016 +//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); + } + +} diff --git a/labTwo_one.java b/labTwo_one.java new file mode 100644 index 0000000..695cf50 --- /dev/null +++ b/labTwo_one.java @@ -0,0 +1,24 @@ +package practicalClass; +//U15/FNS/CSC/016 +//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); + } + +} diff --git a/patternDisplay.java b/patternDisplay.java new file mode 100644 index 0000000..6ee3a98 --- /dev/null +++ b/patternDisplay.java @@ -0,0 +1,11 @@ +package practicalClass; +//U15/FNS/CSC/016 +//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 *"); + } + +}