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
What year did buck tooth bob become famous
victus00 [196]
I tried looking at other sites to even have an idea of who this is but I couldn't find anything, sorry
6 0
2 years ago
Read 2 more answers
What is the output of the second println statement in the main method? public class Foo { int i; static int s; public static voi
never [62]

Answer:

The second print statement will print:

f2.i is 1 f2.s is 2

Explanation:

Initially when the execution start. i and s are both 0. i declared as a variable while s is a static variable which value stays once it is re-defined.

When f1 call i and s; their value is both 1 based on the increment statement in the constructor.

For the second print statement:

When f2 call i; it is re-initialized to 1. When f2 call s; it has initial value of 1 and is incremented to 2 which is printed. s hold the initial value of 1 because of the static keyword.

6 0
3 years ago
"True or False? Software designers use layering and other techniques to organize large software systems."
grandymaker [24]

Answer:

True.

Explanation:

Software design can be defined as the process in which a designer or software developer uses a set of tools, techniques and components to create a graphical representation of a software that is intended to be used for solving a problem for the end users.

Hence, software designers use layering such as presentation, business, database, persistence layers and other techniques to organize large software systems.

6 0
2 years ago
While interoperability and unrestricted connectivity is an important trend in networking, the reality is that many diverse syste
iogann1982 [59]

Answer:

Middleware

Explanation:

In today's technology like networking, software development, web development, etc, there is a need for connectivity. The problem at hand is the variation of the tech brands which results in the difference in operating systems, applications, and connectivity protocols. This problem is solved with the introduction of Middleware.

Middleware is the solution to conflicting software applications, interconnectivity between various tech platforms. It promotes cross-platform interactions.

6 0
3 years ago
What does NOT match with Agile Manifesto?
Butoxors [25]

Answer:

yes

Explanation:

7 0
3 years ago
Other questions:
  • Why is it important to have regular maintenance and care of your office equipment?
    5·1 answer
  • What is the simplest way to permanently get rid of a unwanted file
    12·1 answer
  • 3. What are the first steps that you should take if you are unable to get onto the Internet? (1 point)
    15·1 answer
  • Software enables users to create documents
    13·1 answer
  • Which value can be entered to cause the following code segment to display the message: "That number is acceptable." int number;
    11·1 answer
  • The building blocks of coded language are called
    11·2 answers
  • In C, how could I use a command line input to remove certain characters from an existing string? For example, if I have string '
    8·1 answer
  • Computer software is regarded a bridge between the hardware and software.elaborate the statement outlining types and functions o
    10·1 answer
  • Plsss help anyone PLSSSSS ​
    13·1 answer
  • Ryo currently earns a monthly salary of $2200. She has been offered a raise of $250 per month. How much more will she earn per y
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!