From 547beff30a6a3461e6995b9f5f0ec53fec1643ff Mon Sep 17 00:00:00 2001 From: TEJ-1-8 <127389564+TEJ-1-8@users.noreply.github.com> Date: Tue, 21 Mar 2023 09:20:57 +0530 Subject: [PATCH 1/2] Create and Traverse Account Program that creates a class Account that stores a variable balance. The class has methods to start account, to deposit money, to withdraw money and tell the current balance amount. --- Temp.java | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Temp.java diff --git a/Temp.java b/Temp.java new file mode 100644 index 0000000..f8fee1e --- /dev/null +++ b/Temp.java @@ -0,0 +1,59 @@ +import java.util.*; +class Temp +{ + public static void main(String[] args) + { + Account ob = new Account(); //Defaukt Constructor + ob.Traverse(); + } +} + +class Account +{ + public void Traverse() + { + Scanner sc = new Scanner(System.in); + int i=0,num1,balance=0,flag=-1; + while(i!=1) + { + System.out.println("\n\nEnter 1 to Create Account.\nEnter 2 to Deposit Money.\nEnter 3 to Withdraw Money.\nEnter 4 to Check Account Balance.\nEnter 5 to Exit."); + System.out.print("\nEnter your Choice: "); + num1=sc.nextInt(); + if(num1<1 || num1>5) + System.out.println("Invalid Choice!! \nEnter a Valid Input..!!"); + else + { + switch(num1) + { + case 1: + if(flag==-1) + { + flag=0; + System.out.println("Account created successfully."); + } + else + System.out.println("Invalid Choice!! \nAccount already successfully...!"); + break; + case 2: + System.out.print("\nEnter the amount you want to deposit: "); + int temp=sc.nextInt(); + balance+=temp; + break; + case 3: + System.out.print("\nEnter the amount you want to withdraw: "); + int temp2=sc.nextInt(); + balance-=temp2; + break; + case 4: + System.out.println("Balance in your account is: "+balance); + break; + case 5: + i=1; + System.out.println("Goodbye!! Have a Nice Day...."); + break; + } + } + } + sc.close(); + } +} \ No newline at end of file From aa4c188b7ec46dd866f9316413c3adcbe3b7bd48 Mon Sep 17 00:00:00 2001 From: TEJ-1-8 <127389564+TEJ-1-8@users.noreply.github.com> Date: Tue, 21 Mar 2023 09:23:45 +0530 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 14b0497..7e3f339 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ void compare(int, int) void compare(char, char) void compare(String, String) ``` -4. Program that creates a class Account that stores a variable balance. The class has methods to start account, to deposit money, to withdraw money and tell the current balance amount. +4. Program that creates a class Account that stores a variable balance. The class has methods to start account, to deposit money, to withdraw money and tell the current balance amount. [Temp.java](https://github.com/TEJ-1-8/Java-Programs-1/blob/main/Temp.java) 5. Program to implement a Book class that stores the details of a book such as its code, title and price (Use constructors to initialize the objects). 6. Program to differentiate between static and non-static methods. 7. Program to illustrate the usage of **this**, **final** and **finalize**.