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

Assignments by Abhijeet Raut #5

Open
wants to merge 7 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 AccountAssignment01/.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 AccountAssignment01/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AccountAssignment01</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 AccountAssignment01/.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.
85 changes: 85 additions & 0 deletions AccountAssignment01/src/com/demo/bean/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.demo.bean;
import java.util.Date;

public class Account {
private int id;
private String name;
private String accountType;
private double balance;
private Date dateOfJoining;

//Default Constructor
public Account() {
id = 0;
name = null;
accountType = null;
balance = 0;
dateOfJoining = null;
}

//Parameterized Constructor
public Account(int id, String name, String accountType, double balance, Date dateOfJoining) {
this.id = id;
this.name = name;
this.accountType = accountType;
this.balance = balance;
this.dateOfJoining = dateOfJoining;
}

//Method to deposite amount
public void deposit(double amount) {
this.balance = this.balance + amount;

}

//Method to withdraw amount
public int withdraw(double amount) {
if(this.balance-10000 >= amount) {
this.balance = this.balance - amount;
return 1;
}
return -1;
}

//Setters and Getters Methods
public void setId(int id) {
this.id = id;
}

public void setName(String name) {
this.name = name;
}

public void setAccountType(String accountType) {
this.accountType = accountType;
}

public void setBalance(double balance) {
this.balance = balance;
}

public int getId() {
return this.id;
}

public String getName() {
return this.name;
}

public String getAccountType() {
return this.accountType;
}

public double getBalance() {
return this.balance;
}

public Date getDateOfJoining() {
return this.dateOfJoining;
}

//Method to display object
public String toString() {
return "Id : " + id + "\nName : " + name + "\nAccount Type : " + accountType + "\nBalance : " + balance + "\nDate of Joining :" + dateOfJoining;
}
}
78 changes: 78 additions & 0 deletions AccountAssignment01/src/com/demo/service/AccountService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.demo.service;
import java.text.ParseException;
import java.math.*;
import java.lang.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

import com.demo.bean.Account;

public class AccountService {

public static Scanner sc = new Scanner(System.in);
public static SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

//Accept data and create accounts
public static void acceptAccountData(Account[] acc) {
for(int i=0;i<acc.length;i++) {
System.out.println("Enter Id :");
int id = sc.nextInt();
System.out.println("Enter Name :");
String name = sc.next();
System.out.println("Enter Account Type :");
String accountType = sc.next();
System.out.println("Enter Balance :");
double balance = sc.nextDouble();
System.out.println("Enter Date :");
String doj= sc.next();
try {
Date dateOfJoining = sdf.parse(doj);
acc[i] = new Account(id, name, accountType, balance, dateOfJoining);
} catch (ParseException e) {
e.printStackTrace();
}
}
}

//Display the account information by Id
public static void displayAccountData(Account[] acc, int id) {
for(int i=0;i<acc.length;i++) {
if(acc[i].getId() == id) {
System.out.println(acc[i]);
}
}
}

//Withdraw amount from account
public static int withdrawAmount(int id, double amount, Account[] acc) {
int pos = AccountService.searchAccountById(acc, id);
if(pos != -1) {
int result = acc[pos].withdraw(amount);
if(result != -1)
return 1;
}
return -1;
}

//Deposite amount into account
public static int depositAmount(int id, double amount, Account[] acc) {
int pos = AccountService.searchAccountById(acc, id);
if(pos != -1) {
acc[pos].deposit(amount);
return pos;
}
return -1;
}

//Search account by Id
private static int searchAccountById(Account[] acc, int id) {
for(int i=0;i<acc.length;i++) {
if(acc[i].getId() == id) {
return i;
}
}
return -1;
}

}
69 changes: 69 additions & 0 deletions AccountAssignment01/src/com/demo/test/TestAccountClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.demo.test;
import java.util.Scanner;

import com.demo.bean.Account;
import com.demo.service.AccountService;

public class TestAccountClass {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Account[] acc = new Account[2];
int choice = 0;

//Menu to be displayed
do {
System.out.println("1. Create new accounts");
System.out.println("2. Withdraw amount");
System.out.println("3. Make a deposit");
System.out.println("4. Display accounts");
System.out.println("5. Exit");
System.out.println("Enter your choice");

choice = sc.nextInt();
int id = 0;
double amount = 0;
switch(choice) {
case 1:
AccountService.acceptAccountData(acc);
System.out.println("Accounts created");
break;
case 2:
System.out.println("Enter Id:");
id = sc.nextInt();
System.out.println("Enter the amount");
amount = sc.nextDouble();
int result = AccountService.withdrawAmount(id, amount, acc);
if(result != -1) {
System.out.println("Successfully withdrawal");
}
else {
System.out.println("Failed to withdraw");
}
break;
case 3:
System.out.println("Enter Id");
id = sc.nextInt();
System.out.println("Enter the amount");
amount = sc.nextDouble();
result = AccountService.depositAmount(id, amount, acc);
if(result != -1) {
System.out.println("Deposit Successful");
}
else {
System.out.println("Deposit failed");
}
break;
case 4:
System.out.println("Enter Id");
id = sc.nextInt();
AccountService.displayAccountData(acc, id);
break;
case 5:
System.exit(0);
}
}while(choice != 5);

}

}
6 changes: 6 additions & 0 deletions AccountAssignment02/.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 AccountAssignment02/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>AccountAssignment02</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 AccountAssignment02/.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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading