Question

(Java) Below are three arrays each containing 50 values. Store all three arrays in the main...

(Java) Below are three arrays each containing 50 values. Store all three arrays in the main method. Write an object to transfer the three arrays.

int []num_wallet = {4, 3, 4, 2, 4, 6, 7, 2, 6, 1, 6, 1,1,5, 1, 4, 5, 4, 3, 2, 1, 2, 3, 3, 2, 3, 6, 5, 0, 0, 1, 3, 1, 5, 1, 0, 3, 0, 2, 1, 2, 3, 4, 1, 2, 0, 0, 1, 4, 1, 5};

int []dollar[] = {40, 50, 50, 36, 78, 32, 45, 20, 10, 45, 30, 34, 64, 70, 65, 24, 60, 69, 78, 90, 45, 20, 45, 70, 23, 54, 60, 32, 46, 23, 67, 30, 65, 30, 50, 46, 76, 34, 13, 40, 60, 36, 75, 52, 20, 23, 37, 25, 30, 20};

int []weekly_pay = {1501, 556, 540, 2440, 2240, 2451, 1430, 1730, 1801, 1501, 1301, 2510, 2440, 1450, 2700, 2550, 1000, 850, 400, 600, 450, 1300, 2050, 1000, 2250, 450, 1900, 800, 2500, 1000, 1200, 670, 1100, 1000, 450, 1000, 750, 2200, 2600, 1000, 2150, 450, 1250, 670, 800, 670, 2150, 1000, 2350, 670};

1) In the class file, write a method called dollaroption to compute the average dollar amount.

2) In the class file, write a method called walletoption to compute the average dollar amount of those who have exactly 3 wallets.

3) In the class file, write a method called payoption to compute the lowest dollar amount of those who have a weekly pay of $1000 to $2000

Homework Answers

Answer #1

Solution :

NOTE : If you have any problem regarding code, kindly let me know in the comment box, i will do the needful

//class to perform required operation
class Calc{
  int []num_wallet;
  int []dollar;
  int []weekly_pay;

  //constructor to assign values passed in main method
  Calc(int []num_wallet, int []dollar, int []weekly_pay){
    this.num_wallet=num_wallet;
    this.dollar = dollar;
    this.weekly_pay = weekly_pay;
  }
  //find the avg. dollar amount
  public void dollarOption(){
    double total_amt = 0.0;
    for(int i = 0; i<dollar.length;i++)
      total_amt+=dollar[i];
    double avg = total_amt/dollar.length;
    System.out.println("Average dollar amount is " + avg);
  }

  //find the average dollar amount of those who have exactly 3 wallets
  public void walletOption(){
    double total_amt = 0.0;
    int count = 0;
    for(int i = 0; i<num_wallet.length;i++){
      if(num_wallet[i] == 3){
        total_amt+=dollar[i];
        count++;
      }
    }
    System.out.println("Average dollar amount of those who have exactly 3 wallets is " + total_amt/count);
  }

  //find the lowest dollar having weekly pay between 1000 and 2000
  public void payoption(){
    int lowest = 9999;
    for(int i = 0;i<weekly_pay.length;i++){
      if(weekly_pay[i]>1000 && weekly_pay[i]<2000){
          if(dollar[i] < lowest)
            lowest = dollar[i];
      }
    }
    System.out.println("The lowest dollar amount of those who have a weekly pay of $1000 to $2000 is " + lowest);
  }
}
class Main {
  public static void main(String[] args) {
    int []num_wallet = {4, 3, 4, 2, 4, 6, 7, 2, 6, 1, 6, 1,1,5, 1, 4, 5, 4, 3, 2, 1, 2, 3, 3, 2, 3, 6, 5, 0, 0, 1, 3, 1, 5, 1, 0, 3, 0, 2, 1, 2, 3, 4, 1, 2, 0, 0, 1, 4, 1, 5};
    int []dollar = {40, 50, 50, 36, 78, 32, 45, 20, 10, 45, 30, 34, 64, 70, 65, 24, 60, 69, 78, 90, 45, 20, 45, 70, 23, 54, 60, 32, 46, 23, 67, 30, 65, 30, 50, 46, 76, 34, 13, 40, 60, 36, 75, 52, 20, 23, 37, 25, 30, 20};
    int []weekly_pay = {1501, 556, 540, 2440, 2240, 2451, 1430, 1730, 1801, 1501, 1301, 2510, 2440, 1450, 2700, 2550, 1000, 850, 400, 600, 450, 1300, 2050, 1000, 2250, 450, 1900, 800, 2500, 1000, 1200, 670, 1100, 1000, 450, 1000, 750, 2200, 2600, 1000, 2150, 450, 1250, 670, 800, 670, 2150, 1000, 2350, 670};

    Calc ob = new Calc(num_wallet, dollar, weekly_pay);
    ob.dollarOption();
    ob.walletOption();
    ob.payoption();
  }
}

Output :

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
JAVA please Arrays are a very powerful data structure with which you must become very familiar....
JAVA please Arrays are a very powerful data structure with which you must become very familiar. Arrays hold more than one object. The objects must be of the same type. If the array is an integer array then all the objects in the array must be integers. The object in the array is associated with an integer index which can be used to locate the object. The first object of the array has index 0. There are many problems where...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
PLEASE CODE EVERYTHING IN C++ Quick Thinking: Arrays Objective: Test your knowledge in providing efficient solutions...
PLEASE CODE EVERYTHING IN C++ Quick Thinking: Arrays Objective: Test your knowledge in providing efficient solutions for operations on arrays. What you can use only: Loops These variables only const int SIZE = 4; int variable = 0, master array [SIZE][SIZE]; double average = 0.0, parallel array [SIZE]; One conditional statement per problem if needed Note: the conditional statement cannot contain an “else” or “else if’ Provide solutions to the following problem. Absolutely no hard coding can be used. ----------------------------------------------------------------------------------------------------------------------------------------------------------...
clemson This Excel file Undergrad Survey shows the data resulting from a survey of 50 undergraduate...
clemson This Excel file Undergrad Survey shows the data resulting from a survey of 50 undergraduate students at Clemson University. Majors of students in the survey are accounting (A), economics and finance (EF), management (M), marketing (MR), computer information systems (IS), other (O), and undecided (UN). "Number of affiliations" is the number of social networking sites at which the student is registered; "Spending" is the amount spent on textbooks for the current semester. The other variables are self-explanatory. We will...
In java create a dice game called sequences also known as straight shooter. Each player in...
In java create a dice game called sequences also known as straight shooter. Each player in turn rolls SIX dice and scores points for any sequence of CONSECUTIVE numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts. However, a throw that contains three 1's cancels out player's score and they mst start from 0. A total of scores is kept and the first player to reach 100 points,...
PYTHON population_file = open('populations.txt') # 1. Define a variable called total_population, assign 0 to this variable...
PYTHON population_file = open('populations.txt') # 1. Define a variable called total_population, assign 0 to this variable for line in population_file.readlines(): # 2. Add line to the total_population, convert line to an int first # 3. Close the population_file using the close() method total_population_file = open('total_population.txt', 'w') # 4. Use the write() method to write the total_population to the total_population_file. Convert total_population to a string # 5. Close the total_population_file using the close() method Require 1.Program creates a new file called...
Total Product Total Fixed Cost Total Variable Cost 0 $150 $   0 1 150 50 2...
Total Product Total Fixed Cost Total Variable Cost 0 $150 $   0 1 150 50 2 150 75 3 150 105 4 150 145 5 150 200 6 150 270 7 150 360 8 150 475 9 150 620 10 150 800 Based on the cost data given in the accompanying table, which of the price-quantity tables correctly represents the firm's short-run supply schedule? (a) (b) (c) (d) P Qs P Qs P Qs P Qs $20 1 $20 0...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
def count_evens(values: List[List[int]]) -> List[int]: """Return a list of counts of even numbers in each of...
def count_evens(values: List[List[int]]) -> List[int]: """Return a list of counts of even numbers in each of the inner lists of values.    >>> count_evens([[10, 20, 30]]) [3] >>> count_evens([[1, 2], [3], [4, 5, 6]]) [1, 0, 2] """