Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ASSIGNMENT/Lab3/Box.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
23 changes: 23 additions & 0 deletions ASSIGNMENT/Lab3/BoxDemo.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
62 changes: 62 additions & 0 deletions ASSIGNMENT/Lab3/Triangle.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
25 changes: 25 additions & 0 deletions ASSIGNMENT/Lab3/TriangleDemo.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
35 changes: 35 additions & 0 deletions ASSIGNMENT/Lab3/emailBreak.java
Original file line number Diff line number Diff line change
@@ -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]);
}
}


30 changes: 30 additions & 0 deletions ASSIGNMENT/Lab4/BankAccount.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
31 changes: 31 additions & 0 deletions ASSIGNMENT/Lab4/BankAcountDemo.java
Original file line number Diff line number Diff line change
@@ -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");


}
}
22 changes: 22 additions & 0 deletions ASSIGNMENT/Lab4/Box.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
17 changes: 17 additions & 0 deletions ASSIGNMENT/Lab4/BoxDemo.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
33 changes: 33 additions & 0 deletions ASSIGNMENT/Lab4/Circle.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
23 changes: 23 additions & 0 deletions ASSIGNMENT/Lab4/CircleDemo.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
37 changes: 37 additions & 0 deletions ASSIGNMENT/Lab4/Rectangle.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
21 changes: 21 additions & 0 deletions ASSIGNMENT/Lab4/RectangleDemo.java
Original file line number Diff line number Diff line change
@@ -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());

}
}
Loading