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
vagabundo [1.1K]
3 years ago
15

Add the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write

the definition of the function min in the class unorderedArrayListType and write a program to test this function.
Computers and Technology
1 answer:
marshall27 [118]3 years ago
7 0

Answer:

The Answer is given in the explanation section, See detailed explanations as comments within the code.

Explanation:

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

// The abstract class with the abstract method

public abstract class arrayListType {

   public abstract int smallestElement();

}

//Class to implement the the abstract method

class unorderedArrayListType{

   public  int smallestElement(){

       //Create the list of Intitial capacity of 5

       List<Integer> myList = new ArrayList<Integer>(5);

       //Add Elements to the list

       myList.add(3);

       myList.add(4);

       myList.add(1);

       myList.add(6);

       myList.add(7);

     

       //FInd the smallest integer and return it

       int smallestInt = Collections.min(myList);

       return smallestInt;

}

}

//Testing the class with a main method

class Testing {

   public static void main(String[] args) {

       // Creating an instance of the class unorderedArrayListType

   unorderedArrayListType list1 = new unorderedArrayListType();

   //Calling the method to print the smallest Integer in the List

       System.out.println(list1.smallestElement());

   }

}

You might be interested in
Spreadsheet software creates a ____, composed of a grid of columns and rows
Nostrana [21]
Spreadsheet software creates a worksheet, composed of a grid of columns and rows.
5 0
4 years ago
Flesh out the body of the print_seconds function so that it prints the total amount of seconds given the hours, minutes, and sec
goblinko [34]

Answer:

Step by step explanation along with code and output is provided below

Explanation:

#include<iostream>

using namespace std;

// print_seconds function that takes three input arguments hours, mints, and seconds. There are 60*60=3600 seconds in one hour and 60 seconds in a minute. Total seconds will be addition of these three  

void print_seconds(int hours, int mints, int seconds)

{

   int total_seconds= hours*3600 + mints*60 + seconds;

   cout<<"Total seconds are: "<<total_seconds<<endl;

}

// test code

// user inputs hours, minutes and seconds and can also leave any of them by  entering 0 that will not effect the program. Then function print_seconds is called to calculate and print the total seconds.

int main()

{

   int h,m,s;

   cout<<"enter hours if any or enter 0"<<endl;

   cin>>h;

   cout<<"enter mints if any or enter 0"<<endl;

   cin>>m;

   cout<<"enter seconds if any or enter 0"<<endl;

   cin>>s;

   print_seconds(h,m,s);

  return 0;

}

Output:

enter hours if any or enter 0

2

enter mints if any or enter 0

25

enter seconds if any or enter 0

10

Total seconds are: 8710

7 0
3 years ago
Kerry wants to save her file but give it a new name. Kerry should use the ____ command
nexus9112 [7]

Kerry should use the "save as" command.

7 0
3 years ago
How is steering different from turning ? Need help //:
kotykmax [81]

Turning you go make a turn steering is where you keep yourself on the road.

6 0
3 years ago
How do i divid 521 to the nearest tenth
Softa [21]

Answer:

520

Explanation:

take 521 round that to the nearest 10th and thats 520

8 0
4 years ago
Read 2 more answers
Other questions:
  • Colleen is creating a document with two minimal paragraphs of text comparing two business models for her company. She decides to
    14·2 answers
  • If a user has one column in a table and would like to make it into two columns which command should be used?
    8·2 answers
  • All phones must have a way of making and then terminating a connection to the phone network; however the exact procedure for doi
    12·1 answer
  • What is an example of technology that helps support the idea of continental drift.
    15·1 answer
  • An error condition consisting of an error in the passing of parameters -- a method passes or returns an unexpected value such as
    12·1 answer
  • When considering the best technology for its particular use, what should a business consider
    15·2 answers
  • You are doing a Diffie-Hellman-Merkle key exchange with Danny using generator 2 and prime 29. You pick the secret number 4. What
    14·1 answer
  • Which of the following should you press to insert a non-
    8·2 answers
  • We cannot imagine a life without the Internet. Imagine that you had to live without being connected to the Internet. Discuss the
    13·1 answer
  • True or false. A plug-in card is always required to support pc sound
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!