1. Create a bank file with at least 10 records that include an id#, balance, and last name 2. Create another file that will read these records and then create an array of Bank Account objects 3. Create checkboxes that allow the user to select how they want the data sorted 4. List the total number of accounts at the bottom of the GUI
I've created the file no problem that actually writes the ten records. I was able to have the files be read sequentially with System.out.println(), but I can't figure out how to convert these into an array of Bank Account objects and have them show up in a scroll pane. I tried using string builder and array builder, but I couldn't figure out how to turn them into components. I then tried making an Account class to have them be sorted with comparators, but I had the same problem of actually getting them into the scroll pane. Also, as soon as I added in those methods for the GUI, the while loop wouldn't display the array information in system.out.println. Here is my code for the GUI that doesn't display anything with println ...
I'm working on this weeks assignment and I've gotten stuck on passing information from one class to another. We are working with abstract classes this week, and the BankAccount class is the Abstract class that is extended by the CheckingAccount and the SavingsAccount classes. The Bank class is where the user inputs his/her information to process the commands. How can I work this to where the instructions are passed from the main in the Bank class to the different Account classes to actually perform the instructions?
BankAccount:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
package bankaccount; abstract class BankAccount { private final BankAccount acctID; private int acctBalance = 0; public BankAccount checking; public BankAccount savings;
[Code] ....
I can attach a PDF of the instructions if that will provide additional insight to this. I'm sure I'll ask additional questions as we go, but I'm trying to get this to work right and figure out what I'm doing wrong.
public class BankAccount { String name; int accountID; double balance; } public void setAcct ( String nam, double acctID)
[Code] ....
1. Create a class called BankAccount a. It will be a generic simple type of BankAccount
2. BankAccount will contain variables to store: a. the owner/owners of the account b. an account id c. it may contain other basic information (up to you)
3. BankAccount will contain methods that will allow you to: a. Set the account owners information b. Deposit money c. Withdraw money d. Set balances e. Print out transactions (think more like an atm each time an action is taken it gets printed)
4. BankAccount will contain its own main() a. At least 2 BankAccount objects will be created and ALL of their methods called .
When I try to print out the account Id for each account object, the id is always 1. But it should be 1,2,3,4,5....all the way to the number of the account generated.My question is am I missing something in the constructor or in the main method?? I am new to programming.The main method create an array of account objects and generate random balances into each account object.
import java.util.Scanner; public class Bank { public static void main(String[] args) { Scanner userInput=new Scanner(System.in); System.out.print("Enter the number of accounts to generate: "); int numOfAccount=userInput.nextInt();
Develop the class “Account” to be used by a bank. The Account class should have a single instance variable “balance”. Remember that balance must be a floating point number. The required methods for the Account class are shown below.
The Account class “debit” method should return a Boolean and should not allow an overdraft. If a withdraw greater than the current balance is attempted, the function should immediately return “false” and do nothing else.
Develop a test class to thoroughly test all aspects of the Account class. DO NOT change the class name or instance variable name given or the required method names as detailed below.
Account 1 constructor with no parameters (default balance to 0) 1 constructor with a balance parameter setBalance method getBalance method credit method debit method
I have the test class done, I won't need to put that in till later. My main problem is I'm not sure how I'm going to be able to get debit and setBalance to work together with each other.
public class Account { protected double balance; // Constructor to initialize balance public Account( double amount ) { balance = amount;
[Code] ....
You can see I'm stressed out by not reading over my code. I already have the "Debit" in use, just have to change it. Which I did.
So the assignment is as follows. Develop a new class called BankAccount. A bank account has the owner's name and balance. Be sure to include a constructor that allows the client to supply the owner's name and initial balance. A bank account needs - accessors for the name and balance, mutators for making deposits and withdrawals. I have the following code :
import java.util.Scanner; public class BankAccount{ public static void main(String [] args){ Scanner reader = new Scanner(System.in); double name; double balance; double deposit; double withdrawl;
[Code] ....
I am having trouble with my if statements. I don't know how to link the number 1 & 2 keys to deposit and withdrawal actions. Plus I am supposed to have a while loop yet don't know how to implement this so that the while loop will ask the user if they would like to make another transaction after either depositing or withdrawing.
The first is clear , new Person().printPerson(); displays Person but for the second : new Student().printPerson(); it accesses the Student constructor that points to the Person class => object. It builds the Person instance then goes back to the Student constuctor .Both methods are private and to my knowledge invisible one to the other , except that you cant run the the Person one because it's private so the only one in the Student class is the Student one . Guess it 's incorrect , but why ? (is because private methods cant be overriden and somehow the super class one always has priority ? , even if it's private?)
public class Test { public static void main(String[] args) { new Person().printPerson(); new Student().printPerson();
So I'm just a little unclear about this, but how would I call methods from the 'top' of an inheritance chain? I say 'top' because Object is the top... E.g.:
public class AClass { public void myMethod() { ... } } public class BClass extends AClass { public void myMethod() { ... } } public class CClass extends AClass { public void myMethod() { ... } }
Assuming that BClass.myMethod() completely overrides AClass.myMethod() (so that there is no call to super.myMethod() in BClass.myMethod()) How can I call AClass.myMethod() from CClass.myMethod()?
I've an interface with generic methods in it. I would like to have specialized methods in the sub types. While doing that I'm seeing the following warnings in eclipse.
class Sorter { <E> void sort(E[] elements); };
class StringSorter {
// This gives me a warning 'hiding' to 'sort' <String> void sort(String[] elements) { }
// Gives me an error "The method someCrap(String[]) in the type StringSorter is not applicable for the arguments (String[])" void someCrap(String[] elements) { } };
I would like to understand why eclipse gives the above warnings and errors.
How to write a driver program, this my code I have :
import java.util.Date; public class myAccount { public static void main(String[] args) { //create an instance object of class Stock Account myAccount = new Account(012233445566, 20000.00, 0.045);
I am going through Thinking in Java, 4th Ed and I came across the section that talks about overloading variable arguments. I tried out a piece of code from the book. (Method and class names not exactly the same).
public class Varargs { public static void m1(Character... args) { System.out.println("Character");
[code]....
In the above code, the compiler throws an 'Ambiguous for the type varargs' error. The error goes away if the first method is changed to:
public static void m1(char c, Character... args)
why there is ambiguity in the first piece of code and not the second.
I can understand result 3 is because of an upcast from short to int, since FunWithOverloading will not have a overloaded method with short now. However, what is happening with result 4? Shouldn't it call methodA of the subclass with the argument type short? If its because I have declared the reference variable, derived, of the type FunWithOverloading, then how come the first result correctly picks the overloaded method of the sub class?
class FunWithOverloading{ void methodA(int x){System.out.println("Integer method " + x);} void methodA(short x){System.out.println("Short method " + x);} //line 3 } class OverloadedSubClass extends FunWithOverloading{ void methodA(short x){System.out.println("Sub class short method " + x);}
The class Overloading below asks for two names and prints three different greetings. Your task is to write the class methods missing from the class declaration. Methods print the greetings as shown in the example print. The names and parameter types of the needed methods can be checked from the main method because all methods are called there. This exercise also does not require you to copy the source code below to the return field. The method declarations will suffice.
Example output
Type in the first name: John
Type in the second name: Doe
Java Code:
import java.util.Scanner; public class Overloading { public static void main(String[] args) { String firstName, secondName; Scanner reader = new Scanner(System.in);
I am doing a bank queue simulator program which will figure what will happen in 100 minute where 0 to 2 customers comes every minute. 3 counters will handle these customers each counter will poll the customer after 3 minutes.my problem is queue.poll()is not working in counter method and it is adding null values to the queue in the same method. when i add while customers.isEmpty(); the program will not work i do not know why
package dataalgo; import java.util.LinkedList; import java.util.PriorityQueue; import java.util.Queue; import java.util.Random; public class customer {
The class Overloading below asks for two names and prints three different greetings. Your task is to write the class methods missing from the class declaration. Methods print the greetings as shown in the example print.
Hint:The names and parameter types of the needed methods can be checked from the main method because all methods are called there. This exercise also does not require you to copy the source code below to the return field.
The method declarations will suffice.
Example output Type in the first name: John Type in the second name: Doe
********** Hi! ********** Hi, John ********** Hi, John and Doe **********
import java.util.Scanner; public class Overloading { public static void main(String[] args) { String firstName, secondName;
I was told to create a class named Billing that includes three overloaded computeBill methods for a photobook store.
The first method takes the price of the book ordered, adds 8% tax and returns the total due. The second method takes the price of the book, and the quantity, adds tax and returns the total. The final method takes the price, quantity and a coupon discount, adds tax and returns the total.
All of this I have managed fairly well, although I keep getting a strange error at the end of my program that the constructor is undefined. The problem bits of code(the one throwing the errors) are under the comment //Enter values into each of the methods
Code:
package org.CIS406.lab2;
public class Billing { //Declarations double bookPrice; int quantityOrdered; double couponValue;
[Code] ....
My first thought was to create a constructor for each of the methods that I am using...
I have a case in which I want to sort two types of ArrayLists (using quicksort) and the method originally coded only accepts a String ArrayList. The problem is that now I want to sort an ArrayList of type int but couldn't . . . so I decided to overload the method. Since it looks very ugly to copy and paste the same chunk of code only to change the method signature I wondered if there is a better way to make this method more dynamic and be able to take in different types of ArrayLists.
My code:
private ArrayList<String> sort(ArrayList<String> ar, int lo, int hi){ if (lo < hi){ int splitPoint = partition(ar, lo, hi); sort(ar, lo, splitPoint); sort(ar, splitPoint +1, hi);
I am trying to make a bank program that reads to .txt files, one that has the right format and one that has the wrong format. This is part of my problem I do not know how to do this. I also do not know why my code works if I input "account" rather than "account.txt" which is supposed to be the right thing.
Let me present my code that I have so far:
// File: BankAccount.java import java.util.Scanner; import java.io.IOException; public class BankAccount { private int accountNumber; private double balance;