Code
Code
1. CreditCard.java
public class CreditCard {
String customer;
String bank;
String account;
int limit;
double balance;
public CreditCard(String cust, String bk, String acnt, int lim, double
initialBal) {
customer = cust;
bank = bk;
account = acnt;
limit = lim;
balance = initialBal;
}
2. PredatoryCreditCard.java
public class PredatoryCreditCard extends CreditCard {
// Additional instance variable
private double apr; // annual percentage rate
// Constructor for this class
public PredatoryCreditCard(String cust, String bk, String acnt, int
lim, double initialBal, double rate)
{
// initialize superclass attributes
super(cust, bk, acnt, lim, initialBal);
apr = rate;
}
// A new method for assessing monthly interest charges
public void processMonth( ) {
if (balance > 0) {
double monthlyFactor = Math.pow(1 + apr, 1.0/12);
balance *= monthlyFactor;
}
}
// Overriding the charge method defined in the superclass
public boolean charge(double price) {
// call inherited method
boolean isSuccess = super.charge(price);
if (!isSuccess)
// assess a $5 penalty
balance -= 5;
return isSuccess;
}
}
MainCredit.java
public class MainCredit {
public static void main(String[] args)
{
CreditCard CC1=new CreditCard("Alba","ABI","123",500,100);
if(CC1.charge(200))
{
System.out.println("New charge done successfully");
}
ScoreBoard.java
package Game;
// shift any lower scores rightward to make room for the new entry
int j = numEntries - 1;
while (j > 0 && board[j-1].getScore( ) < newScore) {
board[j] = board[j-1];
// shift entry from j-1 to j
j--; // and decrement j
}
board[j] = e; // when done, add new entry
}
}
return temp;
// return the removed object
}
MainGame.java
package Game;
System.out.println();
S.remove(2);
//S.search(2); //printimi i objektit ne indexin 2
//S.search(10); //10 jane piket .Ka apo jo lojtare me 10 pike.
//Nese po do printoni objektin (Emrin,Piket)
//Nese jo do printoni nuk gjendet.
S.BoardString();
}
}
SinglyLinkedList (LinkedList.java, SinglyLinkedList.java)
LinkedList.java
package SinglyLinkedList;
class Node
{
int data;
Node next;
Node(int d) {
data = d;
next = null;
}
}
new_node.next = null;
last.next = new_node;
return;
}
SinglyLinkedList.java
package SinglyLinkedList;
// access methods
public int size() {
return size;
}
public boolean isEmpty( ) {
return size == 0;
}
public E first() {
if (isEmpty( ))
return null;
return head.getElement( );
}
public E last() {
if (isEmpty( ))
return null;
return tail.getElement( );
}
// update methods
public void addFirst(E e) {
head = new Node<>(e, head);
if (size == 0)
tail = head;
size++;
}
public E removeFirst( ) {
// removes and returns the first element
if (isEmpty( ))
return null;
E answer = head.getElement( );
head = head.getNext( );
size--;
if (size == 0)
tail = null;
return answer;
}
}