1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
klemol [59]
2 years ago
14

Suppose that class OrderList has a private attribute double cost[100] which hold the cost of all ordered items, and a private at

tributes int num_of_items which hold the number of items ordered. For example, if num_of_items is 5, then cost[0], cost[1], ..., cost[4] hold the cost of these 5 items. Implement the member function named total_cost which returns the total cost of this OrderList.
Computers and Technology
1 answer:
harina [27]2 years ago
7 0

Answer:

<u>OrderList.java</u>

  1. public class OrderList {
  2.    private double cost[];
  3.    private int num_of_items;
  4.    
  5.    public OrderList(){
  6.        cost = new double[100];
  7.    }
  8.    public double total_cost(){
  9.        double total = 0;
  10.        for(int i=0; i < num_of_items; i++){
  11.            total += cost[i];
  12.        }
  13.        return total;
  14.    }
  15. }

<u>Main.java</u>

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        OrderList sample = new OrderList();
  4.        double totalCost = sample.total_cost();
  5.    }
  6. }

Explanation:

Firstly, define a class OrderList with two private attributes, cost and num_of_items (Line 1-3). In the constructor, initialize the cost attribute with a double type array with size 100. Next, create another method total_cost() to calculate the total cost of items (Line 9-15). To implement the total_cost member function, create an OrderList instance and use that instance to call the total_cost() and assign it to totalCost variable.

You might be interested in
Keisha wants to change the default printer before printing an e-mail. Which steps will accomplish this task?
Angelina_Jolie [31]

Answer:

The steps that will accomplish the task are;

On the File tab, clicking Print and choosing the desired printer from the Printer drop-down list

Explanation:

In steps required to change the default printer on Microsoft Outlook before printing as e-mail are as follows;

1) Select the File tab on the Menu bar

2) Click on the Print option on the File's Menu

3) From the Print window displayed under the File Menu in Microsoft Outlook select the desired printer from the Printer options drop-down list

The steps that will accomplish the task are On the File tab, clicking Print and choosing the desired printer from the Printer drop-down list.

8 0
3 years ago
if an individual inserts a thumb drive containing classified information on a computer in the office that is not part of the cla
KATRIN_1 [288]

Answer: Spillage

Explanation:

7 0
3 years ago
'|'/2`/ '|'[] |)[-([]|)[- '|'#!$
natita [175]

Answer: mr Man

Explanation:

7 0
3 years ago
Which technique is used to convert a color image to a black and white image?
Andrew [12]
Microscope
bc thats the answer
4 0
3 years ago
Which of the following are advantages of cloud computing?
Leona [35]
Hahahahaha lawllakad
7 0
3 years ago
Read 2 more answers
Other questions:
  • Which practice represents the trait of effective communication?
    6·2 answers
  • The approved systems design document is used by programmers, the personnel department, and information systems personnel.
    8·1 answer
  • What is ment by creative middle way solution
    6·1 answer
  • What is the standard internet protocol, which provides the technical foundation for the public internet?
    9·1 answer
  • Urgent ..algorithm and flowchart to check weather a number is odd or even ???​
    8·2 answers
  • Write a class called Person that has two data members - the person's name and age. It should have an init method that takes two
    12·1 answer
  • Was just testing how this works, no actual question; feel free to take the points anyways though. ​
    13·1 answer
  • What happened to the ten commandments tablets.
    9·1 answer
  • 8.1.4: Ghost Invasion!
    10·1 answer
  • Many large companies use the word(s), _____, to refer to the huge network of computers that meets their diverse computing needs.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!