Author Archives: Mr. M

Bank Runner Class

Bank Class

This is a modified version of this bank assignment

The responsibilities of this class are to

  • Methods
    • Person[] topAccountOwners(int number )
      • this method returns the  top number  owners with the greatest amount of cash in 1 account
    • ** boolean binarySearch( int accountNumber)  // this method should implement the binary search algorithm to determine if the account acct exists . Note for binary search to work, what must be true?
    • ** extra credit  Account[] sortByAccountId()
      •   this method returns an array of Accounts sorted by amount in the account

 

 

Bank Account Inheritance Assignment

Person Class

This page is an edited version of this (old) assignment

Constructor

  • public Person( String _name, int _age)

instance Variables

  • private String name
  • private int age

 Methods

  • public String  getName()
  • public boolean equals(Person  other) // assume that two objects with same age and name are equal

Account – Super Class

Static Variable(s)

  • static private  int nextAccountNum

Constructor

  • public Account( double_balance, Person _owner)

instance Variables

  • private int  accountNumber
  • protected  double  balance
  • protected  Person[] owners

 Methods

  • public int getAccountNumber()
  • public void deposit(double amount)
  • public double getCurrentBalance()
  • public  boolean withdraw(double amount); // returns  false if  amount > this.balance
  • public boolean equals(Account other)
  • public String toString()
  • public void addOwner(Person p)
  • public void removeOwner( Person p)
  • public Person[] getOwners()

CheckingAccount extends Account

  • instance Variables
    • private int checksWritten
  • Acessors and Mutators
    • void writeCheck( double amount) –> tries to call super.withDraw() as long as the balance is enough and records a new check number

SavingsAccount extends Account

  • instance variables
    • private double interestRate
    • double[]  dailyBalances

    static variables

    • public static final int MINIMUM_BALANCE=100; // this is the absolute minimum amount of money that must always be in the account
  • methods
    • public boolean withdraw(double amount) //@override the withdraw() method to ensure that currentBalance the never gets below MINIMUM_BALANCE
    • public void recordDailyBalance() // @ record current day’s balance by storing it in   dailyBalances

 

After you have completed this, work on the Bank runner class.

Compiled and Interpreted Languages

Comilers and Interpreters

Retrieved from http://en.wikibooks.org/wiki/Introduction_to_Programming_Languages/Interpreted_Programs

Retrieved from http://en.wikibooks.org/wiki/Introduction_to_Programming_Languages/Interpreted_Programs

java-compiler-interpreter

retrieved from http://www.greenteapress.com/thinkapjava/html/thinkjava003.html

 

compiler_interpreter

retrieved from http://www.pasteur.fr/formation/infobio/python/ch05s02.html

 

Class Roster Array Version [Java] Assignment

Class Roster: This class will implement the functionality of all roster for school. It will , in essence, manage an Array of Student objects. Each roster will store a default of 10 Students

  • “global” Instance Variables
    • private Student myStudents   : an array storing Student Objects
    • private String className  (a name to represent a given roster like “Ap CS”)
    • public int period //during which period of the day does this roster meet
  • a default constructor should initialize the Array to store 20 strings
    a single parameter constructor that takes an Array <String>
    Both constructors should initialize the instance variables
  • Methods
    • Accessors
      • private int indexOf(Student st) //@returns index of Student St or -1
      • public boolean containsStudent(Student studentName )/ /@returns true if studentName is in roster .
      • public boolean equals(ClassRoster other) //@ returns whether or not rosters are equal. Rosters are equal if identical students are in identical order in the lists
    • Mutators:

public void addStudent(String studentName, int age) ;// adds student name and age to end of roster

. Hint: Make user of the containsStudent() method
public boolean removeStudent(int ssnId ) // removes student from roster based on id. Make sure that you maintain the integrity of the parallel ArrayLists.

public boolean removeStudent(String name) //removes student based on name. Make sure that you maintain the integrity of the parallel ArrayLists.

public  boolean removeStudent( Student st) //removes student st. Make sure that you maintain the integrity of the parallel ArrayLists.

Student Runner Part 2

1) Construct the Java statement to create the Student object called aStudent  in the

StudentsRunner

 

2)

Back to the Student Class


 

Student Object (OOP Java)

Student Class

A school district decided to write a program to help keep track of various parts of the school.

It has been decided to store relevant information about Students in a Student class. Each Student will have an array of Strings to store the names of his or her teachers.

private instance variables

 

Part 1

* Construct the Java statement to declare the array called

teachersNames to store the String names of the student’s teachers

Part 2

  • write a default constructor
  • construct a method called  addTeacher( String name) that adds String name to the  teachersNames  array
    • to do this let’s create a private method  private String[] addStr( String[] input, String val) that adds value to the end of the array and returns it. [redact]Solution[/redact]
  • construct hasTeacher(String name)  that returns true if name is in the teachersName array
  • construct a method removeTeacher(String name) that removes the   String name from the  teachersNames  array.
  • construct a method the line of code needed in the setGpa(double to) method of the Student Class.
  • construct a method boolean setTeacher (String name, int index) .   This method should return true if index is valid in the array and false if  index >= teachersName.length

 

Next: The runner class