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

Assignment1_Shubham #13

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

public class Account {
static {
cnt = 0;
}

private static int cnt;
private int perId;
private String pName;
private String typeOfAcc;
private Date dOp;
private double balance;

//default constructor
public Account() {
perId = 0;
pName = null;
typeOfAcc = null;
dOp = null;

}

//parameterized constructor
public Account(String pName, String typeOfAcc, Date dOp, double bal) {
this.perId = cnt++ ;
this.pName = pName;
this.typeOfAcc = typeOfAcc;
this.dOp = dOp;
this.balance = bal;
}
//setter and getter methods
public int getId() {
return this.perId;
}
public void setId(int perId) {
this.perId = perId;
}
public void setBal (double bal) {
this.balance = bal;
}
public double getBal() {
return this.balance;
}
public String getpName() {
return this.pName;
}
public void setpName(String pName) {
this.pName = pName;
}

//Deposit function
public void deposit(double amt) {
balance = balance + amt;
}

//Withdraw function
public void withdraw(double amt) {
if(balance-10000 >= amt) {
balance = balance - amt;
}
else {
System.out.println("Insufficient Balance");
}
}

@Override
public String toString() {
return "Id: "+perId +"\nName: " +pName + "\nType of account:"+ typeOfAcc + "\nDate of opening :"+ dOp+"\nbalance: "+balance;
}
}
96 changes: 96 additions & 0 deletions Assignment1/src/com/demo/service/AccountService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.demo.service;

import java.util.Scanner;
import com.demo.bean.Account;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

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

// Accept Account Method
public static void acceptAccountData(Account[] acc) {
for (int i = 0; i < acc.length; i++) {
System.out.println("Enter account holder's name: ");
String name = sc.next();
System.out.println("Enter type of account: ");
String acctype = sc.next();
System.out.println("Enter balance: ");
double bal = sc.nextDouble();
Date dOp = new Date();
acc[i] = new Account(name, acctype, dOp, bal);
}

}

//Search by ID Method
public static int searchById(Account[] acc, int id) {
for (int i = 0; i < acc.length; i++) {
if (acc[i].getId() == id) {
return i;
}
}
return -1;
}

//Deposit Amount method
public static int depositAmt(Account[] acc, int id, double amt) {
int pos = searchById(acc, id);
if (pos != -1) {
pos=pos+1;
acc[pos].deposit(amt);
System.out.println("New balance:" + acc[pos].getBal());
return pos;
} else {
System.out.println("person not found");
return -1;
}
}

//Withdraw Method
public static int withdrawAmt(Account[] acc, int id, double amt) {

int pos = searchById(acc, id);
if (pos != -1) {
acc[pos].withdraw(amt);
System.out.println("New balance:" + acc[pos].getBal());
return pos;
} else {
System.out.println("person not found");
return -1;
}

}

//Display Data
public static void displayData(Account[] acc) {
for (int i = 0; i < acc.length; i++) {
if (acc[i] != null) {
System.out.println(acc[i]);
} else {
break;
}
}
}

//Search by Name
public static int searchByName(Account[] a, String nm) {
for (int i = 0; i < a.length; i++) {
if (a[i].getpName().equals(nm)) {
return i;
}
}
return -1;
}

// Show Data by ID
public static void dispById(Account[] a, int id) {
int pos = searchById(a, id);
if (pos != -1) {
System.out.println(a[pos]);
} else {
System.out.println("Account not found");
}
}
}
63 changes: 63 additions & 0 deletions Assignment1/src/com/demo/test/TestAccountClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.demo.test;

import com.demo.bean.Account;
import com.demo.service.AccountService;
import java.util.Scanner;

public class TestAccountClass {

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

//Main Menu with options
do {
System.out.println("1. New Account : \n2. Search Account by ID : \n3. Deposit : \n4. Withdraw : \n5. Search Account by Name : \n6. Exit");
choice = sc.nextInt();
switch (choice) {
case 1:
AccountService.acceptAccountData(a);
break;
case 2:
System.out.println("Enter ID name ");
int id = sc.nextInt();
int pos = AccountService.searchById(a, id);
if (pos != -1) {
System.out.println(a[pos]);
} else {
System.out.println("No such ID found");
}
break;
case 3:
System.out.println("Deposit Amount : ");
double damt = sc.nextDouble();
System.out.println("Enter the Account ID: ");
int dId = sc.nextInt();
AccountService.depositAmt(a, dId, damt);
break;
case 4:
System.out.println("Withdraw Amount: ");
double wAmt = sc.nextDouble();
System.out.println("Enter the Account ID: ");
int wId = sc.nextInt();
AccountService.withdrawAmt(a, wId, wAmt);
break;
case 5:
System.out.println("Enter Name");
String nm = sc.next();
int posn = AccountService.searchByName(a, nm);
if (posn != -1) {
System.out.println(a[posn]);
} else {
System.out.println("Person Not Found");
}
break;
case 6:
System.exit(0);
}
} while (choice != 6);
sc.close();
}

}
6 changes: 6 additions & 0 deletions Practical_Exam_Shubham_Tapele_WPS4/.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 Practical_Exam_Shubham_Tapele_WPS4/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>PracticalExam</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>
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.
64 changes: 64 additions & 0 deletions Practical_Exam_Shubham_Tapele_WPS4/src/com/demo/bean/Apparel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//Shubham Ramesh Tapele
//Apparel Class which extends Item Class and Stores Apparel Specific Variables

package com.demo.bean;

public class Apparel extends Item{
private String size;
private String material;
private int qnty;

//default constructor
public Apparel() {
super();
}

//parameterised Constructor
public Apparel(String size, String material, int qnty, int itemCode, String itemName, double price) {
super();
this.size = size;
this.material = material;
this.qnty = qnty;
}

//Getter and Setter Methods
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public String getMaterial() {
return material;
}
public void setMaterial(String material) {
this.material = material;
}
public int getQnty() {
return qnty;
}
public void setQnty(int qnty) {
this.qnty = qnty;
}


@Override
public String toString() {
return "Apparel [size=" + size + ", material=" + material + ", qnty=" + qnty + "]";
}
//compare function to sort by qnty
public int compareTo(Apparel ob) {
System.out.println("In person compareTo"+qnty+"----"+ob.qnty);
if(this.qnty>ob.qnty) {
return -1;
}else if(this.qnty==ob.qnty) {
return 0;
}
else {
return 1;
}
}



}
Loading