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]
3 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]3 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
3. Choose the statement that best describes a ray. A ray extends forever in both directions. B ray is a part of a line with two
e-lub [12.9K]

Answer:

Ray is part of a line that starts at one point and extends forever in one direction.

Explanation:

In geometry, a ray can be defined as a part of a line that has a fixed starting point but no end-point. It can extend infinitely in one direction. On its way to infinity, a ray may pass through more than one point. The vertex of the angles is the starting point of the rays.

<u>Extra</u>

B. A part of a line with two endpoints?

line segment

A line segment has two endpoints. It contains these endpoints and all the points of the line between them. You can measure the length of a segment, but not of a line. A segment is named by its two endpoints, for example, ¯AB.

6 0
2 years ago
The two principal catalysts for the Information Age have been:________.
jok3333 [9.3K]

Answer:

The two principal catalysts for the Information Age have been computers and communication networks.

Explanation:

Since the invention of computers and internet, people can get the information they need faster than ever before due to the ease of use of both technologies and the relatively cheap price of acquiring the technology.

6 0
3 years ago
What runs horizontally and is identified with numbers?
kramer
D. the answer is Column 
6 0
3 years ago
Read 2 more answers
Write a program that asks the user to enter the amount s/he has budgeted for a month. The amount should be between 1000 and 2000
Elena-2011 [213]

Answer:

The program to this question can be given as:

Program:

  //import package for user input.

import java.util.*;      

//define class

public class Budget                      

{

public static void main(String [] a)            //define main method.

{

//creating Scanner class object.

Scanner ob =new Scanner(System.in);    

//define variable.      

double budgetamount=0, amountspent=0 ,difference=0,total=0,num=0 ;        

int count = 0;                            

System.out.println("How much have you budgeted for the month? :");        //print message.

budgetamount=ob.nextDouble();                             //taking input

       while(budgetamount != 0)           //checkig number greater then 4 digite.

       {

           budgetamount= budgetamount/10;        

           ++count;

       }

       if(count>4)                 //condition

       {

       System.out.println("enter each expense, then type -999 to quit: ");

       while(num!=-999)               //taking expense  

       {

       total=total+num;                 //totaling expense

       num=scan.nextDouble();                  

       }

       if(total<=budgetamount)           //condtion for over budget.

       {

       System.out.print("under budget:");         //print message

       System.out.print(budgetamount-total);

       }

       else

       {

       System.out.print("over budget:");              //for under budget

       System.out.print(total-budgetamount);

       }

       }

       else

       {

       System.out.println("not valid");        //message for number lessthen 4 digit.    

       }                                      

}

}

output:

How much have you budgeted for the month? : 1200.55.

enter each expense, then type -999 to quit: 365.89

556.90

339.98

-999

over budget:1262.77

Explanation:

The explanation of this program can be given as:

In the above program we import the package in that is used for scanner class. This class is used for the input from the user after input we use the while loop and if-else statement. The while loop is the entry control loop It is used for input validation and if-else is used for the checking condition. Then we insert expense that is inserted by the user. Then we calculate under-budgeted and over-budgeted by conditional statement that is if-else. and at the last we print it.

5 0
3 years ago
Please help ASAP!
makkiz [27]
B. training is the correct answer
8 0
2 years ago
Other questions:
  • Peak download rate for a 4g network is __________. select one:
    12·2 answers
  • Use a one-dimensional array to solve the following problem: A company pays its salespeople on a commission basis. The salespeopl
    6·1 answer
  • Object-oriented programs employ a group of techniques for handling errors called ________ handling.
    12·1 answer
  • You are running out of storage space on one of your servers. you need to purchase an external hard drive, as there are no drive
    8·2 answers
  • Matt is a senior developer for Cyber Protect, a company that helps secure management information systems. Matt's new task is to
    8·1 answer
  • Which type of film would typically require the least amount of input from a screenwriter?
    10·1 answer
  • Information about hardware engineers?
    9·1 answer
  • Why is failure important when you are designing a solution to a problem?
    6·2 answers
  • The Binder Prime Company wants to recognize the employee who sold the most of its products during a specified period. Write a qu
    12·1 answer
  • ¿Cuáles aspectos serían los que más incidirían para que no se pudiera cumplir con el principio de imparcialidad en una auditoría
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!