Question

In: Computer Science

20. Assume you have a Java Interface with a method has this signature: public double min(double......

20. Assume you have a Java Interface with a method has this signature:

public double min(double... grades);

Write the implementation of this method so that it returns the smallest of the grades. Show example on calling the method when you are done with the implementation.

Solutions

Expert Solution

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package settest;

import java.util.Scanner;

/**
 *
 * @author pihu
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package settest;

/**
 *
 * @author pihu
 */
public interface min_interface {
    public double min(double[] grades);
}





public class ImplInterface implements min_interface {
    public double min(double[] grades)
    {
        double min;
        min=grades[0];
        for(int i=1;i<grades.length;i++)
        {
            if(min>grades[i])
            {
                min=grades[i];
            }
        }
        return min;
    }
    public static void main(String args[])
    {
        System.out.println("Enter no of grades");
        ImplInterface impInterface=new ImplInterface();
        Scanner input=new Scanner(System.in);        
        int count=input.nextInt();
        double grade[]=new double[count];
        for(int i=0;i<count;i++)
        {
            System.out.println("Enter grade"+(i+1));
            double element=input.nextDouble();
            grade[i]=element;
        }
        System.out.println("Smallest Grades is "+impInterface.min(grade));
        
        
    }
}

Related Solutions

In Java. Create a class called FileSumWrapper with a method that has the signature public static...
In Java. Create a class called FileSumWrapper with a method that has the signature public static void handle(String filename, int lowerBound) Make this method call FileSum.read and make your method catch all the errors. FileSum.read is a method that takes a filename and a lower bound, then sums up all the numbers in that file that are equal to or above the given lower bound. FileSum : import java.io.File; import java.rmi.UnexpectedException; import java.util.Scanner; public class FileSum { public static int...
You have a program which has an interface for a remote public interface Remote { public...
You have a program which has an interface for a remote public interface Remote { public void on(); public void off(); public void setChannel(int channel); public int getChannel(); public void sleep(int numMinutes); } You've been working with a Spanish firm that wants to use your program, but they have a different interface public interface controlRemoto { public void enciende(); public void apague(); public void cambiaCanal(int channel); public int qualCanal(); public void duerme(int numMinutes); } Create an adapter/wrapper around controlRemoto to...
In Java Create an interface Create an interface Printing, which have a method getPageNumber () that...
In Java Create an interface Create an interface Printing, which have a method getPageNumber () that return page number of any printing. Create an abstract class named Novel that implements Printing. Include a String field for the novel's title and a double field for the novel price. Within the class, include a constructor that requires the novel title, and add two get methods--one that returns the title and one that returns the price. Include an abstract method named setPrice().. Create...
JAVA 1. Create an Interface Vehicle. Declare one public void method in it paint( ). 2....
JAVA 1. Create an Interface Vehicle. Declare one public void method in it paint( ). 2. Create a class Car. Implements Vehicle. It's paint() method prints "Car Painted". It's drive( ) method prints "Car Driven". 3. Create a class Bus. Implements Vehicle. It's paint() method prints "Bus Painted" . It's drive( ) method prints "Bus Driven".   4. Create a method AutoWork which accepts an object of type Vehicle. The method makes a call to the vehicle's paint( ) and drive()...
Create a class called FileSumWrapper with a method that has the signature public static void handle(String...
Create a class called FileSumWrapper with a method that has the signature public static void handle(String filename, int lowerBound). Make this method call FileSum.read and make your method catch all the errors. FileSum.read is a method that takes a filename and a lower bound, then sums up all the numbers in that file that are equal to or above the given lower bound. I'm unsure at how to incorporate the FileSum.read() method to even start anything. I also don't know...
Write a generic method in java code public static double jaccard(HashSet A, HashSet B) that on...
Write a generic method in java code public static double jaccard(HashSet A, HashSet B) that on input two sets represented as hash sets, returns their Jaccard similarity. The following are a few sample runs: Input :    A=1, 2, 3, 4,   B=2, 4, 6, 8 Return:   0.3333333333333333 Input :    A=Larry, Michael, Shaq, Kobe, LeBron                    B=Steve, Kobe, Shaq, LeBron, Steph, Jeremy, Michael Return:   0.5 Your method must have time complexity On and space complexity O1, where n is the size of...
write JAVA program have a public class named GeometricShapes that has the main() method. In the...
write JAVA program have a public class named GeometricShapes that has the main() method. In the main() method the user needs to select if he want 2D shapes or 3D shape -if user select 2D user needs to select the shape type (Square, Circle, or Triangle) after selected shape the user needs to specify whether to find the Area or the Perimeter or to find side-length (radius for the circles), accordingly the needed constructor is used. (using Polymorphism principle) -if...
Finish the following java question: Consider the following interface: interface Duty { public String getDuty(); }...
Finish the following java question: Consider the following interface: interface Duty { public String getDuty(); } Write a class called Student which implements Duty. Class Student adds 1 data field, id, and 2 methods, getId and setId, along with a 1-argument constructor. The duty of a Student is to study 40 hours a week. Write a class called Professor which implements Duty. Class Professor adds 1 data field, name, and 2 methods, getName and setName, along with a 1-argument constructor....
java: Given the definitions: public interface ActionListener { public void actionPerformed(ActionEvent e); } public JTextField {...
java: Given the definitions: public interface ActionListener { public void actionPerformed(ActionEvent e); } public JTextField { public JTextField(){} public void setText(String text) {} public String getText() {} } Write the code to create a JButton on the South of the window and a JTextField on the North. The first time you click on the button, it should print out “hello!” on the JTextField. For the second time, should show “hello!hello!”. For the third time, should show “hello!hello!hello!”.
Implement the following methods in Java: a. A method named MergeFileswith the following signature that gets...
Implement the following methods in Java: a. A method named MergeFileswith the following signature that gets two file names and write the content of the first file (sourceFile) into the beginning of the second file (destinationFile. For example, if sourceFile contains “Hello ” and destinationFile contains “World!”, this method must keep sourceFile as it is, but replace the content of the second file by “Hello World!”.public static voidMergeFiles(String sourceFile, String destinationFile) b. A recursive method with the following signature that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT