top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

can help me to Discuss the approach where you will need to write the object's state to a textfile

+2 votes
420 views

Object Persistence as Non-Serializable
Assume that the Java programming languae does not have the serializable feature (or you want to mimic
the serializable feature manually).
Discuss the approach where you will need to write the object's state (the values of all member feilds of an
object) to a textfile.
State all possible cases where the manual approach will have pitfalls(at some instance, the manual
approach may either potentially fail or certainly will fail).

posted Dec 19, 2014 by As M Ob

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button
cant understand anything please ask to the point.
Assume that the Java programming languae does not have the serializable feature (or you want to mimic
the serializable feature manually).
Discuss the approach where you will need to write the object's state (the values of all member feilds of an
object) to a textfile.
State all possible cases where the manual approach will have pitfalls(at some instance, the manual
approach may either potentially fail or certainly will fail).

Similar Questions
+1 vote

Can someone help me to build Failure Test case for these Functions..

public int sumFromTo(int[] arr, int from, int to) { // 1 Case
        if (arr == null || arr.length == 0 || to > arr.length - 1) {
            throw new IllegalArgumentException();
        }
        int sum = 0;
        for (int i = from; i <= to; i++) {
            sum += arr[i];
        }
        return sum;
    }

    // Second Function
    public String replaceCharacter(String word, char oldchar, char newchar) {
        if (word == null) {
            throw new IllegalArgumentException(); // 2 cases
        }
        int i = 0;
        String s = new String();
        do {
            if (word.toLowerCase().charAt(i) == oldchar) {
                s += newchar;
            } else {
                s += word.charAt(i);
            }
            i++;
        } while (i < word.length());
        return s;
    }

    // Third Function
    public boolean isPrime(int num) { // 3 cases
        for (int i = 2; i < 10; i++) {
            if (num % i == 0 && i != num) {
                return false;
            }
        }
        return true;
    }
+1 vote

Create two subclasses of the Account class, one for checking accounts, Checking, and one for saving accounts, Saving. These two subclasses cannot be extended any further. A checking account has overdraft limit, but a saving account doesn’t have an overdraft. A Saving account is an interest-bearing financial product, but checking accounts are not.

Overdraft in a bank account means the balance can go for negative value, say -$500.00.
Interest-bearing bank account means the bank pays an interest, with a pre-specified rate, for positive balances in the account, calculated daily, paid monthly, for typical bank accounts. For simplicity, we will consider only fixed, non-cumulative rate calculations. For instance if the balance is $1000, annual rate is 3%, then the total interest would be (3/100 * 1000 = $30 per annum, or $30/12 months = $2.5 monthly.

Hints. To develop a nice, and easy to implement solution, try to write the above paragraph as functional and non-functional requirements. For example

Functional Requirements: Two types of accounts, checking and saving.
Non-Functional Requirements: as design constraint, e.g. these two accounts cannot be further extended.
After splitting each description of the project, most often, but not always, is to design and implement the functional objectives of the project (i.e. the functional requirements in this exercise). After this, implement the non-functional requirements, as additional constraints.

when Account class :
import java.util.Date;

public class Account {
int id ;
String name;
double balance;
double annualInterestRate ;
Date dateCreated ;

public Account()
{ 
    dateCreated = new Date(); 
};
public Account(int id , String name)
{
dateCreated = new Date();
this.id=id;
this.name=name;
};
public Account(int id , String name , double balance )
{
dateCreated = new Date();
this.id=id;
this.name=name;
this.balance=balance;
};
public Account(int id, String name, double balance, double annualInterestRate)
{
dateCreated=new Date();
this.id=id;
this.name=name;
this.balance=balance;
this.annualInterestRate=annualInterestRate;
}
public void setID(int id1)
{
id=id1 ;
}
public int getID()
{
return id;
}
public void setANNUAL(double annual)
{
annualInterestRate=annual;
}
public double getANNUAL()
{
return annualInterestRate;
}
public void setNAME(String name1)
{
name=name1;
}
public String getNAME()
{
return name;
}
public void setBALANCE(double balance1)
{
balance = balance1;
}
public double getBALANCE()
{
return balance;
}
 double getMonthlyInterestRate()
{
    return balance/12;
}
public double withdraw(double amount )
 {
     balance = this.balance - amount ;
     return balance ;

 }
public double deposit(double amount )
 {
     balance = this.balance + amount ;
     return balance ;

 }
public boolean equals(Object other){

 if (other instanceof Account){

    if(other==null && this == null)
          return true;

     else
      {
             Account obj=(Account) other;

            if(obj.id==this.id && obj.name==this.name) 
                return true;
            else{
                return false;
           }
         }
 }
    else return false;

}

public String toString(){
return "Name : " + this.name +
"\n" +"ID : " + this.id +
"\n" +"Balance :" + this.balance +
"\n" +"DateCreated :" +this.dateCreated +
"\n" +"MonthlyInterestRate :" +this.getMonthlyInterestRate() ;

}

}

and the Test Class :
public class TestAccount {

public static void main(String[] args) {
    Account account1 = new Account(740135 ,"Alma Mather" , 500 ) ; 
    Account account2 = new Account(32842 ,"Harley Hacker" ,4000  ) ;     
    Account account3 = new Account(224519 ,"Carl Cracker," , 1000 ) ; 
    // ACCOUNT 1
    account1.deposit(100); 
    account1.withdraw(200);
    account1.withdraw(100);
    account1.withdraw(50);
    account1.deposit(150);
    // ACCOUNT 2
    account2.withdraw(700); 
    account2.withdraw(400);
    account2.deposit(300);
    account2.withdraw(40);
    account2.withdraw(200);
    // ACCOUNT 3
    account3.withdraw(300); 
    account3.withdraw(100);
    account3.deposit(250);
    account3.withdraw(40);
    account3.withdraw(200);

    /////
    System.out.println(account1.toString());
    System.out.println();
    System.out.println();
    System.out.println(account2.toString());
    System.out.println();
    System.out.println();
    System.out.println(account3.toString());
    System.out.println();
    System.out.println();

}

}

+3 votes

Hexadecimal Conversion.
The conversion into Hexadecimal is the same as mentioned above, except when the remainder is from 10
to 15, you have to replace it by the corresponding Hexa digit, i.e. if the remainder is 14, replace it with the letter 'e' or 'E'.

You have to design and implement another class where it implements the ConvertableNumberSystems.
AlphaBase. The implementation of the xbase() method is only to convert from any non-negative decimal integer into its equivalent one in Hexadecimal (base = 16). When implementing the xbase() method, you would notice that the method must return a string that represents the number in the base 16. This would, for sure to return back (iterative development with backtracking) to change all past implementation to reflect this new modification.

Tip. You may use the the StringBuilder class to accumulate the remainders of the division into the result.

+1 vote

Can someone help me with java example that show in coding the Content Coupling?

...