-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cba2e5
commit 9876ca1
Showing
9 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//Create a bank application to perform basic operation as withdraw and deposit using object-oriented approaches. | ||
|
||
import java.util.*; | ||
|
||
public class Bank | ||
{ | ||
private long balance; | ||
Bank(long b) | ||
{ | ||
this.balance=b; | ||
} | ||
Bank() | ||
{ | ||
this.balance=0; | ||
} | ||
private void withdraw(long n) | ||
{ | ||
if(n<0) | ||
{ | ||
System.out.println("Error : Withdraw Cannot be Negetive"); | ||
return; | ||
} | ||
this.balance-=n; | ||
if(this.balance<0) | ||
{ | ||
System.out.println("Error : Not Enough Balance"); | ||
this.balance+=n; | ||
} | ||
else | ||
{ | ||
System.out.println("Withdraw : Rs. "+n+" Withdrawn"); | ||
} | ||
} | ||
private void deposit(long n) | ||
{ | ||
if(n<0) | ||
{ | ||
System.out.println("Error : Deposit Cannot be Negetive"); | ||
return; | ||
} | ||
this.balance+=n; | ||
System.out.println("Deposit : Rs. "+n+" Deposited"); | ||
} | ||
private void display() | ||
{ | ||
System.out.println("Message : Your Current Balance is "+this.balance); | ||
} | ||
public static void main(String args[]) | ||
{ | ||
Scanner in = new Scanner(System.in); | ||
System.out.print("Enter the Intial Balance : "); | ||
Bank ob = new Bank(in.nextLong()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//Write a java program to print hello world using eclipse IDE. | ||
public class a1q1 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
System.out.println("Hello World"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//Write program to demonstrate the use of class, public, private, static key word of java. | ||
import mypack.*; | ||
public class a1q2p3 extends a1q2p1 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
//Different Package using Subclass | ||
a1q2p3 ob = new a1q2p3(); | ||
ob.display(); | ||
} | ||
void display() | ||
{ | ||
//Not accessible | ||
//System.out.println(private_Value); | ||
//System.out.println(default_Value); | ||
|
||
//Accessible | ||
System.out.println(protected_Value); | ||
System.out.println(public_Value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//Write program to demonstrate the use of class, public, private, static key word of java. | ||
|
||
import mypack.*; | ||
public class a1q2p4 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
//Different Package | ||
a1q2p1 ob = new a1q2p1(); | ||
|
||
//Not Accessible | ||
//System.out.println(ob.private_Value); | ||
//System.out.println(ob.protected_Value); | ||
//System.out.println(ob.default_Value); | ||
|
||
//Accessible | ||
System.out.println(ob.public_Value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//Write program to create a static function to check a number is prime or not. | ||
|
||
import java.util.*; | ||
|
||
public class a1q3 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
Scanner in = new Scanner(System.in); | ||
System.out.print("Enter a Number : "); | ||
int n=in.nextInt(); | ||
|
||
if(n%2==0 && n!=2) | ||
{ | ||
System.out.println(n+" is non Prime"); | ||
System.exit(0); | ||
} | ||
int sqrt=(int)(Math.sqrt(n)); | ||
for(int i=3; i<=sqrt; i+=2) | ||
{ | ||
if(n%i==0) | ||
{ | ||
System.out.println(n+" is non Prime"); | ||
System.exit(0); | ||
} | ||
} | ||
|
||
System.out.println(n+" is Prime Number"); | ||
System.exit(0); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Semester 3 (CWS-1)/Assignments/Assignment 1/mypack/a1q2p1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//Write program to demonstrate the use of class, public, private, static key word of java. | ||
|
||
package mypack; | ||
|
||
public class a1q2p1 { | ||
public String public_Value="I am Public"; | ||
protected String protected_Value="I am Protected"; | ||
String default_Value="I am Default"; | ||
private String private_Value="I am Private"; | ||
public static void main(String args[]) | ||
{ | ||
//same class | ||
a1q2p1 ob = new a1q2p1(); | ||
ob.method(); | ||
} | ||
void method() | ||
{ | ||
//Accessible | ||
System.out.println(public_Value); | ||
System.out.println(private_Value); | ||
System.out.println(protected_Value); | ||
System.out.println(default_Value); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Semester 3 (CWS-1)/Assignments/Assignment 1/mypack/a1q2p2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//Write program to demonstrate the use of class, public, private, static key word of java. | ||
package mypack; | ||
|
||
public class a1q2p2 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
//same package different class | ||
a1q2p1 ob = new a1q2p1(); | ||
System.out.println(ob.public_Value); | ||
|
||
//This one is not accessible | ||
//System.out.println(ob.private_Value); | ||
|
||
//Accessible | ||
System.out.println(ob.protected_Value); | ||
System.out.println(ob.default_Value); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Semester 3 (CWS-1)/Assignments/Assignment 1/mypack2/a1q5p1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//Write program to demonstrate the use of more than one class in a single. package. | ||
|
||
package mypack2; | ||
|
||
public class a1q5p1 | ||
{ | ||
void log(String s) | ||
{ | ||
System.out.println("LOG : "+s); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Semester 3 (CWS-1)/Assignments/Assignment 1/mypack2/a1q5p2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//Write program to demonstrate the use of more than one class in a single. package. | ||
package mypack2; | ||
|
||
public class a1q5p2 | ||
{ | ||
public static void main(String args[]) | ||
{ | ||
a1q5p1 ob = new a1q5p1(); | ||
ob.log("Hello There !!"); | ||
} | ||
} |