Inheritance, abstract classes

Inheritance, abstract classes

Hi. I wish to thank you for answering my last question, but I had figured it out, but the GUI was very helpful. I could use someones help again with abstracts & a demo account. I know you will be thinking how could I write the code but not get the simplest part.I'm getting a little lost with child classes, but here goes and don't know what to call. First, the code works, I just can't finish the demo application.For class, I had to create a class named Account for a bank. Included an integer field for the account number and a double field for the account balance.Also included a constructor that requires an account number and sets the balance to 0.0. I included a set method for the balance. Also included two abstract get methods-one for each field. I created two child classes of Account: Checking and Savings. Within the Checking class, the get method displays the string"Checking Account Information", the account number and the balance. Within the Savings class, added a field to hold the interest rate, and require the Savings get method to display the string "Savings Account Information", the account number, the balance, and the interest rate. I have to write an application that displays both Checkin and Savings objects. Save as Account.java, Checking.java, Savings.java. In addition, I had to write an application named AccountArray in which you enter data for a mix of 10 Checking and Savings accounts. Use a loop to display data, save as AccountArray.java. My code is as follows:

public Account(int an)

{

accountNumber = an;

accountBalance = 0.0;

}

public void setBalance(double bal)

{

accountBalance = bal;

}

public abstract int getNumber();

public abstract double getBalance();

public abstract void getInfo();

}
public class Checking extends Account

{

public Checking(int a)

{

super(a);

}

public void getInfo()

{

System.out.println("Checking Account Information " +

getNumber() + " $" + getBalance());

}

public int getNumber()

{

return accountNumber;

}

public double getBalance()

{

return accountBalance;

}

}
public class Savings extends Account

{

double rate;

public Savings(int a, double r){

super(a);

rate = r;

}

public void getInfo()

{

System.out.println("Savings Account Information " +

getNumber() + " $" +getBalance() + " rate " + rate);

}

public int getNumber()

{

return accountNumber;

}

public double getBalance()

{

return accountBalance;

}

}

This is the DemoAccounts application I am having problems with. I can only get the Savings to print:

public class DemoAccounts

{

public static void main(String[] args)

{

Savings mySvAcct = new Savings(2345, 0.03);

 mySvAcct.getInfo();

}

}

This is the AccountArray:

public class AccountArray

{

public static void main(String[] args)

{

Account someAccts[] = new Account[10];

int i;

someAccts[0] = new Checking(101);

someAccts[1] = new Savings(201, 2.1);

someAccts[2] = new Checking(102);

someAccts[3] = new Savings(202, 2.2);

someAccts[4] = new Checking(103);

someAccts[5] = new Savings(203, 2.3);

someAccts[6] = new Checking(104);

someAccts[7] = new Savings(204, 2.4);

someAccts[8] = new Checking(105);

someAccts[9] = new Savings(205, 2.5);

for(i = 0; i <10; ++i)

someAccts[i].getInfo();

}

}
View Answers









Related Tutorials/Questions & Answers:
Inheritance, abstract classes
Inheritance, abstract classes  Hi. I wish to thank you for answering... a little lost with child classes, but here goes and don't know what to call... method for the balance. Also included two abstract get methods-one for each
What is Abstract classes in Java?
What is Abstract classes in Java?  What is Abstrack class in Java...,   Hi, In Java programming language we are used the Java Abstract class to declare some common characteristics of subclasses.This Abstract class
Advertisements
Abstract class,Abstract methods and classes
Abstract methods and classes     ... is used with methods and classesAbstract MethodADS_TO_REPLACE_1... language, abstract classes are those that works only as the parent class
Interfaces and Abstract Classes - Development process
Interface and Abstract Classes?  Hi Friend, Interface: Java does.... It relate classes from different types of hierarchy. Abstract Class: Any class... be embedded into these classes. Abstract class prevents from instantiating a class
Abstract Classes - Java Interview Questions
Abstract Classes  Why we cann't instantiate a Abstract Classes? Even if an Abstract Class does not have any abstract methods, but declaring the class as abstract prevents it from creating an instance. Why? Thanks in Advance
Java Inheritance and abstract - Java Interview Questions
Java Inheritance and abstract  1) Why we need to write the separate Interface in which we are not doing any operation except declaring empty abstract... the abstract methods. If the subclass need to use this methods then he can write
Abstract methods and classes
Abstract methods and classes     ... is used with methods and classesAbstract MethodADS_TO_REPLACE_1... language, abstract classes are those that works only as the parent class
inheritance
inheritance  how does one implement inheritance in java
inheritance
inheritance  hi.. pleaseeeeee i need a quick help(answer) in creating aprogrm in java by using inheritance for car in such away that .... Car is parent class and both of Private and Public Car extends it then both of Bus
Java Abstract Class Example
the behaviour of classes from the outside environment. Abstract class can be created... and some are unique to specific classes. An abstract class should...Java Abstract Class Example In this section we will read about the Abstract
inheritance
inheritance  write a programwhich has three classes,namely,FirmClass,Animal and Dog,to illustrate how these class Dog inherits from Animal .The class Animal should have a method called move() which prints out the string"Animal
abstract class
abstract methods. Abstract classes cannot be instantiated, but they can be extended...abstract class   Explain the concept of abstract class and it?s use with a sample program.   Java Abstract Class An abstract class
Inheritance in Java
Inheritance, one of the important concepts of Object Oriented Programming.... Benefit of using inheritance: A code can be used again and again Inheritance in Java enhances the properties of the class, which means
multiple inheritance - Java Beginners
)why java classes does not support Multiple Inheritance? JAVA CLASSES ONLY... Inheritance. Ans...>java classes doesn't support multiple inheritance,the practical...multiple inheritance  Why java does not support Multiple Inheritance
Interface Vs Abstract Class
) and non-public members abstract classes may or may not be a little bit... Interface Vs Abstract Class       There are three main differences between an interface and an abstract
Abstract class and abstract method
Some key points about abstract methods are as following An abstract modifier identifies abstract classes and methods An abstract methods cannot be private because it defined in the other class. An abstract methods cannot
multiple inheritance
multiple inheritance  why java doesn't support multiple inheritance? we can achieve this by using interface but not with classes? what is the main reason that java community implemented like
Inheritance,Inheritance in Java,Java Inheritance
Inheritance       To know the concept of inheritance clearly you must have the idea of class and its... this, super etc. As the name suggests, inheritance means to take something
Java Abstract Class
. It may or may not have abstract methods. Abstract classes cannot be instantiated... an abstract class. Which helps us to organize our classes based on common methods.... Abstract classes contain mixture of non-abstract and abstract methods
Uses of abstract class & interface - Java Beginners
classes from different types of hierarchy. Abstract Class: Any class... into these classes. Abstract class prevents from instantiating a class...Uses of abstract class & interface  Dear sir, I'm new
Abstract Factory Pattern
Abstract Factory Pattern       II Abstract Factory Pattern :  This pattern is one level of abstraction higher than factory pattern. This means that the abstract factory returns
Difference between abstract class and an interface
an abstract class is class which cannot extends multiple classes because java...Difference between abstract class and an interface The difference between abstract class and interface is one of the most popular question in the interview
Multiple Inheritance
inheritance but by default Object class is super class for all the user defined classes and we can extend at most one class so each class can extend more than one class so java any how do multiple inheritance? Can you please explain
Inheritance
Inheritance       To know the concept of inheritance clearly you must have the idea of class and its... this, super etc. As the name suggests, inheritance means to take something
Abstract and Interface
abstract classes, java interfaces are slow as it requires extra indirection...Abstract and Interface  What is interface? When time is most suitable for using interface? Why we use interface instead of abstract? What
abstract class - Java Beginners
use becomes necessary and useful ?give some examples of abstract classes..., In java programming language, abstract classes are those that works only... inherited from the abstract class (base class). Abstract classes
PHP Inheritance Class
values in classes, we must use the inheritance when the structure...Inheritance in PHP: Inheritance is a property of Object Oriented Programming.... With the help of this property classes and objects  get more flexibility, scalability
abstract method
abstract method  Can we have abstract class with no abstract methods
abstract class
abstract class  Can there be an abstract class with no abstract methods
Abstract class
Abstract class  Can an abstract class be final
Abstract class
Abstract class  what is an Abstract class
abstract method
abstract method  is final method is in abstract class
multiple inheritance.
multiple inheritance.  hello, can java support multiple inheritance???   hi,ADS_TO_REPLACE_1 java does not support multiple inheritance
abstract method
abstract method  Can a concrete class have an abstract method
Abstract and Interface
Abstract and Interface  what is the difference between Abstract and Interface accurateatly
abstract wizard form controller
abstract wizard form controller  Hi In roseindia for abstract wizard form controller example contains half of the code. please send the remaing half of the code like controller classes
Abstract class and interface in Java
variables) and non-public members abstract classes may or may not be a little bit...Abstract class and interface in Java  What is the difference between abstract class and interfaces in Java?   Differences between
Inheritance
Inheritance       To know the concept of inheritance clearly you must have the idea of class and its... this, super etc. As the name suggests, inheritance means to take something
Interface and Abstract class
or more abstract methods and these method implemented by sub classes. Abstract class...Interface and Abstract class  hello,, Can some body tell me what is the difference between an Interface and an Abstract class?   hi,ADS
Abstract class - Java Beginners
are overrided in which that is implemented . thats all abt abstract classes...Abstract class  Why can use abstract class in java.?when abstract class use in java.plz Explain with program.   abstract class abs{ public
Concept of Inheritance in Java
Concept of Inheritance in Java Concept of Inheritance in Java is considered one of the important features of Object Oriented Programming. Inheritance as the name suggest is used to derive classes from other classes. The derived class
Abstract class
Abstract class  j   An Abstract class is a base class which... with an abstract keyword. For more information, visit the following links: http://www.roseindia.net/help/java/a/java-abstract-class.shtml http://www.roseindia.net/java
Inheritance in Spring
Inheritance in Spring       Inheritance Demo, In the example given below we are going to tell about the inheritance in the Spring framework. By inheritance we mean a way
Interface and Abstract class
be invoked if a main() exists. 8)In comparison with java abstract classes, java...Interface and Abstract class  Difference between Interface and Abstract class? Give some example   Difference Between Interface
abstract class
abstract class  abstract class AbstractClass{ } is possible and compile the class or any compile time error occur tell me the answer Blockquote
abstract class
abstract class  what is abstract class .why we use it or what is the need of this class?   Abstract class is like base class which contains abstract method and cannot instantiated.   Please go through
Advanced Concepts with Classes - JDBC
Advanced Concepts with Classes  Advanced Concepts with Classes( Inheritance, Polymorphism, Overriding) i need help to create this application,than you Employees in a company are divided into the classes Employee, HourlyPaid
java inheritance
contain three classes, a SalesEmployee class, a SalesPerson class and a SalesAgent... would be good? public abstract class employees { protected double sales...; } public abstract void computetotalsales( ); } public class sales
javascript inheritance framework
javascript inheritance framework  javascript inheritance framework
Abstract Class in Java
. Abstract classes can be extended into sub classes. Abstract class can...Abstract class in Java is a class that is declared using abstract keyword. It cannot be instantiated but can be extended into subclass. Abstract class cannot

Ads