diff --git a/Lab3Box.java b/Lab3Box.java new file mode 100644 index 0000000..2537d1a --- /dev/null +++ b/Lab3Box.java @@ -0,0 +1,20 @@ +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/Lab3BoxDemo.java b/Lab3BoxDemo.java new file mode 100644 index 0000000..4ed3f83 --- /dev/null +++ b/Lab3BoxDemo.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/Lab3EmailBreak.java b/Lab3EmailBreak.java new file mode 100644 index 0000000..d357bc7 --- /dev/null +++ b/Lab3EmailBreak.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/Lab3Triangle.java b/Lab3Triangle.java new file mode 100644 index 0000000..1359bf9 --- /dev/null +++ b/Lab3Triangle.java @@ -0,0 +1,61 @@ +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/Lab3TriangleDemo.java b/Lab3TriangleDemo.java new file mode 100644 index 0000000..2d7ecb2 --- /dev/null +++ b/Lab3TriangleDemo.java @@ -0,0 +1,24 @@ +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/Lab4Box.java b/Lab4Box.java new file mode 100644 index 0000000..092ae72 --- /dev/null +++ b/Lab4Box.java @@ -0,0 +1,21 @@ +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/Lab4BoxDemo.java b/Lab4BoxDemo.java new file mode 100644 index 0000000..e4f4342 --- /dev/null +++ b/Lab4BoxDemo.java @@ -0,0 +1,18 @@ +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/Lab4Circle.java b/Lab4Circle.java new file mode 100644 index 0000000..f1cbe1c --- /dev/null +++ b/Lab4Circle.java @@ -0,0 +1,32 @@ +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 * Math.PI * radius; + } + + public static int getNumberOfCircles() + { + return numberOfCircles; + } + + public void setRadius(double rad) + { + radius = rad; + } + } diff --git a/Lab4CircleDemo.java b/Lab4CircleDemo.java new file mode 100644 index 0000000..926f8f5 --- /dev/null +++ b/Lab4CircleDemo.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/Lab4Rectangledemo.java b/Lab4Rectangledemo.java new file mode 100644 index 0000000..97404c3 --- /dev/null +++ b/Lab4Rectangledemo.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/Lab4Student.java b/Lab4Student.java new file mode 100644 index 0000000..096a744 --- /dev/null +++ b/Lab4Student.java @@ -0,0 +1,61 @@ +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/Lab4studentdemo.java b/Lab4studentdemo.java new file mode 100644 index 0000000..823bd9f --- /dev/null +++ b/Lab4studentdemo.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/Lab5Arithmetic progression.java b/Lab5Arithmetic progression.java new file mode 100644 index 0000000..3e29e0e --- /dev/null +++ b/Lab5Arithmetic progression.java @@ -0,0 +1,52 @@ +/* + * 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 + */ + 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/Lab5Quadratic.java b/Lab5Quadratic.java new file mode 100644 index 0000000..b49bf7d --- /dev/null +++ b/Lab5Quadratic.java @@ -0,0 +1,43 @@ +/* + * 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 + */ + 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/Lab5Switchcase.java b/Lab5Switchcase.java new file mode 100644 index 0000000..394426e --- /dev/null +++ b/Lab5Switchcase.java @@ -0,0 +1,76 @@ +/* + * 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 + 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/Lab5pseudocode.java b/Lab5pseudocode.java new file mode 100644 index 0000000..e3aae29 --- /dev/null +++ b/Lab5pseudocode.java @@ -0,0 +1,49 @@ + + /* + * 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 + */ + 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/Lab6 employee2.java b/Lab6 employee2.java new file mode 100644 index 0000000..145e651 --- /dev/null +++ b/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); + } + } + diff --git a/Lab6Author.java b/Lab6Author.java new file mode 100644 index 0000000..e9afc85 --- /dev/null +++ b/Lab6Author.java @@ -0,0 +1,47 @@ +@@ -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(); + } + } + BIN +894 Bytes ASSIGNMENT/Lab6/BoxDemoModify.java diff --git a/Lab6Employee1.java b/Lab6Employee1.java new file mode 100644 index 0000000..faf58ba --- /dev/null +++ b/Lab6Employee1.java @@ -0,0 +1,57 @@ +/** + * 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/Lab6Employee3.java b/Lab6Employee3.java new file mode 100644 index 0000000..58f54f3 --- /dev/null +++ b/Lab6Employee3.java @@ -0,0 +1,51 @@ +/** + * 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/Lab6TestEmployee2.java b/Lab6TestEmployee2.java new file mode 100644 index 0000000..1c3511f --- /dev/null +++ b/Lab6TestEmployee2.java @@ -0,0 +1,39 @@ + /** + * 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/Lab6TestEmployee3.java b/Lab6TestEmployee3.java new file mode 100644 index 0000000..3848586 --- /dev/null +++ b/Lab6TestEmployee3.java @@ -0,0 +1,41 @@ +/** + * 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); + } +} diff --git a/lAb4bankAccount.java b/lAb4bankAccount.java new file mode 100644 index 0000000..6c3fe6b --- /dev/null +++ b/lAb4bankAccount.java @@ -0,0 +1,29 @@ +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/lab4BankAcctDemo.java b/lab4BankAcctDemo.java new file mode 100644 index 0000000..c32a306 --- /dev/null +++ b/lab4BankAcctDemo.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/lab4Rectangle.java b/lab4Rectangle.java new file mode 100644 index 0000000..144f0a7 --- /dev/null +++ b/lab4Rectangle.java @@ -0,0 +1,36 @@ +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/lab5Pseudocode2.java b/lab5Pseudocode2.java new file mode 100644 index 0000000..32159f3 --- /dev/null +++ b/lab5Pseudocode2.java @@ -0,0 +1,52 @@ +* + * 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 + */ + 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: "); + } + + } +} diff --git a/lab5psuleudocode1.java b/lab5psuleudocode1.java new file mode 100644 index 0000000..0abe859 --- /dev/null +++ b/lab5psuleudocode1.java @@ -0,0 +1,41 @@ +/* + * 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 + */ + 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/lab6Boxmodify.java b/lab6Boxmodify.java new file mode 100644 index 0000000..3306392 --- /dev/null +++ b/lab6Boxmodify.java @@ -0,0 +1,43 @@ +/** + * 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/lab6TestAuthor.java b/lab6TestAuthor.java new file mode 100644 index 0000000..a40739d --- /dev/null +++ b/lab6TestAuthor.java @@ -0,0 +1,32 @@ +/** + * 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/lab6TestEmployee1.java b/lab6TestEmployee1.java new file mode 100644 index 0000000..6bcbcab --- /dev/null +++ b/lab6TestEmployee1.java @@ -0,0 +1,40 @@ +//** + * 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/labs/displayTable.java b/labs/displayTable.java new file mode 100644 index 0000000..523dab9 --- /dev/null +++ b/labs/displayTable.java @@ -0,0 +1,12 @@ +package practicalClass; +//U15/FNS/CSC/063 +//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/labs/labTwo_addressBreak.java b/labs/labTwo_addressBreak.java new file mode 100644 index 0000000..0fdf013 --- /dev/null +++ b/labs/labTwo_addressBreak.java @@ -0,0 +1,29 @@ +package practicalClass; + +import java.util.Scanner; +//U15/CSC/063 +//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/labs/labTwo_emailBreak.java b/labs/labTwo_emailBreak.java new file mode 100644 index 0000000..1416804 --- /dev/null +++ b/labs/labTwo_emailBreak.java @@ -0,0 +1,29 @@ +package practicalClass; +//U15/FNS/CSC/063 +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/labs/labTwo_mathFunction.java b/labs/labTwo_mathFunction.java new file mode 100644 index 0000000..296f8ad --- /dev/null +++ b/labs/labTwo_mathFunction.java @@ -0,0 +1,20 @@ +package practicalClass; +//U15/FNS/CSC/063 +//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/labs/labTwo_one.java b/labs/labTwo_one.java new file mode 100644 index 0000000..4c8c9b0 --- /dev/null +++ b/labs/labTwo_one.java @@ -0,0 +1,24 @@ +package practicalClass; +//U15/FNS/CSC/063 +//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/labs/patternDisplay.java b/labs/patternDisplay.java new file mode 100644 index 0000000..a7a8a9a --- /dev/null +++ b/labs/patternDisplay.java @@ -0,0 +1,11 @@ +package practicalClass; +//U15/FNS/CSC/063 +//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 *"); + } + +}