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 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...
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...
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice)....
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice). This program will read in three integers with Scanner, put the values in an array of int, and then print the product of the three values. Example output of the program is shown below, with user input shown in bold: Enter first integer: 3 Enter second integer: 4 Enter third integer: 5 Product: 60 More details about the method you need to write are...
Given main() complete the Stack class by writing the methods push() and pop(). The stack uses...
Given main() complete the Stack class by writing the methods push() and pop(). The stack uses an array of size 5 to store elements. The command Push followed by a positive number pushes the number onto the stack. The command Pop pops the top element from the stack. Entering -1 exits the program. Ex. If the input is Push 1 Push 2 Push 3 Push 4 Push 5 Pop -1 the output is Stack contents (top to bottom): 1 Stack...
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...
The decimal values of the Roman numerals are: M D C L X V I 1000...
The decimal values of the Roman numerals are: M D C L X V I 1000 500 100 50 10 5 1 Remember, a larger numeral preceding a smaller numeral means addition, so LX is 60. A smaller numeral preceding a larger numeral means subtraction, so XL is 40. Assignment: Begin by creating a new project in the IDE of your choice. Your project should contain the following: Write a class romanType. An object of romanType should have the following...
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. ----------------------------------------------------------------------------------------------------------------------------------------------------------...
we defined, implemented, and tested a class Time. In this lab, we will continue working with...
we defined, implemented, and tested a class Time. In this lab, we will continue working with the Time class. A. Separate the class definition and class implementation from the client program. Move the class definition into a header file named Time.h and move the class implementation into a cpp file named Time.cpp. Use preprocessor directive to include header files as needed. B. Modify the Time class as follows: 1. Replace the default constructor and overloaded constructor with a constructor with...
Write a Java program that asks the user to enter an array of integers in the...
Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named isSorted that accepts an array of and returns true if the list is in sorted (increasing) order and false otherwise. For example, if arrays named arr1 and arr2 store [10, 20, 30, 41,...