Questions
Modify the BankAccount class to throw IllegalArgumentException exceptions, create your own three exceptions types. when the...

Modify the BankAccount class to throw IllegalArgumentException exceptions, create your own three exceptions types. when the account is constructed with negative balance, when a negative amount is deposited, or when an amount that is not between 0 and the current balance is withdrawn. Write a test program that cause all three exceptions occurs and catches them all.

/**
A bank account has a balance that can be changed by
deposits and withdrawals.
*/
public class BankAccount
{
private double balance;

/**
Constructs a bank account with a zero balance
*/
public BankAccount()
{   
balance = 0;
}

/**
Constructs a bank account with a given balance
@param initialBalance the initial balance
*/
public BankAccount(double initialBalance)
{   
if (initialBalance < 0)
throw new NegativeBalanceException(
"Cannot create account: " + initialBalance + " is less than zero");   
  
balance = initialBalance;
}

/**
Deposits money into the bank account.
@param amount the amount to deposit
*/
public void deposit(double amount)
{
if (amount < 0)
throw new NegativeAmountException(
"Deposit of " + amount + " is less than zero");
double newBalance = balance + amount;
balance = newBalance;
}

/**
Withdraws money from the bank account.
@param amount the amount to withdraw
*/
public void withdraw(double amount)
{   
if (amount < 0)
throw new NegativeAmountException(
"Withdrawal of " + amount + " is less than zero");
  
if (amount > balance)
throw new InsufficientFundsException(
"Withdrawal of " + amount + " exceeds balance of " + balance);
  
double newBalance = balance - amount;
balance = newBalance;
}

/**
Gets the current balance of the bank account.
@return the current balance
*/
public double getBalance()
{   
return balance;
}
}
---------------

/**
A class to test the BankAccount class.
*/
public class BankAccountTester2
{
public static void main(String[] args)
{
BankAccount harrysChecking = new BankAccount();
  
try
{
harrysChecking.deposit(300);
System.out.println("success");
}
catch (IllegalArgumentException e)
{
System.out.println("exception");
}
System.out.println("Expected: success");

try
{
harrysChecking.withdraw(100);
System.out.println("success");
}
catch (IllegalArgumentException e)
{
System.out.println("exception");
}
System.out.println("Expected: success");

try
{
harrysChecking.deposit(-100);
System.out.println("success");
}
catch (IllegalArgumentException e)
{
System.out.println("exception");
}
System.out.println("Expected: exception");

try
{
harrysChecking.withdraw(300);
System.out.println("success");
}
catch (IllegalArgumentException e)
{
System.out.println("exception");
}
System.out.println("Expected: exception");
}
}
-------------------------

Hint:

/**
This exception reports a negative initial balance on a bank account.
*/
public class NegativeBalanceException extends RuntimeException
{
public NegativeBalanceException()
{
}

public NegativeBalanceException(String message)
{
super(message);
}
}

In: Computer Science

C PROGRAM In Stage 1, you will be implementing the Draw Line command to draw horizontal...

C PROGRAM

In Stage 1, you will be implementing the Draw Line command to draw horizontal and vertical lines.

The Draw Line command is given four additional integers, which describe two pixels: the start and end pixels of the line.

Each pixel consists of two numbers: the index of the row, and the index of the column.

For example, the command 1 10 3 10 10 tells your program to draw a line (1), starting at the pixel at row 10 and column 3, and ending at the pixel at row 10 and column 10.

When given the Draw Line command, your program should set the colour of the relevant elements in the canvas array, starting at the provided start pixel location, and continuing along the horizontal or vertical line until it reaches the end pixel location (including both the start and end pixels themselves).

Hints

  • Your program will only be drawing either horizontal or vertical lines in Stage 1, which means that either row1 and row2 will be the same, or col1 and col2 will be the same.
  • If row1 == row2 && col1 == col2, your program should draw a single pixel, at the location (row1, col1), (row2, col2).

Handling Invalid Input

  • If the given command both starts and ends outside the canvas, you should do nothing, and ignore that Draw Line command. Note that ignoring the command should still read in it's arguments. Otherwise, if one end pixel of the line is within the canvas you should draw the section of the line that is within the canvas.
  • If the given start and end pixels would not give an entirely horizontal or vertical line, your program should ignore that Draw Line command and do nothing. Note that ignoring the command should still read in it's arguments.

Input Commands

  • Input to your program will be via standard input (similar to typing into a terminal).
  • You can assume that the input will always be integers and that you will always receive the correct number of arguments for a command. You will never be given a integer that represents a command that doesn't exist.
  • You can assume that input will always finish with the "End of Input" signal (Ctrl-D in the terminal).

Starter Code.

#include <stdio.h>

// The dimensions of the canvas (20 rows x 36 columns).
#define N_ROWS 20
#define N_COLS 36

// Shades (assuming your terminal has a black background).
#define BLACK 0
#define WHITE 4

// IF YOU NEED MORE #defines ADD THEM HERE


// Provided helper functions:
// Display the canvas.
void displayCanvas(int canvas[N_ROWS][N_COLS]);
// Clear the canvas by setting every pixel to be white.
void clearCanvas(int canvas[N_ROWS][N_COLS]);


// ADD PROTOTYPES FOR YOUR FUNCTIONS HERE


int main(void) {
    int canvas[N_ROWS][N_COLS];

    clearCanvas(canvas);

    // TODO: Add your code here!

    // Hint: start by scanning in the command.
    //
    // If the command is the "Draw Line" command, scan in the rest of
    // the command (start row, start col, length, direction) and use
    // that information to draw a line on the canvas.
    //
    // Once your program can draw a line, add a loop to keep scanning
    // commands until you reach the end of input, and process each
    // command as you scan it.

    displayCanvas(canvas);

    return 0;
}



// ADD CODE FOR YOUR FUNCTIONS HERE



// Displays the canvas, by printing the integer value stored in
// each element of the 2-dimensional canvas array.
//
// You should not need to change the displayCanvas function.
void displayCanvas(int canvas[N_ROWS][N_COLS]) {
    int row = 0;
    while (row < N_ROWS) {
        int col = 0;
        while (col < N_COLS) {
            printf("%d ", canvas[row][col]);
            col++;
        }
        row++;
        printf("\n");
    }
}


// Sets the entire canvas to be blank, by setting each element in the
// 2-dimensional canvas array to be WHITE (which is #defined at the top
// of the file).
//
// You should not need to change the clearCanvas function.
void clearCanvas(int canvas[N_ROWS][N_COLS]) {
    int row = 0;
    while (row < N_ROWS) {
        int col = 0;
        while (col < N_COLS) {
            canvas[row][col] = WHITE;
            col++;
        }
        row++;
    }
}

In: Computer Science

(using c) You will build a system to manage patients’ data in a hospital. The hospital...

(using c) You will build a system to manage patients’ data in a hospital. The hospital patient management system stores specific information in the form of health record to keep track of the patients’ data.

Your program should read the information from a file called “patients.txt” that should be on the following format: Patient Name#Gender#Date of admission#Date of birth #Illness#Address (City)#Blood type (using c)

Example of data input:

Alma Mukhles#F#2212019#01012000#Ear infection#Nablus#B+

Ahmed A. Ali#M#01102020#05101970#Low blood pressure#AlBireh#A-

Your program should be able to do the following tasks:

Options:

1. Read data: read the data of the patients from the file.

2. Create linked list: create a linked list.

3. Sort data: use Radix sort to sort the data based on the patients’ names.

4. Add patient: add a new patient.

5. Update patient: update patient’s information.

6. Delete patient: soft delete (explained below).

7. Search for patients a. Name b. Date of birth

8. List patients

a. All patients

b. Category (i.e., illness)

c. City

d. Discharged (Patients who were deleted from the system)

9. Export medical report: export XML file following medial health record standards.

10. Exit: exit from the system and store the information back to the file.

Notes:

- Deleted patients should not be deleted from the linked list (data). Instead, there should be a flag in their record indicating if they are discharged. This means, when exporting the data, all patients, including the records that have been deleted should be kept. However, when listing all patients in the linked list, this data should not be listed.

- For simplicity you my limit the number of patients to n=100 and the number of characters m in each name to 50. - You are allowed to use only character comparisons. Thus, you are not allowed to use the String library functions.

- Export medical report: this should export an XML format of the data in the linked list using the following format:
<patient>

<name>Alma Mukhles</name>

<gender>F</gender>

<admissionDate value=”2212019” />

<birthDate value=”01012000” />

<diagnosis>Ear infection</diagnosis>

<city>Nablus</city>

<bloodType>B+</bloodType>

</patient>

<patient>

<name>Ahmed A. Ali</name>

<gender>M</gender>

<admissionDate value=”01102020” />

<birthDate value=”05101970” />

<diagnosis>Low blood pressure </diagnosis>

<city> AlBireh </city>

<bloodType>A-</bloodType>

</patient>

The   data   is   exported   to   a   file   called   Report.xml

In: Computer Science

There are two algorithms that perform a particular task. Algorithm 1 has a complexity function: f(n)...

There are two algorithms that perform a particular task. Algorithm 1 has a complexity function: f(n) = 5n + 50. Algorithm 2 has a complexity function g(n) = n^2 + 10g . (Show your answer)

a)Which algorithm is more efficient when n = 5?

b) Which algorithm is more efficient when n = 20?

c) what are complexity of f(n) and g(n)

In: Computer Science

A positive integer n is said to be prime (or, "a prime") if and only if...

A positive integer n is said to be prime (or, "a prime") if and only if n is greater than 1 and is divisible only by 1 and n . For example, the integers 17 and 29 are prime, but 4, 21 and 38 are not prime. Write a function named "is_prime" that takes a positive integer argument and returns as its value the integer 1 if the argument is prime and returns the integer 0 otherwise.

Can you make it in vba excel and in the form of functions because its hard for me

In: Computer Science

LANGUAGE C Code function: I wanted to create an array, i.e. index[100], and store 3 elements...

LANGUAGE C

Code function:

I wanted to create an array, i.e. index[100], and store 3 elements into it.

The elements that i wanted to store is from the same variable, however its value will always change in the while loop

e.g. index[0]=1, index[1]=3, index[2]=5

However it seems that my code has a problem that my compiler warns me that the variable index is set but not used. And also, is it not possible to store the elements into the array using the while loop in my code? As i am not familiar with c language. Can sir/madam fix the codes below and teaches the proper way?

NOTE: i use gcc compiler in unix environment. Any assistance is very much appreciated in advance

#include <stdio.h>

int main(){
   int c=0;
   int j=2;
   int i=0;
   int index[100];

   int a=1;
  
   while(c<=j){
       index[c]=a;
       a+=2;
       c+=1;

   }

   for(i=0;i++;i<=j){
       printf("%d",index[i]);
   }
}

In: Computer Science

Big-O: Describe the worst case running time of the following pseudocode or functions in Big-Oh notation...

Big-O: Describe the worst case running time of the following pseudocode or functions in Big-Oh notation in terms of the variable n. Show your work

a) O( )

int m1(int n, int m) {

if (n < 10) return n;

else if (n < 100)

return happy (n - 2, m);

else

return happy (n/2, m);

}

-----------------------------

b) O ( )

void m2 (int n) {

j = 0;

while (j < n) {

for (int i = 0; i < n; ++i)

{ System.out.println(”i = ” + i);

for (int k = 0; k < i; ++k)

System.out.println(”k = ” + k);

}

j = j + 1; }

}

---------------------------

c) O ( )

void m3 (int n) {

for (int i = 0; i < n * n; ++i) {

for (int k = 0; k < i; ++k)

System.out.println(”k = ” + k);

for (int j = n; j > 0; j--)

System.out.println(”j = ” + j);

}

} ------------------

d) O ( )

void m4 (int n, int x) {

for (int k = 0; k < 500; ++k)

if (x > 500) {

for (int i = 0; i < n * k; ++i)

for (int j = 0; j < n; ++j)

System.out.println(”x = ” + x);

}

}

In: Computer Science

what are cloud computing security concerns and their countermeasures

what are cloud computing security concerns and their countermeasures

In: Computer Science

Explain and demonstrate a Linked List by adding following items into a Linked List: 10, 30,...

Explain and demonstrate a Linked List by adding following items into a Linked List: 10, 30, 15, 25 (show your work, you may write on paper and upload if you prefer)

In: Computer Science

I. Describe the differences between discretionary access control model and mandatory access control model II. File...

I. Describe the differences between discretionary access control model and mandatory access control model

II. File permissions in Linux can be also represented in digits from 0-7 for the owner, group and others with reading as the most significant bit (E.g., the value 6 represents the permission right rw- for a file). Suppose a file in Linux has the permission as the digits 764.

• What does this permission right indicate for the owner/user, group and others?

• What is the letter representation of this permission right?

In: Computer Science

develop a recursive function to compute LCS (x,y)

develop a recursive function to compute LCS (x,y)

In: Computer Science

i'm getting an infinite loop on this code: can you explain what I should do? public...

i'm getting an infinite loop on this code: can you explain what I should do?

public class TriviaLinkedList {

private TriviaNode head;

private int items;

public TriviaLinkedList(TriviaNode head, int items) {

this.head = head;

this.items = items;

}

public TriviaNode getHead() {

return head;

}

public void setHead(TriviaNode head) {

this.head = head;

}

public int getItems() {

return items;

}

public void setItems(int items) {

this.items = items;

}

public String toString() {

return "head=" + head + ", items=" + items;

}

  

public void insertList(TriviaNode node){

if(head == null){

head = node;

}

  

else {

TriviaNode node1 = head;

head = node1;

head.next = node1;

}

this.items++;

}

  

public void deleteList(int id){

TriviaNode first = head;

TriviaNode second = head;

while(first!=null) {

  

if(first.getGame().getId() == id) {

if(first == head) {

head = first.next;

}

  

else if(first.next != null) {

second.next = first.next;

}

else {

second.next = null;

this.items--;

System.out.println("Game: "+id+" was deleted");

return;

}

second = first;

first = first.next;

}

      System.out.println("Unfortunately Game: "+id+" was not found");

}

}

}

  

In: Computer Science

Question 1 Afariwa farm operates a large farm on which cow are raised. The farm manager...

Question 1
Afariwa farm operates a large farm on which cow are raised. The farm
manager Kofi Manu determined that for the cow to grow in the desired
fashion, they need at least minimum amounts of four nutrients. Kofi
Manu is considering three different grains to feed the cow. The table
below lists the number of units of each nutrient in each kilogram of
grain, the minimum daily requirements of each nutrient for each cow,
and the cost of each grain. The manager believes that as long as a cow
receives the minimum daily amount of each nutrient, it will be healthy
and produce a standard amount of meat. The manager wants to raise
the cow at minimum cost.
Grain 1 Grain 2 Grain 3 Minimum
daily
requirement
(units)
Nutrient A 20 30 70 110
Nutrient B 10 10 0 18
Nutrient C 50 30 0 90
Nutrient D 6 2.5 10 14
Cost (GH¢) 41 36 96
a) Formulate a linear programming model for this problem.
b) Use solver to find optimal solution and sensitivity report.
c) Management have asked you to determine the optimal solution.
Write your answer in a form of a report to be submitted to the
management.
(d) Advice the management about objective function value
corresponding to your answer in (b).

In: Computer Science

Research the System Stability Index (SSI). Write a brief summary of its purpose and why it...

Research the System Stability Index (SSI). Write a brief summary of its purpose and why it might be a useful tool for a server admin.

Research the netstat command-line tool. Write a brief summary of its usage, options, and why it might be a useful tool for a server admin

In: Computer Science

In C++, Mrs. Jones wishes to computerize her grading system. She gives 5 tests but only...

  1. In C++, Mrs. Jones wishes to computerize her grading system. She gives 5 tests but only counts the 4 highest scores. Input the 5 test scores and output the average of the highest four. And using the following grading scale, 90-100 A, 80-89 B, 70-79 C, 60-69 D, and below 60 F, output the student’s letter grade. After creating this code, Modify the above to calculate the grade for all students in the class. The first input value will be the number of students in the class. You will then need to use a loop to input the students’ names as well as their 5 grades. Inside the loop (after calculating the average for the student) you will need to add each student’s average to a sum variable because at the end, you will need to print out the class average as well as each students’ names and letter grades.

In: Computer Science