Skip to content

Lab1, lab2 u16/fns/csc/2069 #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
20 changes: 20 additions & 0 deletions Lab3Box.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
23 changes: 23 additions & 0 deletions Lab3BoxDemo.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());
}
}
35 changes: 35 additions & 0 deletions Lab3EmailBreak.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]);
}
}


61 changes: 61 additions & 0 deletions Lab3Triangle.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
24 changes: 24 additions & 0 deletions Lab3TriangleDemo.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
21 changes: 21 additions & 0 deletions Lab4Box.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
18 changes: 18 additions & 0 deletions Lab4BoxDemo.java
Original file line number Diff line number Diff line change
@@ -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");
}
}

32 changes: 32 additions & 0 deletions Lab4Circle.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
23 changes: 23 additions & 0 deletions Lab4CircleDemo.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");
}
}
21 changes: 21 additions & 0 deletions Lab4Rectangledemo.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());

}
}
61 changes: 61 additions & 0 deletions Lab4Student.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
34 changes: 34 additions & 0 deletions Lab4studentdemo.java
Original file line number Diff line number Diff line change
@@ -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();

}
}
Loading