Question

In: Computer Science

Financial Records Create a program to store weekly expenses and revenues over a period of time....

Financial Records

Create a program to store weekly expenses and revenues over a period of time. The program should

store the expenses and revenues in two global array variables. Values stored in the array at index k

represent the total revenues/expenses recorded during the k(th) week. Assume that the maximum number of weeks tracked is 250.

Add the following functions to your program:

-

A function that finds the total of all expenses incurred since week t for a given t.

-

A function that records the total expenses and revenues for the next unrecorded week. It must check if there is still space in the array.

-

A function that prints the number of weeks recorded

-

A function that prints all revenues and expenses recorded

-

A function that returns a pointer to the largest revenue recorded

Organize the program so the function prototypes are presented

first, and the definitions after the main

function. Your program should keep asking the user to select

one of the following options and execute

the corresponding function based on the user choice:

(A)

computed the total of all expenses,

(B)

add a new expense/revenue ,

(C)

print the number of weeks recorded,

(D)

print all revenues and expenses recorded,

(E)

print the largest revenue recorded, or

(F)

exit the program.

Solutions

Expert Solution

FinancialRecords.java

import java.util.Scanner;
class FinancialRecords{
   private double expenses[] = new double[250];
   private double revenues[] = new double[250];
   private int noOfWeeksRecorded=0;//tracks that number of weeks that have been recorded already
   private int largestRevenueIndex;//tracks largest revenue index that has been recorded
  
   public static void main(String a[]){
       FinancialRecords fr = new FinancialRecords();
       Scanner input = new Scanner(System.in);//to take input from user
       String choice;
       do{
           System.out.println("Enter 'F' to exit");
           System.out.println("A-Computed the total of all expenses since given week\nB-Add a new expense/revenue\nC-print the number of weeks recorded\nD-print all revenues and expenses recorded\nE-print the largest revenue recorded\nF-Exit the program");
           choice = input.next();
          
           if(choice.equals("A")){
           //asking user to enter a week number
               System.out.println("Enter a week number:");
               int num = input.nextInt();
               System.out.println(fr.calculateTotalExpenseSinceT(num));
           }
           else if(choice.equals("B")){
               //asking user to enter expense and revenue for next unrecorded week
               System.out.println("Enter Expense:");
               double expense = input.nextDouble();
               System.out.println("Enter Revenue:");
               double revenue = input.nextDouble();
              
               fr.recordExpensesAndRevenues(expense,revenue);
           }
           else if(choice.equals("C"))
           System.out.println("Number of weeks Recorded:"+fr.calculateNumberOfWeeksRecorded());
           else if(choice.equals("D"))
           fr.printAllExpensesAndRevenues();
           else if(choice.equals("E"))
           System.out.println("Largest Revenue:"+fr.revenues[fr.findLargestRevenueRecordIndex()]);
           else if(!choice.equals("F"))
           System.out.println("Enter valid Character!!!");//asking user to enter valid character that are A,B,C,D,E,F;
          
       }
       while(!choice.equals("F"));//loop untill user enters 'F';
   }
   public double calculateTotalExpenseSinceT(int weekNumber){
       //checking weeknumber is valid(>0) and must be less than or equal to number of weeks recorded
       if(weekNumber>=1 && weekNumber<=calculateNumberOfWeeksRecorded()){
           double total=0.0;
           for(int i=weekNumber-1;i<calculateNumberOfWeeksRecorded();i++){//adding all expenses since week number
               total+=expenses[i];
           }
           return total;
       }
       else{
           //user asking for unrecorded week expenses
           System.out.println("This week has not yet been recorded!!!");
           return -1.0;
       }
   }
   public void recordExpensesAndRevenues(double expense,double revenue){
       //checking if there is space in arrays to record
       if(calculateNumberOfWeeksRecorded()<250){
           this.expenses[calculateNumberOfWeeksRecorded()] = expense;
           this.revenues[calculateNumberOfWeeksRecorded()] = revenue;
          
           //for tracking largestRevenueIndex
           if(revenues[this.largestRevenueIndex]<revenue)
           this.largestRevenueIndex = this.noOfWeeksRecorded;
          
           this.noOfWeeksRecorded++;
           System.out.println("Record added successfully!");
       }
       else
       System.out.println("Sorry! there is no space to record!!!");
   }
  
   public int calculateNumberOfWeeksRecorded(){
       return this.noOfWeeksRecorded;
   }
   public void printAllExpensesAndRevenues(){
       System.out.println("Expenses Revenues");
       for(int i=0;i<calculateNumberOfWeeksRecorded();i++){
           System.out.println(expenses[i]+" "+revenues[i]);
       }
   }
   public int findLargestRevenueRecordIndex(){//returning largest revenue index
       return this.largestRevenueIndex;
   }
  
}


Related Solutions

An income statement is a report on a company’s financial performance over a period of time.
  Goodwill and Reported Net Income An income statement is a report on a company’s financial performance over a period of time. The measure of an amount that a company has earned during a period of time is known as net income. The income statement is the financial representation of the operating activities of a company during a period of time. Net income is the measure of an amount that a company has earned during a period of time. In...
Write a program that calculates the amount a person would earn over a period of time...
Write a program that calculates the amount a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should display a table showing the salary for each day, and then show the total pay at the end of the period. The output should be displayed in a dollar amount, not the number of pennies. Input Validation: Do not...
The Daniel Insurance Agency reported revenues of $29,000 and expenses of $31,000 for the current period....
The Daniel Insurance Agency reported revenues of $29,000 and expenses of $31,000 for the current period. What was the final figure reported on the company’s income statement? Multiple Choice $2,000 net loss $2,000 net income $29,000 net income $31,000 net loss
1. Revenues and expenses must be recorded in the accounting period in which they were earned...
1. Revenues and expenses must be recorded in the accounting period in which they were earned or incurred, no matter when cash receipts or outlays occur under which of the following accounting methods? a. accrual basis accounting b. cash basis accounting c. tax basis accounting d. revenue basis accounting 2. Which type of adjustment occurs when cash is not collected or paid, but the related income or expense is reportable in the current period? a. accrual b. deferral c. estimate...
The payroll records of Barnes Co. provided the following data for the current weekly pay period...
The payroll records of Barnes Co. provided the following data for the current weekly pay period ended March 12. Employees Earnings to End of Previous Week Gross Pay Federal Income Taxes Medical Insurance Deduction Union Dues United Way R.Short $5,800 $800 $120 $35 $10 $10 L. Skyler 6,850 1,000 180 35 10 15 C. Richard 12,900 1,440 404 35 10 10 The Earnings to End of Previous Week are gross earnings for the year prior to the current weekly pay...
Describe the difference between the Excess of Revenues over Expenses and the Increase in Unrestricted Net...
Describe the difference between the Excess of Revenues over Expenses and the Increase in Unrestricted Net Assets.
Under which method are revenues and expenses recognized in the same accounting period that cash receipts...
Under which method are revenues and expenses recognized in the same accounting period that cash receipts and payments occur? Under the cash basis of accounting Under the accrual basis of accounting Under the adjusting method of accounting Under both the cash and accrual basis of accounting
If project revenues do not cover expenses this is an example of: Select one: a. Financial...
If project revenues do not cover expenses this is an example of: Select one: a. Financial risk b. Cost estimate risk c. Market risk d. Promotion risk
Create a program wages.py that assumes people are paid double time for hours over 60. They...
Create a program wages.py that assumes people are paid double time for hours over 60. They get paid for at most 20 hours overtime at 1.5 times the normal rate. For example, a person working 65 hours with a regular wage of $10 per hour would work at $10 per hour for 40 hours, at 1.5 * $10 for 20 hours of overtime, and 2 * $10 for 5 hours of double time, for a total of 10*40 + 1.5*10*20...
​Marcy's Event Planning​ Services, Inc. records deferred expenses and deferred revenues using the alternative treatments. The...
​Marcy's Event Planning​ Services, Inc. records deferred expenses and deferred revenues using the alternative treatments. The business makes adjusting entries as needed to bring its books to the full accrual basis once a year at the end of the year. On October​ 1, Marcy's paid $ 3700 for insurance for a one-year period. At the end of the​ year, it will make an adjusting entry that debits Insurance Expense for $ 1542. True False
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT