└── Oasis ├── Online Test ├── OnlineTest.class └── OnlineTest.java ├── Library Management System ├── Book.java ├── Member.java ├── Library.java └── Main.java ├── ATM interface ├── Transaction.java ├── Account.java ├── Bank.java ├── User.java └── ATM.java ├── Number Guessing Game └── GFG.java └── Online Reservation System └── online.java /Oasis/Online Test/OnlineTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivaguru-06/Oasis-Infobyte/HEAD/Oasis/Online Test/OnlineTest.class -------------------------------------------------------------------------------- /Oasis/Library Management System/Book.java: -------------------------------------------------------------------------------- 1 | public class Book { 2 | private String title; 3 | private String author; 4 | private String ISBN; 5 | private boolean isBorrowed; 6 | 7 | public Book(String title, String author, String ISBN) { 8 | this.title = title; 9 | this.author = author; 10 | this.ISBN = ISBN; 11 | this.isBorrowed = false; 12 | } 13 | 14 | public String getTitle() { 15 | return title; 16 | } 17 | 18 | public String getAuthor() { 19 | return author; 20 | } 21 | 22 | public String getISBN() { 23 | return ISBN; 24 | } 25 | 26 | public boolean isBorrowed() { 27 | return isBorrowed; 28 | } 29 | 30 | public void borrowBook() { 31 | if (!isBorrowed) { 32 | isBorrowed = true; 33 | } else { 34 | System.out.println("Book is already borrowed."); 35 | } 36 | } 37 | 38 | public void returnBook() { 39 | isBorrowed = false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Oasis/ATM interface/Transaction.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Transaction{ 3 | private double amount;//amount of this trasaction 4 | private Date timestamp;//time and date of this transcation 5 | private String memo;//memo for this transaction 6 | private Account inAccount;//the account in which transaction is performed 7 | 8 | public Transaction(double amount,Account inAccount){ 9 | this.amount = amount; 10 | this.inAccount = inAccount; 11 | this.timestamp = new Date(); 12 | this.memo = ""; 13 | } 14 | public Transaction(double amount,String memo,Account inAccount){ 15 | //call two args constructor first 16 | this(amount,inAccount); 17 | //set the memo 18 | this.memo = memo; 19 | } 20 | public double getAmount(){ 21 | return this.amount; 22 | } 23 | public String getSummaryLine(){ 24 | if(this.amount >= 0){ 25 | return String.format(this.timestamp.toString()+" : $"+this.amount+" : "+this.memo); 26 | }else{ 27 | return String.format(this.timestamp.toString()+" : $("+this.amount+") : "+this.memo); 28 | } 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /Oasis/Library Management System/Member.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class Member { 4 | private String name; 5 | private int memberId; 6 | private ArrayList borrowedBooks; 7 | 8 | public Member(String name, int memberId) { 9 | this.name = name; 10 | this.memberId = memberId; 11 | this.borrowedBooks = new ArrayList<>(); 12 | } 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public int getMemberId() { 19 | return memberId; 20 | } 21 | 22 | public ArrayList getBorrowedBooks() { 23 | return borrowedBooks; 24 | } 25 | 26 | public void borrowBook(Book book) { 27 | if (!book.isBorrowed()) { 28 | borrowedBooks.add(book); 29 | book.borrowBook(); 30 | System.out.println(name + " has borrowed " + book.getTitle()); 31 | } else { 32 | System.out.println("The book is currently unavailable."); 33 | } 34 | } 35 | 36 | public void returnBook(Book book) { 37 | borrowedBooks.remove(book); 38 | book.returnBook(); 39 | System.out.println(name + " has returned " + book.getTitle()); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /Oasis/Number Guessing Game/GFG.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | 4 | public class GFG { 5 | 6 | 7 | public static void 8 | guessingNumberGame() 9 | { 10 | // Scanner Class 11 | Scanner sc = new Scanner(System.in); 12 | 13 | // Generate the numbers 14 | int number = 1 + (int)(100 15 | * Math.random()); 16 | 17 | // Given K trials 18 | int K = 5; 19 | 20 | int i, guess; 21 | 22 | System.out.println( 23 | "A number is chosen" 24 | + " between 1 to 100." 25 | + "Guess the number" 26 | + " within 5 trials."); 27 | 28 | // Iterate over K Trials 29 | for (i = 0; i < K; i++) { 30 | 31 | System.out.println( 32 | "Guess the number:"); 33 | 34 | 35 | guess = sc.nextInt(); 36 | 37 | 38 | if (number == guess) { 39 | System.out.println( 40 | "Congratulations!" 41 | + " You guessed the number."); 42 | break; 43 | } 44 | else if (number > guess 45 | && i != K - 1) { 46 | System.out.println( 47 | "The number is " 48 | + "greater than " + guess); 49 | } 50 | else if (number < guess 51 | && i != K - 1) { 52 | System.out.println( 53 | "The number is" 54 | + " less than " + guess); 55 | } 56 | } 57 | 58 | if (i == K) { 59 | System.out.println( 60 | "You have exhausted" 61 | + " K trials."); 62 | 63 | System.out.println( 64 | "The number was " + number); 65 | } 66 | } 67 | 68 | 69 | public static void 70 | main(String arg[]) 71 | { 72 | 73 | 74 | guessingNumberGame(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Oasis/ATM interface/Account.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | public class Account { 4 | private String name;//The name of account like saving,current etc 5 | // private double balance; //current balance of this account 6 | private String uuid;//account id number 7 | private User holder;//the user object owns this account 8 | private ArrayList transactions;//list of transaction for this account 9 | /** 10 | * @param holder the User object that holds this account 11 | * @param theBank the bank that issues the account 12 | */ 13 | public Account(String name,User holder,Bank theBank){ 14 | //set the account name and holder 15 | this.name = name; 16 | this.holder = holder; 17 | 18 | //get new account UUID 19 | this.uuid = theBank.getNewAccountUUID(); 20 | 21 | //init transactions 22 | this.transactions = new ArrayList(); 23 | 24 | } 25 | public String getUUID(){ 26 | return this.uuid; 27 | } 28 | public String getSummaryLine(){ 29 | //get the account's balance 30 | double balance = this.getBalance(); 31 | //format the summary line, depending on the wheather the balance is negative 32 | if(balance>=0){ 33 | return String.format(this.uuid+" : $"+balance+" : "+this.name); 34 | }else{ 35 | return String.format(this.uuid+" : $"+balance+" : "+this.name); 36 | } 37 | } 38 | public double getBalance(){ 39 | double balance = 0; 40 | for(Transaction t : this.transactions){ 41 | balance += t.getAmount(); 42 | } 43 | return balance; 44 | } 45 | public void printTransHistory(){ 46 | System.out.println("Transaction history for account : "+this.uuid); 47 | for(int t = this.transactions.size()-1;t>=0;t--){ 48 | System.out.println(this.transactions.get(t).getSummaryLine()); 49 | } 50 | System.out.println(); 51 | } 52 | public void addTransaction(double amount,String memo){ 53 | //create new transaction object and add it to our list 54 | Transaction newTrans = new Transaction(amount,memo,this); 55 | this.transactions.add(newTrans); 56 | } 57 | } -------------------------------------------------------------------------------- /Oasis/Library Management System/Library.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class Library { 4 | private ArrayList books; 5 | private ArrayList members; 6 | 7 | public Library() { 8 | books = new ArrayList<>(); 9 | members = new ArrayList<>(); 10 | } 11 | 12 | public void addBook(Book book) { 13 | books.add(book); 14 | System.out.println(book.getTitle() + " added to the library."); 15 | } 16 | 17 | public void removeBook(Book book) { 18 | books.remove(book); 19 | System.out.println(book.getTitle() + " removed from the library."); 20 | } 21 | 22 | public void addMember(Member member) { 23 | members.add(member); 24 | System.out.println("New member added: " + member.getName()); 25 | } 26 | 27 | public void borrowBook(int memberId, String isbn) { 28 | Member member = findMemberById(memberId); 29 | Book book = findBookByISBN(isbn); 30 | 31 | if (member != null && book != null) { 32 | member.borrowBook(book); 33 | } else { 34 | System.out.println("Invalid member ID or book ISBN."); 35 | } 36 | } 37 | 38 | public void returnBook(int memberId, String isbn) { 39 | Member member = findMemberById(memberId); 40 | Book book = findBookByISBN(isbn); 41 | 42 | if (member != null && book != null) { 43 | member.returnBook(book); 44 | } else { 45 | System.out.println("Invalid member ID or book ISBN."); 46 | } 47 | } 48 | 49 | private Book findBookByISBN(String isbn) { 50 | for (Book book : books) { 51 | if (book.getISBN().equals(isbn)) { 52 | return book; 53 | } 54 | } 55 | return null; 56 | } 57 | 58 | private Member findMemberById(int memberId) { 59 | for (Member member : members) { 60 | if (member.getMemberId() == memberId) { 61 | return member; 62 | } 63 | } 64 | return null; 65 | } 66 | 67 | public void displayBooks() { 68 | for (Book book : books) { 69 | System.out.println(book.getTitle() + " by " + book.getAuthor() + " (ISBN: " + book.getISBN() + ")"); 70 | } 71 | } 72 | } 73 | 74 | -------------------------------------------------------------------------------- /Oasis/Library Management System/Main.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Library library = new Library(); 6 | Scanner scanner = new Scanner(System.in); 7 | 8 | // Sample Data 9 | Book book1 = new Book("Harry Potter", "J.K. Rowling", "12345"); 10 | Book book2 = new Book("The Hobbit", "J.R.R. Tolkien", "67890"); 11 | 12 | Member member1 = new Member("John Doe", 1); 13 | Member member2 = new Member("Jane Doe", 2); 14 | 15 | library.addBook(book1); 16 | library.addBook(book2); 17 | library.addMember(member1); 18 | library.addMember(member2); 19 | 20 | // Menu-based interaction 21 | while (true) { 22 | System.out.println("\nLibrary Management System:"); 23 | System.out.println("1. Display Books"); 24 | System.out.println("2. Borrow Book"); 25 | System.out.println("3. Return Book"); 26 | System.out.println("4. Exit"); 27 | 28 | System.out.println("Enter the Choice: "); 29 | 30 | int choice = scanner.nextInt(); 31 | switch (choice) { 32 | case 1: 33 | library.displayBooks(); 34 | break; 35 | case 2: 36 | System.out.println("Enter member ID:"); 37 | int memberId = scanner.nextInt(); 38 | System.out.println("Enter book ISBN:"); 39 | String isbn = scanner.next(); 40 | library.borrowBook(memberId, isbn); 41 | break; 42 | case 3: 43 | System.out.println("Enter member ID:"); 44 | memberId = scanner.nextInt(); 45 | System.out.println("Enter book ISBN:"); 46 | isbn = scanner.next(); 47 | library.returnBook(memberId, isbn); 48 | break; 49 | case 4: 50 | System.out.println("Exiting..."); 51 | scanner.close(); 52 | System.exit(0); 53 | break; 54 | default: 55 | System.out.println("Invalid choice."); 56 | } 57 | } 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /Oasis/ATM interface/Bank.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Bank{ 3 | private String name; 4 | private ArrayList users; 5 | private ArrayList accounts; 6 | 7 | public Bank(String name){ 8 | this.name = name; 9 | this.users = new ArrayList(); 10 | this.accounts = new ArrayList(); 11 | } 12 | 13 | public String getNewUserUUID(){ 14 | //inits 15 | String uuid; 16 | Random rng = new Random(); 17 | int len = 6; 18 | boolean nonUnique; 19 | //continue looping until we get a unique ID 20 | do{ 21 | //genrate number 22 | uuid=""; 23 | for(int i = 0;iaccounts;//list of accounts for this user 10 | /** 11 | * Create a new user 12 | * @param firstName - user's first name 13 | * @parm lastName - user's last name 14 | * @param pin - the user's account pin 15 | * @param theBank - the Bank object that user is customer of 16 | */ 17 | 18 | public User(String firstName,String lastName,String pin,Bank theBank){ 19 | //set the user name 20 | this.firstName = firstName; 21 | this.lastName = lastName; 22 | 23 | //store the pin's MD5 hash, rather than original value for security purpose 24 | try{ 25 | MessageDigest md = MessageDigest.getInstance("MD5"); 26 | this.pinHash = md.digest(pin.getBytes()); 27 | }catch(NoSuchAlgorithmException e){ 28 | System.err.println("error,caught NoSuchAlgorithmException"); 29 | e.printStackTrace(); 30 | System.exit(1); 31 | } 32 | 33 | // get a new, unique universal ID for user 34 | this.uuid = theBank.getNewUserUUID(); 35 | 36 | //create emptylist of accounts 37 | this.accounts = new ArrayList(); 38 | 39 | //Print log message 40 | System.out.println("New User : "+firstName+" "+lastName+" with ID : "+this.uuid+" created"); 41 | } 42 | /** 43 | * @param anAct the account to add 44 | */ 45 | public void addAccount(Account anAct){ 46 | this.accounts.add(anAct); 47 | } 48 | /** 49 | * return's the user's uuid 50 | */ 51 | public String getUUID(){ 52 | return this.uuid; 53 | } 54 | public boolean validatePin(String aPin){ 55 | try{ 56 | MessageDigest md = MessageDigest.getInstance("MD5"); 57 | return MessageDigest.isEqual(md.digest(aPin.getBytes()),this.pinHash); 58 | }catch(NoSuchAlgorithmException e){ 59 | System.err.println("error,caught NoSuchAlgorithmException"); 60 | e.printStackTrace(); 61 | System.exit(1); 62 | } 63 | return false; 64 | } 65 | 66 | public String getFirstName(){ 67 | return this.firstName; 68 | } 69 | 70 | public void printAccountSummary(){ 71 | System.out.println(this.firstName+"'s account Summary :"); 72 | for(int a = 0;a reservations = new ArrayList<>(); 37 | private int nextId = 1; 38 | 39 | public Reservation makeReservation(String name, String date, int numberOfGuests) { 40 | Reservation reservation = new Reservation(nextId++, name, date, numberOfGuests); 41 | reservations.add(reservation); 42 | return reservation; 43 | } 44 | 45 | public List getReservations() { 46 | return reservations; 47 | } 48 | 49 | public Reservation getReservationById(int id) { 50 | for (Reservation reservation : reservations) { 51 | if (reservation.getId() == id) { 52 | return reservation; 53 | } 54 | } 55 | return null; 56 | } 57 | 58 | public boolean cancelReservation(int id) { 59 | Reservation reservation = getReservationById(id); 60 | if (reservation != null) { 61 | reservations.remove(reservation); 62 | return true; 63 | } 64 | return false; 65 | } 66 | } 67 | 68 | 69 | class ReservationSystemUI { 70 | private ReservationSystem reservationSystem = new ReservationSystem(); 71 | 72 | public void start() { 73 | Scanner scanner = new Scanner(System.in); 74 | 75 | while (true) { 76 | System.out.println("1. Make a reservation"); 77 | System.out.println("2. View all reservations"); 78 | System.out.println("3. Cancel a reservation"); 79 | System.out.println("4. Exit"); 80 | 81 | int choice = scanner.nextInt(); 82 | scanner.nextLine(); 83 | 84 | switch (choice) { 85 | case 1: 86 | System.out.print("Name: "); 87 | String name = scanner.nextLine(); 88 | System.out.print("Date: "); 89 | String date = scanner.nextLine(); 90 | System.out.print("Number of guests: "); 91 | int numberOfGuests = scanner.nextInt(); 92 | scanner.nextLine(); 93 | 94 | Reservation reservation = reservationSystem.makeReservation(name, date, numberOfGuests); 95 | System.out.println("Reservation made with ID " + reservation.getId()); 96 | break; 97 | case 2: 98 | System.out.println("Reservations:"); 99 | for (Reservation r : reservationSystem.getReservations()) { 100 | System.out.println(r.getId() + " - " + r.getName() + " - " + r.getDate() + " - " + r.getNumberOfGuests()); 101 | } 102 | break; 103 | case 3: 104 | System.out.print("Reservation ID to cancel: "); 105 | int id = scanner.nextInt(); 106 | scanner.nextLine(); 107 | 108 | if (reservationSystem.cancelReservation(id)) { 109 | System.out.println("Reservation canceled"); 110 | } else { 111 | System.out.println("Reservation not found"); 112 | } 113 | break; 114 | case 4: 115 | return; 116 | default: 117 | System.out.println("Invalid choice"); 118 | } 119 | 120 | System.out.println(); 121 | } 122 | } 123 | 124 | public static void main(String[] args) 125 | { 126 | ReservationSystemUI obj = new ReservationSystemUI(); 127 | obj.start(); 128 | } 129 | } 130 | 131 | -------------------------------------------------------------------------------- /Oasis/Online Test/OnlineTest.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.awt.event.*; 3 | import javax.swing.*; 4 | 5 | class OnlineTest extends JFrame implements ActionListener 6 | { 7 | JLabel l; 8 | JRadioButton jb[]=new JRadioButton[5]; 9 | JButton b1,b2; 10 | ButtonGroup bg; 11 | int count=0,current=0,x=1,y=1,now=0; 12 | int m[]=new int[10]; 13 | OnlineTest(String s) 14 | { 15 | super(s); 16 | l=new JLabel(); 17 | add(l); 18 | bg=new ButtonGroup(); 19 | for(int i=0;i<5;i++) 20 | { 21 | jb[i]=new JRadioButton(); 22 | add(jb[i]); 23 | bg.add(jb[i]); 24 | } 25 | b1=new JButton("Next"); 26 | b2=new JButton("Bookmark"); 27 | b1.addActionListener(this); 28 | b2.addActionListener(this); 29 | add(b1);add(b2); 30 | set(); 31 | l.setBounds(30,40,450,20); 32 | jb[0].setBounds(50,80,100,20); 33 | jb[1].setBounds(50,110,100,20); 34 | jb[2].setBounds(50,140,100,20); 35 | jb[3].setBounds(50,170,100,20); 36 | b1.setBounds(100,240,100,30); 37 | b2.setBounds(270,240,100,30); 38 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 39 | setLayout(null); 40 | setLocation(250,100); 41 | setVisible(true); 42 | setSize(600,350); 43 | } 44 | public void actionPerformed(ActionEvent e) 45 | { 46 | if(e.getSource()==b1) 47 | { 48 | if(check()) 49 | count=count+1; 50 | current++; 51 | set(); 52 | if(current==9) 53 | { 54 | b1.setEnabled(false); 55 | b2.setText("Result"); 56 | } 57 | } 58 | if(e.getActionCommand().equals("Bookmark")) 59 | { 60 | JButton bk=new JButton("Bookmark"+x); 61 | bk.setBounds(480,20+30*x,100,30); 62 | add(bk); 63 | bk.addActionListener(this); 64 | m[x]=current; 65 | x++; 66 | current++; 67 | set(); 68 | if(current==9) 69 | b2.setText("Result"); 70 | setVisible(false); 71 | setVisible(true); 72 | } 73 | for(int i=0,y=1;iShow Transaction History"); 57 | System.out.println("2>withdraw"); 58 | System.out.println("3>Deposite"); 59 | System.out.println("4>Transfer"); 60 | System.out.println("5>Quit"); 61 | System.out.println(); 62 | System.out.println("Enter Your Choice : "); 63 | choice = sc.nextInt(); 64 | if(choice<1 || choice>5){ 65 | System.out.println("Invalid Choice"+" Please choose between 1-5 "); 66 | } 67 | }while(choice<1 || choice>5); 68 | //process the choice 69 | switch(choice){ 70 | case 1: 71 | ATM.showTransactionHistory(theUser,sc); 72 | break; 73 | case 2: 74 | ATM.withdrawFunds(theUser,sc); 75 | break; 76 | case 3: 77 | ATM.depositeFunds(theUser,sc); 78 | break; 79 | case 4: 80 | ATM.transferFunds(theUser,sc); 81 | break; 82 | case 5: 83 | //gobble up rest of previous input 84 | sc.nextLine(); 85 | break; 86 | } 87 | //redisplay this menu unless user quit 88 | if(choice != 5){ 89 | ATM.printUserMenu(theUser,sc); 90 | } 91 | } 92 | public static void showTransactionHistory(User theUser,Scanner sc){ 93 | int theAct; 94 | //get account whose history to look at 95 | do{ 96 | System.out.printf("Enter the number (1-%d) of the account\n"+" whose transaction you waant to see : ",theUser.numAccounts()); 97 | theAct = sc.nextInt()-1; 98 | if(theAct < 0 || theAct >= theUser.numAccounts()){ 99 | System.out.println("Invalid account. please try again....."); 100 | } 101 | }while(theAct < 0 || theAct >= theUser.numAccounts()); 102 | //Print transaction history 103 | 104 | theUser.printActTransHistory(theAct); 105 | } 106 | public static void transferFunds(User theUser,Scanner sc){ 107 | //intits 108 | int fromAct; 109 | int toAct; 110 | double amount; 111 | double actBal; 112 | //get the account to transfer from 113 | do{ 114 | System.out.printf("Enter the number (1-%d) of the account\n"+"to transfer from:",theUser.numAccounts()); 115 | fromAct = sc.nextInt()-1; 116 | if(fromAct < 0 || fromAct >= theUser.numAccounts()){ 117 | System.out.println("Invalid account. please try again....."); 118 | } 119 | }while(fromAct < 0 || fromAct >= theUser.numAccounts()); 120 | actBal = theUser.getAccountBalance(fromAct); 121 | 122 | //get the account to transfer to 123 | do{ 124 | System.out.printf("Enter the number (1-%d) of the account\n"+"to transfer to:",theUser.numAccounts()); 125 | toAct = sc.nextInt()-1; 126 | if(toAct < 0 || toAct >= theUser.numAccounts()){ 127 | System.out.println("Invalid account. please try again....."); 128 | } 129 | }while(toAct < 0 || toAct >= theUser.numAccounts()); 130 | //get the amount to traansfer 131 | do{ 132 | System.out.println("Enter the amount to transfer (max than $"+actBal+") : $"); 133 | amount = sc.nextDouble(); 134 | if(amount < 0){ 135 | System.out.println("Amount must be greater than zero"); 136 | }else if(amount > actBal){ 137 | System.out.println("Amount must not be greater than \n"+"balance of $"+actBal); 138 | } 139 | }while(amount < 0 || amount>actBal); 140 | //do the transfer 141 | theUser.addActTransaction(fromAct,-1*amount,String.format("Transfer to account "+theUser.getActUUID(toAct))); 142 | theUser.addActTransaction(toAct,amount,String.format("Transfer to account "+theUser.getActUUID(fromAct))); 143 | } 144 | public static void withdrawFunds(User theUser,Scanner sc){ 145 | int fromAct; 146 | String memo; 147 | double amount; 148 | double actBal; 149 | //get the account to transfer from 150 | do{ 151 | System.out.printf("Enter the number (1-%d) of the account\n"+"Where to withdraw :",theUser.numAccounts()); 152 | fromAct = sc.nextInt()-1; 153 | if(fromAct < 0 || fromAct >= theUser.numAccounts()){ 154 | System.out.println("Invalid account. please try again....."); 155 | } 156 | }while(fromAct < 0 || fromAct >= theUser.numAccounts()); 157 | actBal = theUser.getAccountBalance(fromAct); 158 | //get the amount to traansfer 159 | do{ 160 | System.out.println("Enter the amount to withdraw (max $ "+actBal+"): $"); 161 | amount = sc.nextDouble(); 162 | if(amount < 0){ 163 | System.out.println("Amount must be greater than zero"); 164 | }else if(amount > actBal){ 165 | System.out.println("Amount must not be greater than \n"+"balance of $"+actBal); 166 | } 167 | }while(amount < 0 || amount>actBal); 168 | //gobble up rest of previous input 169 | sc.nextLine(); 170 | //get a memo 171 | System.out.println("Enter a memo: "); 172 | memo = sc.nextLine(); 173 | //do withdrawal 174 | theUser.addActTransaction(fromAct,-1*amount,memo); 175 | } 176 | public static void depositeFunds(User theUser,Scanner sc){ 177 | int toAct; 178 | String memo; 179 | double amount; 180 | double actBal; 181 | //get the account to transfer from 182 | do{ 183 | System.out.printf("Enter the number (1-%d) of the account\n"+"Where to Deposite:",theUser.numAccounts()); 184 | toAct = sc.nextInt()-1; 185 | if(toAct < 0 || toAct >= theUser.numAccounts()){ 186 | System.out.println("Invalid account. please try again....."); 187 | } 188 | }while(toAct < 0 || toAct >= theUser.numAccounts()); 189 | actBal = theUser.getAccountBalance(toAct); 190 | //get the amount to transfer 191 | do{ 192 | System.out.print("Enter the amount to deposite (max than $"+actBal+") :$"); 193 | amount = sc.nextDouble(); 194 | if(amount < 0){ 195 | System.out.println("Amount must be greater than zero"); 196 | } 197 | }while(amount < 0 ); 198 | //gobble up rest of previous input 199 | sc.nextLine(); 200 | //get a memo 201 | System.out.println("Enter a memo: "); 202 | memo = sc.nextLine(); 203 | //do withdrawal 204 | theUser.addActTransaction(toAct,amount,memo); 205 | } 206 | } --------------------------------------------------------------------------------