Skip to content
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

Assignment 1 (submitting again) #22

Open
wants to merge 9 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
6 changes: 6 additions & 0 deletions Assignment1/MyAccount/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions Assignment1/MyAccount/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MyAccount</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions Assignment1/MyAccount/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
Binary file not shown.
Binary file not shown.
Binary file not shown.
82 changes: 82 additions & 0 deletions Assignment1/MyAccount/src/com/demo/bean/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.demo.bean;

import java.util.Date;

public class Account {
static {
cnt = 0;
}
public static int cnt; //for auto generating member id
private int memId;
private String memName;
private Date openDate;
private String accType;
private double balance;

//Default constructor
public Account() {
memId = ++cnt;
memName = null;
openDate = null;
accType = null;
balance = 0.0;
}

//Parameterized constructor
public Account(String memName, Date openDate, String accType, double balance) {
this.memId = ++cnt;
this.memName = memName;
this.openDate = openDate;
this.accType = accType;
this.balance = balance;
}

//setter and getter methods
public int getId() {
return this.memId;
}
public void setMemName(String name) {
this.memName = name;
}
public String getMemName() {
return this.memName;
}
public void setOpenDate(Date dt) {
this.openDate = dt;
}
public Date getOpenDate() {
return this.openDate;
}
public void setAccType(String type) {
this.accType = type;
}
public String getAccType() {
return this.accType;
}
public void setBalance(double bal) {
this.balance = bal;
}
public double getBalance() {
return this.balance;
}

//Overriding toString() of Object Class to print details
@Override
public String toString() {
return "Member id : " + memId + "\nMember name : " + memName + "\nAccount openeing date : " + openDate + "\nAccount Type : " + accType + "\nBalance : " + balance;
}

//Withdrawal of amount from a particular amount
public void withdraw(double amt) {
if(balance - 10000 >= amt)
balance = balance - amt;
else
System.out.println("Not enough balance!!");
}


//Deposit of amount to a particular account
public void deposit(double amt) {
balance = balance + amt;
}
}
66 changes: 66 additions & 0 deletions Assignment1/MyAccount/src/com/demo/service/AccountService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.demo.service;
import com.demo.bean.*;
import java.util.Scanner;
//import java.text.ParseException;
//import java.text.SimpleDateFormat;
import java.util.Date;

public class AccountService {
public static Scanner sc = new Scanner(System.in);

//accept data for n customers
public static void acceptMemberData(Account at[]) {
for(int i = 0; i < at.length; i++) {
System.out.println("Enter member name : ");
String nm = sc.next();
System.out.println("Enter account type : ");
String tp = sc.next();
System.out.println("Enter balance : ");
double bal = sc.nextDouble();
at[i] = new Account(nm, new Date(), tp, bal);
}
}

//withdrawal of amount from a particular account
public static void withdrawAmount(Account at[], int id, double bal) {
int index = searchById(at, id);
if(index != -1) {
at[index].withdraw(bal);
System.out.println("Withdraw Successful!!");
}
else
System.out.println("Account not found!!");
}

//deposit amount to a particular amount
public static void depositAmount(Account at[], int id, double bal) {
int index = searchById(at, id);
if(index != -1) {
at[index].deposit(bal);
System.out.println("Deposit Successful!!");
}
else
System.out.println("Account not found!!");
}


//display data of a particular account
public static void displayMemberData(Account at[], int id) {
int index = searchById(at, id);
if(index != -1)
System.out.println("Details : \n" + at[index]);
else
System.out.println("Account not found!!");
}

//search a particular account by member id
public static int searchById(Account at[], int id) {
// for loop returns the position of the requested account in the Account array
for(int i = 0; i < at.length; i++) {
if(at[i].getId() == id)
return i;
}
return -1;
}
}

41 changes: 41 additions & 0 deletions Assignment1/MyAccount/src/com/demo/test/TestAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.demo.test;

import com.demo.bean.*;
import com.demo.service.*;
import java.util.Scanner;

public class TestAccount {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
Account[] at = new Account[10];
int choice;
do {
System.out.print("MENU\nEnter the option :\n(1) to create new accounts\n(2) to withdraw amount\n(3) to deposit amount\n(4) to display details\n(5) to exit. \nEnter choice : ");
choice = sc.nextInt();
switch(choice) {
case 1 : AccountService.acceptMemberData(at);
break;
case 2 : System.out.println("Enter member id : ");
int id = sc.nextInt();
System.out.println("Enter balance to be withdrawn : ");
double bal = sc.nextDouble();
AccountService.withdrawAmount(at, id, bal);
break;
case 3 : System.out.println("Enter member id : ");
id = sc.nextInt();
System.out.println("Enter balance to be deposited : ");
bal = sc.nextDouble();
AccountService.depositAmount(at, id, bal);
break;
case 4 : System.out.println("Enter member id : ");
id = sc.nextInt();
AccountService.displayMemberData(at, id);
break;
case 5 : System.exit(0);
break;
default : System.out.println("Wrong choice!!");
}
}while(choice != '5');
sc.close();
}
}