Sunday 15 July 2012

Can't read values Inheritance in java -


I am writing a simple program to clarify sections and heritage in Java. This program is a bank in which there is an account and operation of 2 sections where the operation expands the account. Now in the main, I declared the values ​​in the account and then I started calling operation from the Operation Class. . Now whenever I call values ​​in the Operation Account, I can return 0 for the value-added integer, and the account for the string

here:

  Public class account {the name of the private string; Private Ent ID; Private double money; Account () {} Account (String N, ITI, Double M) {Name = N; Id = i; Money = m; } Public Zero Saturni (Double M) {Money = M; } Public double getMoney () {return money; } Public int getID () {return ID; } Public string getName () {return name; } Public Zero Check () {println ("Your name is:" + name + "Your id is:" + String.valueOf (ID) + "Your balance is:" + String.valueOf (Money)); }}   

Here is the Operation Class:

  import java.util.Date; Extension of Public Category Operation Account (Private Date Transaction Date); Public Zero Refund (Dual Zodiac) {Double Money = Match (); If (amount> money) System.out.println ("the amount is insufficient"); Other {Money = Money - Zodiac; TransactionDate = New Date (); SetMoney (money); Println ("Available Money" + String.valueOf (Money) + String.valueOf ("TransactionDate" on ")"; }} Public Zero Deposit (Dual Zodiac) {Double Money = getMoney (); If (amount & lt; 0) System.out.println ("You can add zero"); Other {Money = Money + zodiac; TransactionDate = New Date (); SetMoney (money); (: + String.valueOf (TransactionDate) "in" + String.valueOf (Money) + "are your credits"); System.out.println}} Public Zero Check () {string name = getName (); Int id = getID (); Double money = getMoney (); Println (+ name + "Your ID is:" + String.valueOf (ID) + "Your balance is:" "Your name is" + String.valueOf (Money)); }}   

Here's the key:

  import java.io.buffferedReader; Import java.io.IOException; Import java.io.InputStreamReader; Public class main {/ ** * @param arg * @throws IOException * @throws NumberFormatException * / public static void throws (String [] args) NumberFormatException, IOException {// TODO Automatic Created Stub BufferedReader br = New BufferedReader (New InputStream Reader (System.in); System.out.println ("Enter your ID"); Int id = integer.center (breadline ()); System.out.println ("Enter your name"); String name = br.readLine (); System.out.println ("Enter your Money"); Double money = double. PRDABB (breadline ()); Account A = new account (name, id, money); A check (); Operation O = new operation (); While {true} {System.out.println ("\ n -----------------------------------" ); System.out.println ("Enter 1 to withdraw, 2 to submit, check with 3, 4 to exit"); Int operation = integer .pressant (breadline ()); Switch (operation) {case 1: System.out.println ("Enter amount"); Double return money = double. Prsd double (breadline ()); O.Withdraw (withdrawMoney); break; Case 2: System.out.println ("Enter Amount"); Double deposit amount = double. PRDABB (breadline ()); O.Deposit (Depositmoney); break; Case 3: o check (); break; Case 4: Break; Default: System.out.println ("Enter between 1 and 4 only"); } If break (operation == 4); }}}   

I do not know the value of reading the operation cat I have added to the account because the operation account expands can you please tell me the reason and how it is correct Do you? thank you in advanced.

You have two different objects - one account , and one Operation

An example of your operation class has the name, id and money - but they do not have the name, id, and money in the account or other examples of operations.

The only way to fix this, the operator must add a constructor:

  class operation {operation (string n, it, double m) {super (n, I am); } ...}    

No comments:

Post a Comment