diff --git a/Lab 3/Box.class b/Lab 3/Box.class new file mode 100644 index 0000000..e759a87 Binary files /dev/null and b/Lab 3/Box.class differ diff --git a/Lab 3/Box.ctxt b/Lab 3/Box.ctxt new file mode 100644 index 0000000..fcb6483 --- /dev/null +++ b/Lab 3/Box.ctxt @@ -0,0 +1,7 @@ +#BlueJ class context +comment0.target=Box +comment1.params= +comment1.target=double\ getVolume() +comment2.params= +comment2.target=double\ getSurfaceArea() +numComments=3 diff --git a/Lab 3/Box.java b/Lab 3/Box.java new file mode 100644 index 0000000..2ec736c --- /dev/null +++ b/Lab 3/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/Lab 3/QuestionOne.class b/Lab 3/QuestionOne.class new file mode 100644 index 0000000..c6331b4 Binary files /dev/null and b/Lab 3/QuestionOne.class differ diff --git a/Lab 3/QuestionOne.ctxt b/Lab 3/QuestionOne.ctxt new file mode 100644 index 0000000..710063b --- /dev/null +++ b/Lab 3/QuestionOne.ctxt @@ -0,0 +1,5 @@ +#BlueJ class context +comment0.target=QuestionOne +comment1.params=args +comment1.target=void\ main(java.lang.String[]) +numComments=2 diff --git a/Lab 3/QuestionOne.java b/Lab 3/QuestionOne.java new file mode 100644 index 0000000..b215946 --- /dev/null +++ b/Lab 3/QuestionOne.java @@ -0,0 +1,23 @@ +import java.util.Scanner; +public class QuestionOne +{ + + 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/Lab 3/QuestionThree.class b/Lab 3/QuestionThree.class new file mode 100644 index 0000000..3994be4 Binary files /dev/null and b/Lab 3/QuestionThree.class differ diff --git a/Lab 3/QuestionThree.ctxt b/Lab 3/QuestionThree.ctxt new file mode 100644 index 0000000..8634f25 --- /dev/null +++ b/Lab 3/QuestionThree.ctxt @@ -0,0 +1,5 @@ +#BlueJ class context +comment0.target=QuestionThree +comment1.params=args +comment1.target=void\ main(java.lang.String[]) +numComments=2 diff --git a/Lab 3/QuestionThree.java b/Lab 3/QuestionThree.java new file mode 100644 index 0000000..ca0b171 --- /dev/null +++ b/Lab 3/QuestionThree.java @@ -0,0 +1,25 @@ + +import java.util.Scanner; +public class QuestionThree +{ + 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/Lab 3/QuestionTwo.class b/Lab 3/QuestionTwo.class new file mode 100644 index 0000000..ce3a14b Binary files /dev/null and b/Lab 3/QuestionTwo.class differ diff --git a/Lab 3/QuestionTwo.ctxt b/Lab 3/QuestionTwo.ctxt new file mode 100644 index 0000000..81d2e9b --- /dev/null +++ b/Lab 3/QuestionTwo.ctxt @@ -0,0 +1,5 @@ +#BlueJ class context +comment0.target=QuestionTwo +comment1.params=args +comment1.target=void\ main(java.lang.String[]) +numComments=2 diff --git a/Lab 3/QuestionTwo.java b/Lab 3/QuestionTwo.java new file mode 100644 index 0000000..c74cb92 --- /dev/null +++ b/Lab 3/QuestionTwo.java @@ -0,0 +1,14 @@ +import java.util.Scanner; +public class QuestionTwo +{ + public static void main(String[] args) + { + Scanner input = new Scanner(System.in); + System.out.println("Please enter your e-mail address "); + String email = input.nextLine(); + User user = new User(); + user.readEmail(email); + System.out.println("User Name is: " + user.userName); + System.out.println("Domain Name is: " + user.domainName); + } +} diff --git a/Lab 3/README.TXT b/Lab 3/README.TXT new file mode 100644 index 0000000..3762b20 --- /dev/null +++ b/Lab 3/README.TXT @@ -0,0 +1,12 @@ +------------------------------------------------------------------------ +This is the project README file. Here, you should describe your project. +Tell the reader (someone who does not know anything about this project) +all he/she needs to know. The comments should usually include at least: +------------------------------------------------------------------------ + +PROJECT TITLE: Java 2019 +PURPOSE OF PROJECT: Practical Class +VERSION or DATE: Lab 3 +HOW TO START THIS PROJECT: +AUTHORS: U15/FNS/CSC/054 +USER INSTRUCTIONS: diff --git a/Lab 3/Triangle.class b/Lab 3/Triangle.class new file mode 100644 index 0000000..d78a4bd Binary files /dev/null and b/Lab 3/Triangle.class differ diff --git a/Lab 3/Triangle.ctxt b/Lab 3/Triangle.ctxt new file mode 100644 index 0000000..84b37db --- /dev/null +++ b/Lab 3/Triangle.ctxt @@ -0,0 +1,11 @@ +#BlueJ class context +comment0.target=Triangle +comment1.params=s1\ s2\ s3 +comment1.target=Triangle(int,\ int,\ int) +comment2.params= +comment2.target=double\ getPerimeter() +comment3.params= +comment3.target=double\ getArea() +comment4.params= +comment4.target=double\ getRatio() +numComments=5 diff --git a/Lab 3/Triangle.java b/Lab 3/Triangle.java new file mode 100644 index 0000000..bc455cd --- /dev/null +++ b/Lab 3/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/Lab 3/User.class b/Lab 3/User.class new file mode 100644 index 0000000..3c499be Binary files /dev/null and b/Lab 3/User.class differ diff --git a/Lab 3/User.ctxt b/Lab 3/User.ctxt new file mode 100644 index 0000000..dd666a2 --- /dev/null +++ b/Lab 3/User.ctxt @@ -0,0 +1,5 @@ +#BlueJ class context +comment0.target=User +comment1.params=userEmail +comment1.target=void\ readEmail(java.lang.String) +numComments=2 diff --git a/Lab 3/User.java b/Lab 3/User.java new file mode 100644 index 0000000..310b7fa --- /dev/null +++ b/Lab 3/User.java @@ -0,0 +1,16 @@ + +public class User +{ + String email; + String domainName; + String userName; + + public void readEmail(String userEmail) + { + email = userEmail; + int emailNo = email.indexOf("@"); + domainName = email.substring(emailNo + 1); + userName = email.substring(0,emailNo); + } + +} diff --git a/Lab 3/package.bluej b/Lab 3/package.bluej new file mode 100644 index 0000000..770c8ff --- /dev/null +++ b/Lab 3/package.bluej @@ -0,0 +1,76 @@ +#BlueJ package file +dependency1.from=QuestionOne +dependency1.to=Box +dependency1.type=UsesDependency +dependency2.from=QuestionTwo +dependency2.to=User +dependency2.type=UsesDependency +dependency3.from=QuestionThree +dependency3.to=Triangle +dependency3.type=UsesDependency +editor.fx.0.height=739 +editor.fx.0.width=816 +editor.fx.0.x=275 +editor.fx.0.y=-4 +objectbench.height=98 +objectbench.width=657 +package.divider.horizontal=0.6 +package.divider.vertical=0.8346456692913385 +package.editor.height=523 +package.editor.width=567 +package.editor.x=100 +package.editor.y=100 +package.frame.height=735 +package.frame.width=697 +package.numDependencies=3 +package.numTargets=6 +package.showExtends=true +package.showUses=true +project.charset=UTF-8 +readme.height=58 +readme.name=@README +readme.width=47 +readme.x=10 +readme.y=10 +target1.height=50 +target1.name=QuestionOne +target1.showInterface=false +target1.type=ClassTarget +target1.width=110 +target1.x=70 +target1.y=10 +target2.height=50 +target2.name=User +target2.showInterface=false +target2.type=ClassTarget +target2.width=80 +target2.x=230 +target2.y=90 +target3.height=50 +target3.name=QuestionTwo +target3.showInterface=false +target3.type=ClassTarget +target3.width=110 +target3.x=70 +target3.y=100 +target4.height=50 +target4.name=Triangle +target4.showInterface=false +target4.type=ClassTarget +target4.width=80 +target4.x=230 +target4.y=180 +target5.height=50 +target5.name=Box +target5.showInterface=false +target5.type=ClassTarget +target5.width=80 +target5.x=230 +target5.y=10 +target6.height=50 +target6.name=QuestionThree +target6.showInterface=false +target6.type=ClassTarget +target6.width=120 +target6.x=70 +target6.y=180 diff --git a/Lab 4/BankAccount.class b/Lab 4/BankAccount.class new file mode 100644 index 0000000..6a2d9c0 Binary files /dev/null and b/Lab 4/BankAccount.class differ diff --git a/Lab 4/BankAccount.ctxt b/Lab 4/BankAccount.ctxt new file mode 100644 index 0000000..4fd4e87 --- /dev/null +++ b/Lab 4/BankAccount.ctxt @@ -0,0 +1,11 @@ +#BlueJ class context +comment0.target=BankAccount +comment1.params=number\ name\ balance +comment1.target=BankAccount(java.lang.String,\ java.lang.String,\ int) +comment2.params=amountToDeposit +comment2.target=void\ deposit(int) +comment3.params=amountToWithdraw +comment3.target=void\ withdraw(int) +comment4.params= +comment4.target=int\ getBalance() +numComments=5 diff --git a/Lab 4/BankAccount.java b/Lab 4/BankAccount.java new file mode 100644 index 0000000..2da506a --- /dev/null +++ b/Lab 4/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/Lab 4/Box.class b/Lab 4/Box.class new file mode 100644 index 0000000..22f0c08 Binary files /dev/null and b/Lab 4/Box.class differ diff --git a/Lab 4/Box.ctxt b/Lab 4/Box.ctxt new file mode 100644 index 0000000..c6abf33 --- /dev/null +++ b/Lab 4/Box.ctxt @@ -0,0 +1,9 @@ +#BlueJ class context +comment0.target=Box +comment1.params=boxLength\ boxWidth\ boxHeight +comment1.target=Box(double,\ double,\ double) +comment2.params= +comment2.target=double\ volume() +comment3.params= +comment3.target=double\ surfaceArea() +numComments=4 diff --git a/Lab 4/Box.java b/Lab 4/Box.java new file mode 100644 index 0000000..6d61938 --- /dev/null +++ b/Lab 4/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/Lab 4/BoxDemo.class b/Lab 4/BoxDemo.class new file mode 100644 index 0000000..13ef3c1 Binary files /dev/null and b/Lab 4/BoxDemo.class differ diff --git a/Lab 4/BoxDemo.ctxt b/Lab 4/BoxDemo.ctxt new file mode 100644 index 0000000..cce1ee7 --- /dev/null +++ b/Lab 4/BoxDemo.ctxt @@ -0,0 +1,5 @@ +#BlueJ class context +comment0.target=BoxDemo +comment1.params=args +comment1.target=void\ main(java.lang.String[]) +numComments=2 diff --git a/Lab 4/BoxDemo.java b/Lab 4/BoxDemo.java new file mode 100644 index 0000000..661ab03 --- /dev/null +++ b/Lab 4/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/Lab 4/Circle.class b/Lab 4/Circle.class new file mode 100644 index 0000000..1e73278 Binary files /dev/null and b/Lab 4/Circle.class differ diff --git a/Lab 4/Circle.ctxt b/Lab 4/Circle.ctxt new file mode 100644 index 0000000..ec11bce --- /dev/null +++ b/Lab 4/Circle.ctxt @@ -0,0 +1,13 @@ +#BlueJ class context +comment0.target=Circle +comment1.params=circleRadius +comment1.target=Circle(double) +comment2.params= +comment2.target=double\ area() +comment3.params= +comment3.target=double\ circumference() +comment4.params= +comment4.target=int\ getNumberOfCircles() +comment5.params=rad +comment5.target=void\ setRadius(double) +numComments=6 diff --git a/Lab 4/Circle.java b/Lab 4/Circle.java new file mode 100644 index 0000000..4f06cb9 --- /dev/null +++ b/Lab 4/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/Lab 4/CircleDemo.class b/Lab 4/CircleDemo.class new file mode 100644 index 0000000..22784f3 Binary files /dev/null and b/Lab 4/CircleDemo.class differ diff --git a/Lab 4/CircleDemo.ctxt b/Lab 4/CircleDemo.ctxt new file mode 100644 index 0000000..49f69cc --- /dev/null +++ b/Lab 4/CircleDemo.ctxt @@ -0,0 +1,5 @@ +#BlueJ class context +comment0.target=CircleDemo +comment1.params=args +comment1.target=void\ main(java.lang.String[]) +numComments=2 diff --git a/Lab 4/CircleDemo.java b/Lab 4/CircleDemo.java new file mode 100644 index 0000000..55bb247 --- /dev/null +++ b/Lab 4/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/Lab 4/QuestionTwo.class b/Lab 4/QuestionTwo.class new file mode 100644 index 0000000..5818022 Binary files /dev/null and b/Lab 4/QuestionTwo.class differ diff --git a/Lab 4/QuestionTwo.ctxt b/Lab 4/QuestionTwo.ctxt new file mode 100644 index 0000000..81d2e9b --- /dev/null +++ b/Lab 4/QuestionTwo.ctxt @@ -0,0 +1,5 @@ +#BlueJ class context +comment0.target=QuestionTwo +comment1.params=args +comment1.target=void\ main(java.lang.String[]) +numComments=2 diff --git a/Lab 4/QuestionTwo.java b/Lab 4/QuestionTwo.java new file mode 100644 index 0000000..7055453 --- /dev/null +++ b/Lab 4/QuestionTwo.java @@ -0,0 +1,31 @@ +import java.util.Scanner; +public class QuestionTwo +{ + 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/Lab 4/README.TXT b/Lab 4/README.TXT new file mode 100644 index 0000000..71ef431 --- /dev/null +++ b/Lab 4/README.TXT @@ -0,0 +1,12 @@ +------------------------------------------------------------------------ +This is the project README file. Here, you should describe your project. +Tell the reader (someone who does not know anything about this project) +all he/she needs to know. The comments should usually include at least: +------------------------------------------------------------------------ + +PROJECT TITLE: Java 2019 +PURPOSE OF PROJECT: Practical Class +VERSION or DATE: Lab 4 +HOW TO START THIS PROJECT: +AUTHORS: U15/FNS/CSC/054 +USER INSTRUCTIONS: diff --git a/Lab 4/Rectangle.class b/Lab 4/Rectangle.class new file mode 100644 index 0000000..07ab74a Binary files /dev/null and b/Lab 4/Rectangle.class differ diff --git a/Lab 4/Rectangle.ctxt b/Lab 4/Rectangle.ctxt new file mode 100644 index 0000000..1484935 --- /dev/null +++ b/Lab 4/Rectangle.ctxt @@ -0,0 +1,15 @@ +#BlueJ class context +comment0.target=Rectangle +comment1.params=recLength\ recWidth +comment1.target=Rectangle(double,\ double) +comment2.params= +comment2.target=double\ area() +comment3.params= +comment3.target=double\ getLength() +comment4.params= +comment4.target=double\ getWidth() +comment5.params=newLength +comment5.target=void\ setLength(double) +comment6.params=newWidth +comment6.target=void\ setWidth(double) +numComments=7 diff --git a/Lab 4/Rectangle.java b/Lab 4/Rectangle.java new file mode 100644 index 0000000..dd745fc --- /dev/null +++ b/Lab 4/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/Lab 4/RectangleDemo.class b/Lab 4/RectangleDemo.class new file mode 100644 index 0000000..bfdafb5 Binary files /dev/null and b/Lab 4/RectangleDemo.class differ diff --git a/Lab 4/RectangleDemo.ctxt b/Lab 4/RectangleDemo.ctxt new file mode 100644 index 0000000..73aa7bc --- /dev/null +++ b/Lab 4/RectangleDemo.ctxt @@ -0,0 +1,5 @@ +#BlueJ class context +comment0.target=RectangleDemo +comment1.params=args +comment1.target=void\ main(java.lang.String[]) +numComments=2 diff --git a/Lab 4/RectangleDemo.java b/Lab 4/RectangleDemo.java new file mode 100644 index 0000000..5409869 --- /dev/null +++ b/Lab 4/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/Lab 4/Student.class b/Lab 4/Student.class new file mode 100644 index 0000000..3c51d8f Binary files /dev/null and b/Lab 4/Student.class differ diff --git a/Lab 4/Student.ctxt b/Lab 4/Student.ctxt new file mode 100644 index 0000000..84b9d37 --- /dev/null +++ b/Lab 4/Student.ctxt @@ -0,0 +1,21 @@ +#BlueJ class context +comment0.target=Student +comment1.params=sName\ id\ firstQuiz\ secondQuiz\ thirdQuiz +comment1.target=Student(java.lang.String,\ int,\ double,\ double,\ double) +comment2.params= +comment2.target=java.lang.String\ getName() +comment3.params= +comment3.target=int\ getId() +comment4.params= +comment4.target=void\ getQuiz() +comment5.params=quizOne +comment5.target=void\ setQuizOne(double) +comment6.params=quizTwo +comment6.target=void\ setQuizTwo(double) +comment7.params=quizThree +comment7.target=void\ setQuizThree(double) +comment8.params= +comment8.target=double\ average() +comment9.params= +comment9.target=void\ printDetails() +numComments=10 diff --git a/Lab 4/Student.java b/Lab 4/Student.java new file mode 100644 index 0000000..9bd2472 --- /dev/null +++ b/Lab 4/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/Lab 4/StudentDemo.class b/Lab 4/StudentDemo.class new file mode 100644 index 0000000..dde7e2b Binary files /dev/null and b/Lab 4/StudentDemo.class differ diff --git a/Lab 4/StudentDemo.ctxt b/Lab 4/StudentDemo.ctxt new file mode 100644 index 0000000..83d2316 --- /dev/null +++ b/Lab 4/StudentDemo.ctxt @@ -0,0 +1,5 @@ +#BlueJ class context +comment0.target=StudentDemo +comment1.params=args +comment1.target=void\ main(java.lang.String[]) +numComments=2 diff --git a/Lab 4/StudentDemo.java b/Lab 4/StudentDemo.java new file mode 100644 index 0000000..5a997c8 --- /dev/null +++ b/Lab 4/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/Lab 4/package.bluej b/Lab 4/package.bluej new file mode 100644 index 0000000..daf409e --- /dev/null +++ b/Lab 4/package.bluej @@ -0,0 +1,107 @@ +#BlueJ package file +dependency1.from=QuestionTwo +dependency1.to=BankAccount +dependency1.type=UsesDependency +dependency2.from=CircleDemo +dependency2.to=Circle +dependency2.type=UsesDependency +dependency3.from=RectangleDemo +dependency3.to=Rectangle +dependency3.type=UsesDependency +dependency4.from=StudentDemo +dependency4.to=Student +dependency4.type=UsesDependency +editor.fx.0.height=739 +editor.fx.0.width=816 +editor.fx.0.x=275 +editor.fx.0.y=-4 +objectbench.height=93 +objectbench.width=657 +package.divider.horizontal=0.6 +package.divider.vertical=0.84251968503937 +package.editor.height=528 +package.editor.width=567 +package.editor.x=100 +package.editor.y=100 +package.frame.height=735 +package.frame.width=697 +package.numDependencies=4 +package.numTargets=10 +package.showExtends=true +package.showUses=true +project.charset=UTF-8 +readme.height=58 +readme.name=@README +readme.width=47 +readme.x=10 +readme.y=10 +target1.height=50 +target1.name=RectangleDemo +target1.showInterface=false +target1.type=ClassTarget +target1.width=120 +target1.x=190 +target1.y=130 +target10.height=50 +target10.name=BoxDemo +target10.showInterface=false +target10.type=ClassTarget +target10.width=90 +target10.x=190 +target10.y=10 +target2.height=50 +target2.name=Circle +target2.showInterface=false +target2.type=ClassTarget +target2.width=80 +target2.x=70 +target2.y=70 +target3.height=50 +target3.name=QuestionTwo +target3.showInterface=false +target3.type=ClassTarget +target3.width=110 +target3.x=190 +target3.y=200 +target4.height=50 +target4.name=CircleDemo +target4.showInterface=false +target4.type=ClassTarget +target4.width=100 +target4.x=190 +target4.y=70 +target5.height=50 +target5.name=Rectangle +target5.showInterface=false +target5.type=ClassTarget +target5.width=90 +target5.x=60 +target5.y=130 +target6.height=50 +target6.name=StudentDemo +target6.showInterface=false +target6.type=ClassTarget +target6.width=110 +target6.x=190 +target6.y=280 +target7.height=50 +target7.name=BankAccount +target7.showInterface=false +target7.type=ClassTarget +target7.width=110 +target7.x=50 +target7.y=200 +target8.height=50 +target8.name=Box +target8.showInterface=false +target8.type=ClassTarget +target8.width=80 +target8.x=70 +target8.y=10 +target9.height=50 +target9.name=Student +target9.showInterface=false +target9.type=ClassTarget +target9.width=80 +target9.x=60 +target9.y=280 diff --git a/Lab1and2/A.java b/Lab1and2/A.java new file mode 100644 index 0000000..c5bf002 --- /dev/null +++ b/Lab1and2/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/Lab1and2/B.java b/Lab1and2/B.java new file mode 100644 index 0000000..92cc81b --- /dev/null +++ b/Lab1and2/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/Lab1and2/C.java b/Lab1and2/C.java new file mode 100644 index 0000000..a2800a5 --- /dev/null +++ b/Lab1and2/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/Lab1and2/D.java b/Lab1and2/D.java new file mode 100644 index 0000000..f62b906 --- /dev/null +++ b/Lab1and2/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/Lab1and2/E.java b/Lab1and2/E.java new file mode 100644 index 0000000..9e6b824 --- /dev/null +++ b/Lab1and2/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/Lab1and2/F.java b/Lab1and2/F.java new file mode 100644 index 0000000..c6219d2 --- /dev/null +++ b/Lab1and2/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 *"); + } + +}