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
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added out/production/Assignment1/com/company/Circle.class
Binary file not shown.
Binary file not shown.
Binary file added out/production/Assignment1/com/company/Main.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added out/production/Assignment1/com/company/Sphere.class
Binary file not shown.
Binary file added out/production/Assignment1/com/company/Square.class
Binary file not shown.
Binary file not shown.
184 changes: 184 additions & 0 deletions src/com/Hotwax/www/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
package com.company;
import java.util.*;


class Triangle{
int height;
int base;

void getDimensions(int h , int b){
height = h;
base = b;
}

void calculateArea(){
System.out.println((height*base)/2);
}

void calculatePerimeter(int a , int b , int c){
System.out.println(a+b+c);
}
}
class Rectangle{
void calculateArea(int l , int b){
System.out.println(l*b);
}
void calculatePerimeter(int l , int b){
System.out.println(2*l + 2*b);
}
}
class Square{
void calculateArea(int l ){
System.out.println(l*l);
}
void calculatePerimeter(int l){
System.out.println(4*l);
}
}
class Cylinder{
void calculateArea(int r, int h ){
System.out.println(2*3.14*r*h+ 2*3.14*r*r);
}
void calculatePerimeter(int r ){
System.out.println((2*3.14*r*r));
}
void calculateVolume(int r , int h ){
System.out.println(3.14 * r*r*h);
}
}
class Sphere{
void calculateArea(int r ){
System.out.println(4*3.14*r*r);
}
void calculatePerimeter(int r ){
System.out.println((2*3.14*r));
}
void calculateVolume(int r ){
System.out.println(3.14 * r*r*r * 1.34);
}
}
class Circle{
void calculateArea(int r){
System.out.println(3.14*r*r);
}
void calculatePerimeter(int r){
System.out.println((2*3.14*r));
}
}
public class Main {

public static void main(String[] args) {
// write your code here
while (true)
{
System.out.println("Enter shape : ");
Scanner sc = new Scanner(System.in);
String shape = sc.next();
if (shape.equalsIgnoreCase( "triangle")){
Triangle t = new Triangle();
System.out.println("Enter Operation to be performed : ");
String operation = sc.next();
if (operation.equalsIgnoreCase("area")){
System.out.print("Enter height of Triangle : ");
int height = sc.nextInt();
System.out.print("Enter base of Triangle : ");
int base = sc.nextInt();
t.getDimensions(height, base);
t.calculateArea();
}
if (operation.equalsIgnoreCase("perimeter")){
System.out.println("Enter length of first side");
int a = sc.nextInt();
System.out.println("Enter length of second side");
int b = sc.nextInt();
System.out.println("Enter length of third side");
int c = sc.nextInt();
t.calculatePerimeter(a,b,c);
}

}
else if (shape.equalsIgnoreCase("rectangle")){
Rectangle r = new Rectangle();
System.out.println("Enter Operation to be performed : ");
String operation = sc.next();
System.out.println("Enter length : ");
int l = sc.nextInt();
System.out.println("Enter breadth : ");
int b = sc.nextInt();
if (operation.equalsIgnoreCase("area")){
r.calculateArea(l,b);
}
else if (operation.equalsIgnoreCase("perimeter")){
r.calculatePerimeter(l,b);
}
}
else if (shape.equalsIgnoreCase("square")){
Square r = new Square();
System.out.println("Enter Operation to be performed : ");
String operation = sc.next();
System.out.println("Enter side : ");
int l = sc.nextInt();
if (operation.equalsIgnoreCase("area")){
r.calculateArea(l);
}
else if (operation.equalsIgnoreCase("perimeter")){
r.calculatePerimeter(l);
}
}
else if (shape.equalsIgnoreCase("cylinder")){
Cylinder c = new Cylinder();
System.out.println("Enter Operation to be performed : ");
String operation = sc.next();
System.out.println("Enter radius : ");
int r = sc.nextInt();
System.out.println("Enter height : ");
int h = sc.nextInt();
if (operation.equalsIgnoreCase("area")){
c.calculateArea(r,h);
}
else if (operation.equalsIgnoreCase("perimeter")){
c.calculatePerimeter(r);
}
else if (operation.equalsIgnoreCase("Volume")){
c.calculateVolume(r,h);
}
}
else if (shape.equalsIgnoreCase("circle")){
Circle c = new Circle();
System.out.println("Enter Operation to be performed : ");
String operation = sc.next();
System.out.println("Enter radius : ");
int r = sc.nextInt();
if (operation.equalsIgnoreCase("area")){
c.calculateArea(r);
}
else if (operation.equalsIgnoreCase("perimeter")) {
c.calculatePerimeter(r);
}
}
else if (shape.equalsIgnoreCase("Sphere")){
Sphere s = new Sphere();
System.out.println("Enter Operation to be performed : ");
String operation = sc.next();
System.out.println("Enter radius : ");
int r = sc.nextInt();
if (operation.equalsIgnoreCase("area")){
s.calculateArea(r);
}
else if (operation.equalsIgnoreCase("perimeter")) {
s.calculatePerimeter(r);
}
else if (operation.equalsIgnoreCase("Volume")) {
s.calculateVolume(r);
}
}
else if (shape.equalsIgnoreCase("done")){
break;
}
else{
System.out.println("shape not found");
}

}
}
}
49 changes: 49 additions & 0 deletions src/com/Hotwax/www/Problem_statement_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.company;
import java.io.*;
import java.util.Scanner;
import java.net.*;


public class Problem_statement_1 {
public static void main(String[] args) {
String[] a = new String[3];
try {
File obj1 = new File("url.txt");
Scanner r = new Scanner(obj1);
File f = new File("words.txt");
Scanner sc = new Scanner(f);
int j=0;
while (sc.hasNextLine()){
// System.out.println(sc.nextLine());
a[j] = sc.nextLine();
j+=1;
}
while (r.hasNextLine()) {
String data = r.nextLine();
URL x = new URL(data);
BufferedReader in = new BufferedReader(new InputStreamReader(x.openStream()));
String inputLine;

int v=0,w=0,y=0;
while ((inputLine = in.readLine()) != null) {
String result = inputLine.replaceAll("<[^>]*>", "");
int count = (result.split(a[0]).length) - 1;
int count1 = (result.split(a[1]).length) - 1;
int count2 = (result.split(a[2]).length) - 1;
v += count;
w += count1;
y += count2;
}
System.out.println("Word "+a[0]+" has occurred "+v+" times");
System.out.println("Word "+a[1]+" has occurred "+w+" times");
System.out.println("Word "+a[2]+" has occurred "+y+" times");

in.close();
}
r.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
39 changes: 39 additions & 0 deletions src/com/Hotwax/www/Problem_statement_4_OverdrawnDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.company;

class Accountt extends Thread {
String name;
int balance = 1000;
int getBalance(){
return balance;
}
public void run(){
int i =0;
while(i<5){
balance = balance - 100;
System.out.println("b"+balance);
i+=1;
}

}
}

class AccountOverdrawDemo1 {
public void main() {
Accountt boy1 = new Accountt();
boy1.name = "vin";
boy1.run();
boy1.start();

for(int i =0 ; i<5;i++){
boy1.balance = boy1.balance-100;
System.out.println("a"+boy1.balance);
}
}
}
public class Problem_statement_4_OverdrawnDemo {
public static void main(String[] args) {
AccountOverdrawDemo1 acc = new AccountOverdrawDemo1();
// AccountOverdrawDemo1 acc = new AccountOverdrawDemo1();
acc.main();
}
}
46 changes: 46 additions & 0 deletions src/com/Hotwax/www/Problem_statement_4_OverdrawnSafeDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.company;

class Account{
int balance = 1000;
void withdraw(String s , int b){
if (balance >= b){
balance = balance - b;
System.out.println(s +" withdrew "+b+" amount of money");
System.out.println("New balance " + balance);
}
else{
System.out.println("Not enough money");
}
}
}

class AccountOverdrawSafeDemo extends Thread{
Account ac;
String name;
int balance;
AccountOverdrawSafeDemo(Account ob, String n, int b)
{
ac = ob;
name = n;
balance = b;
}

public void run(){
ac.withdraw(name, balance);
}
}

public class Problem_statement_4_OverdrawnSafeDemo {
public static void main(String[] args) {
Account acc = new Account();
for (int i =0 ;i<5;i++){
AccountOverdrawSafeDemo a = new AccountOverdrawSafeDemo(acc, "a", 100);
a.start();
}
for (int i =0 ;i<5;i++){
AccountOverdrawSafeDemo b = new AccountOverdrawSafeDemo(acc, "b", 100);
b.start();
}
}

}
Loading