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
32 changes: 32 additions & 0 deletions JAVA MAIN/Assignment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 Assignment {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);

System.out.println("please enter name: ");
String name=input.nextLine();

System.out.println("please enter age: ");
int age =input.nextInt();




System.out.println(name+ " " +age);





}
}

28 changes: 28 additions & 0 deletions JAVA MAIN/BoxDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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;

public class BoxDemo{
public static void main (String[] args){
//Create two box objects
BoxC box1 = new BoxC(20.0,12.0,15.0);
BoxC box2 = new BoxC(9.0,5.0,12.0);
double volume ,area;

volume=box1.volume();
area=box1.surfaceArea();

//volume and surface area of box1
System.out.println("the volume of box1 is: "+volume+" cubic cm" );
System.out.println("the area of box1 is: "+area+" square cm\n" );

//volume and surface area of box2
System.out.println("the volume of box2 is: "+box2.volume()+" cubic cm" );
System.out.println("the area of box2 is: "+box2.surfaceArea()+" square cm\n" );


}
}
21 changes: 21 additions & 0 deletions JAVA MAIN/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 JAVA MAIN/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 JAVA MAIN/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 JAVA MAIN/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 JAVA MAIN/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]);
}
}


49 changes: 49 additions & 0 deletions JAVA MAIN/Lab4/BankAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

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 JAVA MAIN/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 JAVA MAIN/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 JAVA MAIN/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 JAVA MAIN/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;
}
}
Loading