From 1cd8be4d56df42a2a26d6f52dc8c2ae574649dfc Mon Sep 17 00:00:00 2001 From: egirubu4025 Date: Thu, 25 Apr 2019 23:55:16 +0100 Subject: [PATCH 1/2] Lab1 & 2 WEB, U14/FNS/CSC/018 --- LAB1,2,3/a.java | 12 ++++++++++++ LAB1,2,3/b.java | 28 ++++++++++++++++++++++++++++ LAB1,2,3/c.java | 29 +++++++++++++++++++++++++++++ LAB1,2,3/d.java | 20 ++++++++++++++++++++ LAB1,2,3/e.java | 24 ++++++++++++++++++++++++ LAB1,2,3/f.java | 11 +++++++++++ 6 files changed, 124 insertions(+) create mode 100644 LAB1,2,3/a.java create mode 100644 LAB1,2,3/b.java create mode 100644 LAB1,2,3/c.java create mode 100644 LAB1,2,3/d.java create mode 100644 LAB1,2,3/e.java create mode 100644 LAB1,2,3/f.java diff --git a/LAB1,2,3/a.java b/LAB1,2,3/a.java new file mode 100644 index 0000000..c5bf002 --- /dev/null +++ b/LAB1,2,3/a.java @@ -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); + } + } +} diff --git a/LAB1,2,3/b.java b/LAB1,2,3/b.java new file mode 100644 index 0000000..92cc81b --- /dev/null +++ b/LAB1,2,3/b.java @@ -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); + } +} diff --git a/LAB1,2,3/c.java b/LAB1,2,3/c.java new file mode 100644 index 0000000..a2800a5 --- /dev/null +++ b/LAB1,2,3/c.java @@ -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]); + } +} + diff --git a/LAB1,2,3/d.java b/LAB1,2,3/d.java new file mode 100644 index 0000000..f62b906 --- /dev/null +++ b/LAB1,2,3/d.java @@ -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); + } + +} diff --git a/LAB1,2,3/e.java b/LAB1,2,3/e.java new file mode 100644 index 0000000..9e6b824 --- /dev/null +++ b/LAB1,2,3/e.java @@ -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); + } + +} diff --git a/LAB1,2,3/f.java b/LAB1,2,3/f.java new file mode 100644 index 0000000..c6219d2 --- /dev/null +++ b/LAB1,2,3/f.java @@ -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 *"); + } + +} From 6ee9ca9735cc66fcde1b21f209a4db340145492a Mon Sep 17 00:00:00 2001 From: egirubu4025 Date: Sun, 5 May 2019 17:48:43 +0100 Subject: [PATCH 2/2] Lab 3,4,5,6, U14/FNS/CSC/018 --- ASSIGNMENT/Lab3/Box.java | 21 ++++++ ASSIGNMENT/Lab3/BoxDemo.java | 23 ++++++ ASSIGNMENT/Lab3/Triangle.java | 62 +++++++++++++++++ ASSIGNMENT/Lab3/TriangleDemo.java | 25 +++++++ ASSIGNMENT/Lab3/emailBreak.java | 35 ++++++++++ ASSIGNMENT/Lab4/BankAccount.java | 30 ++++++++ ASSIGNMENT/Lab4/BankAcountDemo.java | 31 +++++++++ ASSIGNMENT/Lab4/Box.java | 22 ++++++ ASSIGNMENT/Lab4/BoxDemo.java | 17 +++++ ASSIGNMENT/Lab4/Circle.java | 33 +++++++++ ASSIGNMENT/Lab4/CircleDemo.java | 23 ++++++ ASSIGNMENT/Lab4/Rectangle.java | 37 ++++++++++ ASSIGNMENT/Lab4/RectangleDemo.java | 21 ++++++ ASSIGNMENT/Lab4/Student.java | 62 +++++++++++++++++ ASSIGNMENT/Lab4/StudentDemo.java | 34 +++++++++ ASSIGNMENT/Lab5/ArithmeticProgression.java | 55 +++++++++++++++ ASSIGNMENT/Lab5/Pseudocode1.java | 40 +++++++++++ ASSIGNMENT/Lab5/Pseudocode2.java | 51 ++++++++++++++ ASSIGNMENT/Lab5/Pseudocode3.java | 48 +++++++++++++ ASSIGNMENT/Lab5/Quadratic.java | 42 +++++++++++ ASSIGNMENT/Lab5/Switchcase.java | 77 +++++++++++++++++++++ ASSIGNMENT/Lab6/Author.java | 45 ++++++++++++ ASSIGNMENT/Lab6/BoxDemoModify.java | Bin 0 -> 894 bytes ASSIGNMENT/Lab6/BoxModify.java | 44 ++++++++++++ ASSIGNMENT/Lab6/Employee1.java | 58 ++++++++++++++++ ASSIGNMENT/Lab6/Employee2.java | 53 ++++++++++++++ ASSIGNMENT/Lab6/Employee3.java | 52 ++++++++++++++ ASSIGNMENT/Lab6/TestAuthor.java | 33 +++++++++ ASSIGNMENT/Lab6/TestEmployee1.java | 41 +++++++++++ ASSIGNMENT/Lab6/TestEmployee2.java | 40 +++++++++++ ASSIGNMENT/Lab6/TestEmployee3.java | 42 +++++++++++ 31 files changed, 1197 insertions(+) create mode 100644 ASSIGNMENT/Lab3/Box.java create mode 100644 ASSIGNMENT/Lab3/BoxDemo.java create mode 100644 ASSIGNMENT/Lab3/Triangle.java create mode 100644 ASSIGNMENT/Lab3/TriangleDemo.java create mode 100644 ASSIGNMENT/Lab3/emailBreak.java create mode 100644 ASSIGNMENT/Lab4/BankAccount.java create mode 100644 ASSIGNMENT/Lab4/BankAcountDemo.java create mode 100644 ASSIGNMENT/Lab4/Box.java create mode 100644 ASSIGNMENT/Lab4/BoxDemo.java create mode 100644 ASSIGNMENT/Lab4/Circle.java create mode 100644 ASSIGNMENT/Lab4/CircleDemo.java create mode 100644 ASSIGNMENT/Lab4/Rectangle.java create mode 100644 ASSIGNMENT/Lab4/RectangleDemo.java create mode 100644 ASSIGNMENT/Lab4/Student.java create mode 100644 ASSIGNMENT/Lab4/StudentDemo.java create mode 100644 ASSIGNMENT/Lab5/ArithmeticProgression.java create mode 100644 ASSIGNMENT/Lab5/Pseudocode1.java create mode 100644 ASSIGNMENT/Lab5/Pseudocode2.java create mode 100644 ASSIGNMENT/Lab5/Pseudocode3.java create mode 100644 ASSIGNMENT/Lab5/Quadratic.java create mode 100644 ASSIGNMENT/Lab5/Switchcase.java create mode 100644 ASSIGNMENT/Lab6/Author.java create mode 100644 ASSIGNMENT/Lab6/BoxDemoModify.java create mode 100644 ASSIGNMENT/Lab6/BoxModify.java create mode 100644 ASSIGNMENT/Lab6/Employee1.java create mode 100644 ASSIGNMENT/Lab6/Employee2.java create mode 100644 ASSIGNMENT/Lab6/Employee3.java create mode 100644 ASSIGNMENT/Lab6/TestAuthor.java create mode 100644 ASSIGNMENT/Lab6/TestEmployee1.java create mode 100644 ASSIGNMENT/Lab6/TestEmployee2.java create mode 100644 ASSIGNMENT/Lab6/TestEmployee3.java diff --git a/ASSIGNMENT/Lab3/Box.java b/ASSIGNMENT/Lab3/Box.java new file mode 100644 index 0000000..2ec736c --- /dev/null +++ b/ASSIGNMENT/Lab3/Box.java @@ -0,0 +1,21 @@ + +public class Box +{ + double length; + double width; + double height; + double volume; + double surfaceArea; + + public double getVolume() + { + volume = length * width * height; + return volume; + } + + public double getSurfaceArea() + { + surfaceArea = length + width + height; + return volume; + } +} diff --git a/ASSIGNMENT/Lab3/BoxDemo.java b/ASSIGNMENT/Lab3/BoxDemo.java new file mode 100644 index 0000000..47f1a79 --- /dev/null +++ b/ASSIGNMENT/Lab3/BoxDemo.java @@ -0,0 +1,23 @@ +import java.util.Scanner; +public class BoxDemo +{ + + public static void main(String[] args) + { + Box box = new Box(); + + Scanner input = new Scanner(System.in); + + System.out.println("Enter the Length"); + box.length = input.nextDouble(); + + System.out.println("Enter the Width"); + box.width = input.nextDouble(); + + System.out.println("Enter the Length"); + box.height = input.nextDouble(); + + System.out.println("The volume is: " + box.getVolume()); + System.out.println("The volume is: " + box.getSurfaceArea()); + } +} diff --git a/ASSIGNMENT/Lab3/Triangle.java b/ASSIGNMENT/Lab3/Triangle.java new file mode 100644 index 0000000..bc455cd --- /dev/null +++ b/ASSIGNMENT/Lab3/Triangle.java @@ -0,0 +1,62 @@ + +public class Triangle +{ + int hypotenus; + int shortestSide; + int a; + int b; + int c; + + public Triangle(int s1, int s2, int s3) + { + a = s1; + b = s2; + c = s3; + + if (a > b && a > c) + { + hypotenus = a; + if (b > c) + shortestSide = c; + else if (c > b) + shortestSide = b; + } + + else if (b > a && b > c) + { + hypotenus = b; + if (a > c) + shortestSide = c; + else if (c > a) + shortestSide = a; + } + else if (c > a && c > b) + { + hypotenus = c; + if (a > b) + shortestSide = b; + else if (b > a) + shortestSide = a; + } + } + + + public double getPerimeter() + { + double perimeter = a + b + c; + return perimeter; + } + + public double getArea() + { + //using Heron's Formula + double s = (a + b + c)/2; + double area = Math.sqrt(s *((s-a) * (s-b) * (s-c))); + return area; + } + + public double getRatio() + { + return hypotenus/shortestSide; + } +} diff --git a/ASSIGNMENT/Lab3/TriangleDemo.java b/ASSIGNMENT/Lab3/TriangleDemo.java new file mode 100644 index 0000000..58fbd48 --- /dev/null +++ b/ASSIGNMENT/Lab3/TriangleDemo.java @@ -0,0 +1,25 @@ + +import java.util.Scanner; +public class TriangleDemo +{ + public static void main(String[] args) + { + Scanner input = new Scanner(System.in); + System.out.println("Please enter the sides of the Triangle\n First Side: "); + int firstSide = input.nextInt(); + + System.out.println("Second Side: "); + int secondSide = input.nextInt(); + + System.out.println("Third Side: "); + int thirdSide = input.nextInt(); + + Triangle triangle = new Triangle(firstSide, secondSide, thirdSide); + + System.out.println("The Perimter of the Triangle is: " + triangle.getPerimeter()); + System.out.println("The Area of the Triangle is: " + triangle.getArea()); + System.out.println("The Longest side of the Triangle is: " + triangle.hypotenus); + System.out.println("The Shortest side of the Triangle is: " + triangle.shortestSide); + System.out.println("The remainder is: " + triangle.getRatio()); + } +} diff --git a/ASSIGNMENT/Lab3/emailBreak.java b/ASSIGNMENT/Lab3/emailBreak.java new file mode 100644 index 0000000..a51528f --- /dev/null +++ b/ASSIGNMENT/Lab3/emailBreak.java @@ -0,0 +1,35 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package assignment; + +import java.util.Scanner; +//Program to break inputed email into username and domain name +public class 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/ASSIGNMENT/Lab4/BankAccount.java b/ASSIGNMENT/Lab4/BankAccount.java new file mode 100644 index 0000000..2da506a --- /dev/null +++ b/ASSIGNMENT/Lab4/BankAccount.java @@ -0,0 +1,30 @@ + +public class BankAccount +{ + private String accountNumber; + private String accountName; + private int accountBalance; + + public BankAccount(String number, String name, int balance) + { + accountNumber = number; + accountName = name; + accountBalance = balance; + } + + public void deposit(int amountToDeposit) + { + + accountBalance = accountBalance + amountToDeposit; + } + + public void withdraw(int amountToWithdraw) + { + accountBalance = accountBalance - amountToWithdraw; + } + + public int getBalance() + { + return accountBalance; + } +} diff --git a/ASSIGNMENT/Lab4/BankAcountDemo.java b/ASSIGNMENT/Lab4/BankAcountDemo.java new file mode 100644 index 0000000..306d474 --- /dev/null +++ b/ASSIGNMENT/Lab4/BankAcountDemo.java @@ -0,0 +1,31 @@ +import java.util.Scanner; +public class BankAccountDemo +{ + public static void main(String[] args) + { + Scanner input = new Scanner(System.in); + + System.out.println("Enter Account Number: "); + String accNo = input.nextLine(); + + System.out.println("Enter Customer Name: "); + String name = input.nextLine(); + + System.out.println("Enter Initial Balance: "); + int bal = input.nextInt(); + + BankAccount bankAccount = new BankAccount(accNo, name, bal); + + System.out.println("Enter amount to deposit: "); + bankAccount.deposit(input.nextInt()); + + System.out.println("New balance is: " + bankAccount.getBalance()); + + System.out.println("Enter amount to withdraw: "); + bankAccount.withdraw(input.nextInt()); + + System.out.println("New balance is: " + bankAccount.getBalance() + "\n\n"); + + + } +} diff --git a/ASSIGNMENT/Lab4/Box.java b/ASSIGNMENT/Lab4/Box.java new file mode 100644 index 0000000..6d61938 --- /dev/null +++ b/ASSIGNMENT/Lab4/Box.java @@ -0,0 +1,22 @@ + +public class Box +{ + private double length, width, height; + + public Box(double boxLength, double boxWidth, double boxHeight) + { + length = boxLength; + width = boxWidth; + height = boxHeight; + } + + public double volume() + { + return length * width * height; + } + + public double surfaceArea() + { + return 2 * (length*width + length*height + width*height); + } +} diff --git a/ASSIGNMENT/Lab4/BoxDemo.java b/ASSIGNMENT/Lab4/BoxDemo.java new file mode 100644 index 0000000..661ab03 --- /dev/null +++ b/ASSIGNMENT/Lab4/BoxDemo.java @@ -0,0 +1,17 @@ +import java.util.Scanner; +public class BoxDemo +{ + public static void main(String[] args) + { + + Box box1 = new Box(20.0, 10.0, 15.0); + Box box2 = new Box(6.0, 4.0, 2.0); + + + System.out.println("The volume of box1 is: " + box1.volume() + " cubic cm"); + System.out.println("The surface area of box1 is: " + box1.surfaceArea() + " square cm"); + + System.out.println("The volume of box2 is: " + box2.volume() + " cubic cm"); + System.out.println("The surface area of box2 is: " + box2.surfaceArea() + " square cm"); + } +} diff --git a/ASSIGNMENT/Lab4/Circle.java b/ASSIGNMENT/Lab4/Circle.java new file mode 100644 index 0000000..4f06cb9 --- /dev/null +++ b/ASSIGNMENT/Lab4/Circle.java @@ -0,0 +1,33 @@ + + 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 * Math.PI * radius; + } + + public static int getNumberOfCircles() + { + return numberOfCircles; + } + + public void setRadius(double rad) + { + radius = rad; + } +} diff --git a/ASSIGNMENT/Lab4/CircleDemo.java b/ASSIGNMENT/Lab4/CircleDemo.java new file mode 100644 index 0000000..55bb247 --- /dev/null +++ b/ASSIGNMENT/Lab4/CircleDemo.java @@ -0,0 +1,23 @@ +import java.util.Scanner; +public class CircleDemo +{ + public static void main(String[] args) + { + Scanner input = new Scanner(System.in); + System.out.println("The number of Circles is: " + Circle.getNumberOfCircles()); + + System.out.println("Please enter the radius of the Circle 1: "); + Circle circle1 = new Circle(input.nextDouble()); + System.out.println("The number of circles is: " + circle1.getNumberOfCircles()); + + System.out.println("Please enter the radius of the Circle 2: "); + Circle circle2 = new Circle(input.nextDouble()); + System.out.println("The number of circles is: " + circle2.getNumberOfCircles()); + + System.out.println("The Area of the first circle is: " + circle1.area()); + System.out.println("The Perimeter of the first circle is: " + circle1.circumference() + " cm"); + + System.out.println("The Area of the second circle is: " + circle2.area()); + System.out.println("The Perimeter of the second circle is: " + circle2.circumference() + " cm"); + } +} diff --git a/ASSIGNMENT/Lab4/Rectangle.java b/ASSIGNMENT/Lab4/Rectangle.java new file mode 100644 index 0000000..dd745fc --- /dev/null +++ b/ASSIGNMENT/Lab4/Rectangle.java @@ -0,0 +1,37 @@ + +public class Rectangle +{ + private double length, width; + + public Rectangle(double recLength, double recWidth) + { + length = recLength; + width = recWidth; + } + + public double area() + { + return length * width; + } + + public double getLength() + { + return length; + } + + public double getWidth() + { + return width; + } + + public void setLength(double newLength) + { + length = newLength; + } + + public void setWidth(double newWidth) + { + width = newWidth; + } + +} diff --git a/ASSIGNMENT/Lab4/RectangleDemo.java b/ASSIGNMENT/Lab4/RectangleDemo.java new file mode 100644 index 0000000..5409869 --- /dev/null +++ b/ASSIGNMENT/Lab4/RectangleDemo.java @@ -0,0 +1,21 @@ +import java.util.Scanner; +public class RectangleDemo +{ + public static void main(String[] args) + { + Scanner input = new Scanner(System.in); + System.out.println("Please Enter the Length: "); + double l = input.nextDouble(); + System.out.println("Please Enter the Width: "); + double w = input.nextDouble(); + Rectangle rectangle = new Rectangle(l,w); + System.out.println("The Area is : " + rectangle.area() + " square cm"); + System.out.println("The Length of the Rectangle is : " + rectangle.getLength() + " cm"); + System.out.println("Please enter the new Length of the Rectangle"); + + rectangle.setLength(input.nextDouble()); + System.out.println("The new Length of the Rectangle is : " + rectangle.getLength() + " cm"); + System.out.println("The new Area of the Rectangle is: " + rectangle.area()); + + } +} diff --git a/ASSIGNMENT/Lab4/Student.java b/ASSIGNMENT/Lab4/Student.java new file mode 100644 index 0000000..9bd2472 --- /dev/null +++ b/ASSIGNMENT/Lab4/Student.java @@ -0,0 +1,62 @@ + +public class Student +{ + private String name; + private int iDNumber; + private double quiz1, quiz2, quiz3; + + public Student(String sName, int id, double firstQuiz, double secondQuiz, double thirdQuiz) + { + name = sName; + iDNumber = id; + quiz1 = firstQuiz; + quiz2 = secondQuiz; + quiz3 = thirdQuiz; + } + + public String getName() + { + return name; + } + + public int getId() + { + return iDNumber; + } + + public void getQuiz() + { + System.out.println("Quiz1 = " + quiz1); + System.out.println("Quiz2 = " + quiz2); + System.out.println("Quiz3 = " + quiz3); + } + + public void setQuizOne(double quizOne) + { + quiz1 = quizOne; + } + + public void setQuizTwo(double quizTwo) + { + quiz2 = quizTwo; + } + + public void setQuizThree(double quizThree) + { + quiz3 = quizThree; + } + + public double average() + { + return (quiz1 + quiz2 + quiz3)/3; + } + + public void printDetails() + { + + getName(); + getId(); + getQuiz(); + average(); + } +} diff --git a/ASSIGNMENT/Lab4/StudentDemo.java b/ASSIGNMENT/Lab4/StudentDemo.java new file mode 100644 index 0000000..5a997c8 --- /dev/null +++ b/ASSIGNMENT/Lab4/StudentDemo.java @@ -0,0 +1,34 @@ +import java.util.Scanner; +public class StudentDemo +{ + + public static void main(String[] args) + { + Scanner input = new Scanner(System.in); + System.out.println("Please enter your name"); + String name = input.nextLine(); + + System.out.println("Please enter your ID"); + int id = input.nextInt(); + + System.out.println("Please enter your Quiz Grades"); + System.out.println("Quiz 1: "); + double q1 = input.nextInt(); + + System.out.println("Quiz 2: "); + double q2 = input.nextInt(); + + System.out.println("Quiz 3: "); + double q3 = input.nextInt(); + + Student student = new Student(name, id, q1, q2, q3); + + student.printDetails(); + + System.out.println("Enter new grade for quiz 3: "); + student.setQuizThree(input.nextDouble()); + + student.printDetails(); + + } +} diff --git a/ASSIGNMENT/Lab5/ArithmeticProgression.java b/ASSIGNMENT/Lab5/ArithmeticProgression.java new file mode 100644 index 0000000..2a52dd3 --- /dev/null +++ b/ASSIGNMENT/Lab5/ArithmeticProgression.java @@ -0,0 +1,55 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package assignment; +import java.util.Scanner; +/** + *2 + * @author UMAR HARUNA A ZAKARI + */ +public class ArithmeticProgression { + + + + public static void main(String[] args) + { + Scanner input = new Scanner(System.in); + + double firstTerm = 0; + double numberOfTerms = 0; + double nthTerm = 0; + double commonDifference = 0; + double sum= 0; + double term = 0; + + System.out.print("Enter the value of a (First Term) : "); + firstTerm = input.nextDouble(); + + System.out.print("Enter the value of d (Common Difference) : "); + commonDifference = input.nextDouble(); + + System.out.print("Enter the value of n (Number of terms) : "); + numberOfTerms = input.nextDouble(); + + nthTerm = firstTerm + (numberOfTerms - 1) * commonDifference; + + sum = numberOfTerms * (2 * firstTerm + (numberOfTerms - 1) * commonDifference)/2; + + System.out.println(""); + System.out.println("The Arithmetic Progression is as follows :"); + + for(int i = 0; i < numberOfTerms; i++){ + term = firstTerm + i * commonDifference; + System.out.print(term+" + "); + } + + System.out.println("..."); + System.out.println("The nthTerm of the series : " + nthTerm); + System.out.println("The Sum of n terms of series : " + sum); + } +} + + + diff --git a/ASSIGNMENT/Lab5/Pseudocode1.java b/ASSIGNMENT/Lab5/Pseudocode1.java new file mode 100644 index 0000000..46e9787 --- /dev/null +++ b/ASSIGNMENT/Lab5/Pseudocode1.java @@ -0,0 +1,40 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package assignment; +import java.util.Scanner; +/** + * + * @author UMAR HARUNA A ZAKARI + */ +public class Pseudocode1 { + + public static void main(String [] args){ + + int counter,total,num,average; + Scanner input = new Scanner(System.in);; + + counter=1; + total=0; + + + + while(counter<=10){ + + System.out.println("Enter Number"); + num = input.nextInt(); + + total=total+num; + counter=counter+1; + } + + average=total/10; + + + + System.out.println("total :"+average); + +} + } diff --git a/ASSIGNMENT/Lab5/Pseudocode2.java b/ASSIGNMENT/Lab5/Pseudocode2.java new file mode 100644 index 0000000..af5c856 --- /dev/null +++ b/ASSIGNMENT/Lab5/Pseudocode2.java @@ -0,0 +1,51 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package assignment; + +import java.util.Scanner; + +/** + * + * @author UMAR HARUNA A ZAKARI + */ +public class Pseudocode2 { + public static void main(String [] args){ + + int counter,grade,total; + float average; + + Scanner input = new Scanner(System.in);; + + total=0; + counter=0; + + System.out.println("Enter grade, -1 to end: "); + grade = input.nextInt(); + + while(grade != -1){ + + System.out.println("Enter grade, -1 to end: "); + grade = input.nextInt(); + + total=total+grade; + counter=counter+1; + + System.out.println("Enter grade, -1 to end: "); + grade = input.nextInt(); + } + + + + if (counter !=0){ + average = (float)total/counter; + + System.out.println("Class average is : "+average); + } + else{ + System.out.println("No grades were entered: "); + } + + }} \ No newline at end of file diff --git a/ASSIGNMENT/Lab5/Pseudocode3.java b/ASSIGNMENT/Lab5/Pseudocode3.java new file mode 100644 index 0000000..c2f8795 --- /dev/null +++ b/ASSIGNMENT/Lab5/Pseudocode3.java @@ -0,0 +1,48 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package assignment; + +import java.util.Scanner; + +/** + * + * @author UMAR HARUNA A ZAKARI + */ +public class Pseudocode3 { + public static void main(String [] args){ + int passes =0; + int failures=0; + int student=0; + int result; + + Scanner input = new Scanner(System.in); + + while (student<=10){ + System.out.println("Enter result ( 1=pass,2=fail ): "); + result = input.nextInt(); + + if (result==1){ + passes=passes+1; + + } + else{ + failures=failures+1; + } + + student=student+1; + } + System.out.println("Passed :"+passes); + System.out.println("Failed :"+failures); + + if(passes>8){ + System.out.println("Raise tuition"); + + } + + return; + } + +} diff --git a/ASSIGNMENT/Lab5/Quadratic.java b/ASSIGNMENT/Lab5/Quadratic.java new file mode 100644 index 0000000..0f80b86 --- /dev/null +++ b/ASSIGNMENT/Lab5/Quadratic.java @@ -0,0 +1,42 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package assignment; + +/** + * + * @author UMAR HARUNA A ZAKARI + */ +public class Quadratic +{ + public static void main(String[] args) + { + /*Suppose our Quadratic Equation to be solved + * is 2x2 + 6x + 4 = 0 . + * (Assuming that both roots are real valued) + * + * General form of a Quadratic Equation is + * ax2 + bx + c = 0 where 'a' is not equal to 0 + * + * Hence a = 2, b = 6 and c = 4. + */ + + int a = 3; + int b = 7; + int c = 9; + + + //Finding out the roots + + + double root1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2*a) ; + double root2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2*a) ; + + System.out.println(root1); + + + + }} + diff --git a/ASSIGNMENT/Lab5/Switchcase.java b/ASSIGNMENT/Lab5/Switchcase.java new file mode 100644 index 0000000..f3b2318 --- /dev/null +++ b/ASSIGNMENT/Lab5/Switchcase.java @@ -0,0 +1,77 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package assignment; +import java.util.Scanner; +/** + * + * @author UMAR HARUNA A ZAKARI + */ +public class Switchcase { + public static void main(String [] args) { + int score ; char grade; + Scanner input = new Scanner(System.in); + System.out.println("Enter your score"); + score = input.nextInt(); + + switch(score){ + + + case 100: + case 99: + case 98: + case 97: + case 96: + case 95: + case 94: + case 93: + case 92: + case 91: + case 90: grade = 'A'; break; + + + case 89: + case 88: + case 87: + case 86: + case 85: + case 84: + case 83: + case 82: + case 81: + case 80: grade = 'B'; break; + + + case 79: + case 78: + case 77: + case 76: + case 75: + case 74: + case 73: + case 72: + case 71: + case 70: grade = 'C'; break; + + + case 69: + case 68: + case 67: + case 66: + case 65: + case 64: + case 63: + case 62: + case 61: + case 60: grade = 'D'; break; + + default: grade = 'F'; break; + + + + } + + System.out.println("Your test score is "+ score + ", which is equivalent to the grade " + grade + "."); } +} diff --git a/ASSIGNMENT/Lab6/Author.java b/ASSIGNMENT/Lab6/Author.java new file mode 100644 index 0000000..09a5040 --- /dev/null +++ b/ASSIGNMENT/Lab6/Author.java @@ -0,0 +1,45 @@ + +/** + * Write a description of class Arthur here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Author +{ + // instance variables - replace the example below with your own + private String name, email; + private char gender; + + /** + * Constructor for objects of class Arthur + */ + public Author(String name, String email, char gender) + { + this.name=name; + this.email=email; + this.gender=gender; + } + public String getName() + { + return name; + } + public String getEmail() + { + return email; + } + public void setEmail(String email) + { + this.email=email; + } + public char getGender() + { + return gender; + } + + public String toString() + { + // put your code here + return "\n"+getName()+" ("+getGender()+") at "+getEmail(); + } +} diff --git a/ASSIGNMENT/Lab6/BoxDemoModify.java b/ASSIGNMENT/Lab6/BoxDemoModify.java new file mode 100644 index 0000000000000000000000000000000000000000..90496814f3c160e0b240c96dd9c6a744a5f9ce6f GIT binary patch literal 894 zcmah{%TB{E5agV%Sml&Hl(ebff{>sfapF`Y4wQqFxUErQ2S3_IsQ=E|af+&@;6r4u zXJ==|36kM3fFZm|rYR68sLCa)H4_}f3i6UD1#_`~qLp|N1zR<+p_0bfW83bD(HkKl zYJ`!%Nks>)yroiEiikkB<)+H01O($0q8%^^YLk^L@0$~R2LRyjl_nZtTfqvb2;F&1}rIUCvhH3k~ zjwgfL^RD!)%To0rXJ^QpBV{4bJ4H{WspuGuP}0sylD?~}ZaF<@@|kKNynuqKx+IM! zawTQtisbm7$Z4O^%5!b)Fcf7gaeIoqa0m7`p5OudyX!@xG_7J`bX;Thy5vzf$8e{> z6ofExl%DDmHg(t$4p09<&W^~LM_zV}22TuIdgr!J#*)8oy3l<~r he`gi`A=mPq%x?qtUTvzQ5Y(5!9WpJs=Q;$3;0IEk69@nR literal 0 HcmV?d00001 diff --git a/ASSIGNMENT/Lab6/BoxModify.java b/ASSIGNMENT/Lab6/BoxModify.java new file mode 100644 index 0000000..ad81d8d --- /dev/null +++ b/ASSIGNMENT/Lab6/BoxModify.java @@ -0,0 +1,44 @@ + +/** + * Write a description of class BoxModify here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class BoxModify +{ + private double length , width , height; //instance variables + public BoxModify(double boxLength , double boxWidth , double boxHeight) { //constructor + length = boxLength; + width = boxWidth; + height = boxHeight; + } + public BoxModify(BoxModify obj) { //constructor + length = obj.length; + width = obj.width; + height = obj.height; + } + public BoxModify(double boxLength) { //constructor + length = boxLength; + width = boxLength; + height = boxLength; + } + public double volume() { //instant methods + return length * width * height; + } + public double surfaceArea() { + return 2*(length*width + length*height + width*height); + } + public double getLength( ){ + return length; + } + public double getWidth(){ + return width; + } + public double getHeight(){ + return height; + } + public String toString() { + return "\nLength: "+getLength()+" Width: "+getWidth()+" Height:"+getHeight(); + } +} diff --git a/ASSIGNMENT/Lab6/Employee1.java b/ASSIGNMENT/Lab6/Employee1.java new file mode 100644 index 0000000..e7e129c --- /dev/null +++ b/ASSIGNMENT/Lab6/Employee1.java @@ -0,0 +1,58 @@ + +/** + * Write a description of class Employee1 here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Employee1 +{ + private int iDNumber; + private String name; + private double salary; + public Employee1(int iD, String employeeName, double employeeSalary){ + iDNumber = iD; + name = employeeName; + salary = employeeSalary; + } + public Employee1(String employeeName, int iD, double employeeSalary){ + iDNumber = iD; + name = employeeName; + salary = employeeSalary; + } + public Employee1(int iD, String employeeName) { + iDNumber = iD; + name = employeeName; + salary = 0.0; + } + public Employee1(String employeeName, int iD) { + iDNumber = iD; + name = employeeName; + salary = 0.0; + } + public void setSalary(double employeeSalary) { + salary = employeeSalary; + } + public int getIDNumber(){ + return iDNumber; + } + public String getName() { + return name; + } + public double getSalary() { + return salary; + } + public void deductions(double telephoneBills) { + salary -= telephoneBills; + } + public void deductions(double telephoneBills, double medicalBills) { + salary -= (telephoneBills + medicalBills); + } + public void raiseSalary(double percentIncrease) { + salary += salary * percentIncrease/100; + } + public void printDetails() { + System.out.println("\nID Number: "+iDNumber+"\nName: "+name+"\nSalary:" + +salary) ; + } +} diff --git a/ASSIGNMENT/Lab6/Employee2.java b/ASSIGNMENT/Lab6/Employee2.java new file mode 100644 index 0000000..308e366 --- /dev/null +++ b/ASSIGNMENT/Lab6/Employee2.java @@ -0,0 +1,53 @@ + +/** + * Write a description of class Employee2 here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Employee2 +{ + private int iDNumber; + private String name; + private double salary; + public Employee2(int iDNumber, String name, double salary) { + this.iDNumber = iDNumber; + this.name = name; + this.salary = salary; + } + public Employee2(String name, int iDNumber, double salary) { + this(iDNumber, name, salary); + } + public Employee2(int iDNumber, String name) { + this(iDNumber, name, 0.0); + } + public Employee2(String name, int iDNumber) { + this(iDNumber, name, 0.0); + } + public void setSalary(double salary) { + this.salary = salary; + } + public int getIDNumber() { + return iDNumber; + } + public String getName() { + return name; + } + public double getSalary() { + return salary; + } + public void deductions(double telephoneBills) { + salary -= telephoneBills; + } + public void deductions(double telephoneBills, double medicalBills) { + salary -= (telephoneBills + medicalBills); + } + public void raiseSalary(double percentIncrease) { + salary += salary * percentIncrease/100; + } + + public void printDetails() { + System.out.println("\nID Number: "+iDNumber+"\nName: "+name+"\nSalary:"+salary); + } +} + \ No newline at end of file diff --git a/ASSIGNMENT/Lab6/Employee3.java b/ASSIGNMENT/Lab6/Employee3.java new file mode 100644 index 0000000..a054005 --- /dev/null +++ b/ASSIGNMENT/Lab6/Employee3.java @@ -0,0 +1,52 @@ + +/** + * Write a description of class Employee3 here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Employee3 +{ + private int iDNumber; + private String name; + private double salary; + public Employee3(int iDNumber, String name, double salary) { + this.iDNumber = iDNumber; + this.name = name; + this.salary = salary; + } + public Employee3(String name, int iDNumber, double salary) { + this(iDNumber, name, salary); + } + public Employee3(int iDNumber, String name) { + this(iDNumber, name, 0.0); + } + public Employee3(String name, int iDNumber) { + this(iDNumber, name, 0.0); + } + public void setSalary(double salary) { + this.salary = salary; + } + public int getIDNumber() { + return iDNumber; + } + public String getName() { + return name; + } + public double getSalary() { + return salary; + } + public void deductions(double telephoneBills) { + salary -= telephoneBills; + } + public void deductions(double telephoneBills, double medicalBills) { + salary -= (telephoneBills + medicalBills); + } + public void raiseSalary(double percentIncrease) { + salary += salary * percentIncrease/100; + } + + public String toString() { + return "\nID Number: "+iDNumber+"\nName: "+name+"\nSalary:"+salary; + } +} diff --git a/ASSIGNMENT/Lab6/TestAuthor.java b/ASSIGNMENT/Lab6/TestAuthor.java new file mode 100644 index 0000000..df70496 --- /dev/null +++ b/ASSIGNMENT/Lab6/TestAuthor.java @@ -0,0 +1,33 @@ + +/** + * Write a description of class TestArthur here. + * + * @author (your name) + * @version (a version number or a date) + */ +import java.util.Scanner; +public class TestAuthor +{ + public static void main(String[ ] args) { + Scanner input = new Scanner(System. in); + String name,email; + char gender; + System.out.print("Enter Author Name: "); + name = input.nextLine(); + System.out.print("Enter gender e.g M or F: "); + gender = input.next().charAt(0); + input.nextLine(); + System.out.print("Enter email: "); + email = input.nextLine(); + //any of the following constructors be used to create the object + Author author = new Author(name, email,gender); + + System.out.println(author); + //enter new email + System.out.print("\nEnter new email: "); + email = input.nextLine(); + author.setEmail(email); + //print new email + System.out.println(author); + } +} diff --git a/ASSIGNMENT/Lab6/TestEmployee1.java b/ASSIGNMENT/Lab6/TestEmployee1.java new file mode 100644 index 0000000..e289eb1 --- /dev/null +++ b/ASSIGNMENT/Lab6/TestEmployee1.java @@ -0,0 +1,41 @@ + +/** + * Write a description of class TestEmployee1 here. + * + * @author (your name) + * @version (a version number or a date) + */ +import java.util.Scanner; +public class TestEmployee1 +{ + public static void main(String[ ] args) { + Scanner input = new Scanner(System. in); + int number; + String name; + double salary; + System.out.print("Enter Name for Employee 1: "); + name = input.nextLine(); + System.out.print("Enter ID Number for Employee 1: "); + number = input.nextInt(); + System.out.print("Enter Salary for Employee 1: "); + salary = input.nextDouble(); + //any of the following constructors be used to create the object + Employee1 emp1 = new Employee1(number, name, salary); + // or Employee1 emp1 = new Employee1(name, number, salary) ; + input.nextLine(); + System.out.print("\nEnter Name for Employee 2: "); + name = input.nextLine(); + //input.nextLine(); + System.out.print("Enter ID Number for Employee 2: "); + number = input.nextInt(); + //if we do not know the salary, we can use one of the following constructors + Employee1 emp2 = new Employee1(number, name); + //or Employee1 emp2 = new Employee1(name, number) ; + emp2.setSalary(emp1.getSalary()); + emp1.deductions(50); + emp2.deductions(60, 40); + emp1.printDetails(); + emp2.printDetails(); + } +} + diff --git a/ASSIGNMENT/Lab6/TestEmployee2.java b/ASSIGNMENT/Lab6/TestEmployee2.java new file mode 100644 index 0000000..17d79ba --- /dev/null +++ b/ASSIGNMENT/Lab6/TestEmployee2.java @@ -0,0 +1,40 @@ + +/** + * Write a description of class TestEmployee2 here. + * + * @author (your name) + * @version (a version number or a date) + */ +import java.util.Scanner; +public class TestEmployee2 +{ + public static void main(String[ ] args) { + Scanner input = new Scanner(System. in); + int number; + String name; + double salary; + System.out.print("Enter Name for Employee 1: "); + name = input.nextLine(); + System.out.print("Enter ID Number for Employee 1: "); + number = input.nextInt(); + System.out.print("Enter Salary for Employee 1: "); + salary = input.nextDouble(); + //any of the following constructors be used to create the object + Employee2 emp1 = new Employee2(number, name, salary); + // or Employee1 emp1 = new Employee1(name, number, salary) ; + input.nextLine(); + System.out.print("\nEnter Name for Employee 2: "); + name = input.nextLine(); + //input.nextLine(); + System.out.print("Enter ID Number for Employee 2: "); + number = input.nextInt(); + //if we do not know the salary, we can use one of the following constructors + Employee2 emp2 = new Employee2(number, name); + //or Employee1 emp2 = new Employee1(name, number) ; + emp2.setSalary(emp1.getSalary()); + emp1.deductions(50); + emp2.deductions(60, 40); + emp1.printDetails(); + emp2.printDetails(); + } +} diff --git a/ASSIGNMENT/Lab6/TestEmployee3.java b/ASSIGNMENT/Lab6/TestEmployee3.java new file mode 100644 index 0000000..59b1571 --- /dev/null +++ b/ASSIGNMENT/Lab6/TestEmployee3.java @@ -0,0 +1,42 @@ + +/** + * Write a description of class TestEmployee3 here. + * + * @author (your name) + * @version (a version number or a date) + */ +import java.util.Scanner; +public class TestEmployee3 +{ + public static void main(String[ ] args) { + Scanner input = new Scanner(System. in); + int number; + String name; + double salary; + System.out.print("Enter Name for Employee 1: "); + name = input.nextLine(); + System.out.print("Enter ID Number for Employee 1: "); + number = input.nextInt(); + System.out.print("Enter Salary for Employee 1: "); + salary = input.nextDouble(); + //any of the following constructors be used to create the object + Employee3 emp1 = new Employee3(number, name, salary); + // or Employee1 emp1 = new Employee1(name, number, salary) ; + input.nextLine(); + System.out.print("\nEnter Name for Employee 2: "); + name = input.nextLine(); + //input.nextLine(); + System.out.print("Enter ID Number for Employee 2: "); + number = input.nextInt(); + //if we do not know the salary, we can use one of the following constructors + Employee3 emp2 = new Employee3(number, name); + //or Employee1 emp2 = new Employee1(name, number) ; + emp2.setSalary(emp1.getSalary()); + emp1.deductions(50); + emp2.deductions(60, 40); + //emp1.printDetails(); + //emp2.printDetails(); + System.out.println(emp1); + System.out.println(emp2); + } +}