Question

First, launch NetBeans and close any previous projects that may be open (at the top menu...

First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "MinMax" (without the quotation marks) that declares an array of doubles of length 5, and uses methods to populate the array with user input from the command line and to print out the max (highest) and min (lowest) values in the array. The methods that determine the max and min values may not use any built-in sort methods in Java. That is, you need to write the appropriate logic in those methods. NOTE: For this assignment and all future assignments that deal with methods, you should be calling the appropriate method to do the task indicated, rather than implementing the task logic in the main method itself.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

inputs should should be taken from comman line arguments.. here i am taking inputs as 50 51 56 49 77

public class MinMax
{
public static void main(String[] args) //args is a array of string type
{
double[] array=new double[5]; //decalring array of doubles with size=5
for(int i=0;i<5;i++) //this loop used to convert strings to doubles
{
array[i]=Double.parseDouble(args[i]); //convert string to double and store it in array
}
double max_value=max(array); //calling max method and store return values in max_variable
double min_value=min(array); //calling min method and store return values in max_variable

System.out.println("Maximum value in the array is "+max_value); //printing max value
System.out.println("Maximum value in the array is "+min_value); //printing min value
}
  
  
  
static double max(double[] array)
{
double max=array[0]; //max is a variable intially hold the value array[0]
  
for(int i=0;i<5;i++) //this loop used to find max value
{if(array[i]>max) //if condition execute only if array[i]>max
{max=array[i];} //then change the max =array[i]
}
return max; //return max value
}
  
static double min(double[] array)   
{
double min=array[0]; //min is a variable intially hold the value array[0]
  
for(int i=0;i<5;i++) //this loop used to find min value
{if(array[i]<min) //if condition execute only if array[i]<min
{min=array[i];} //then change the min =array[i]
}
return min; //return min value
}   
}

Add a comment
Know the answer?
Add Answer to:
First, launch NetBeans and close any previous projects that may be open (at the top menu...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • First, launch NetBeans and close any previous projects that may be open (at the top menu...

    First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "MultiDimensions" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the...

  • First, launch NetBeans and close any previous projects that may be open (at the top menu...

    First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create a new Java application called "PasswordChecker" (without the quotation marks) that gets a String of a single word from the user at the command line and checks whether the String, called inputPassword, conforms to the following password policy. The password must: Be 3 characters in length Include at least one uppercase character Include at least...

  • create a new Java application called "MinMax" (without the quotation marks) that declares an array of...

    create a new Java application called "MinMax" (without the quotation marks) that declares an array of doubles of length 5, and uses methods to populate the array with user input from the command line and to print out the max (highest) and min (lowest) values in the array.

  • In this problem you'll get to use one of Java's random number generators, java.util.Random (see the...

    In this problem you'll get to use one of Java's random number generators, java.util.Random (see the docs for Random). This class generates a random double precision number uniformly distributed in the range [0.0 ... 1.0). That is, the numbers go from 0 to 1, including 0 but excluding 1. It is a common need in Java programming to generate a random integer number that's uniformly distributed in the range of [0 ... n), such as we saw in the dice...

  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

  • You may not add any instance variables to any class, though you may create local variables...

    You may not add any instance variables to any class, though you may create local variables inside of a method to accomplish its task. No other methods should be created other than the ones listed here.    Step 1 Develop the following class: Class Name: CollegeDegree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String [ ] Name: courseCreditArray Access...

  • You may not add any instance variables to any class, though you may create local variables...

    You may not add any instance variables to any class, though you may create local variables inside of a method to accomplish its task. No other methods should be created other than the ones listed here. (I need step 2 please.) Step 1 Develop the following class: Class Name: CollegeDegree Access Modifier: public Instance variables Name: major Access modifier: private Data type: String Name: numberOfCourses Access modifier: private Data type: int Name: courseNameArray Access modifier: private Data type: String [...

  • In Java, Implement a class MyArray as defined below, to store an array of integers (int)....

    In Java, Implement a class MyArray as defined below, to store an array of integers (int). Many of its methods will be implemented using the principle of recursion. Users can create an object by default, in which case, the array should contain enough space to store 10 integer values. Obviously, the user can specify the size of the array s/he requires. Users may choose the third way of creating an object of type MyArray by making a copy of another...

  • Status Topic Interfaces Description Video Scene Problem Consider a video scene in which we want to...

    Status Topic Interfaces Description Video Scene Problem Consider a video scene in which we want to display several different types (classes) of objects. Let's say, we want to display three objects of type Deer, two objects of type Tree and one object of type Hill. Each of them contains a method called display. We would like to store their object references in a single array and then call their method display one by one in a loop. However, in Java,...

  • PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4...

    PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4 THE GAME STARTS 1=PLAY GAME, 2=SHOW GAME RULES, 3=SHOW PLAYER STATISTICS, AND 4=EXIT GAME WITH A GOODBYE MESSAGE.) PLAYERS NEED OPTION TO SHOW STATS(IN A DIFFERNT WINDOW-FOR OPTION 3)-GAME SHOULD BE rock, paper, scissor and SAW!! PLEASE USE A JAVA GRAPHICAL USER INTERFACE. MUST HAVE ROCK, PAPER, SCISSORS, AND SAW PLEASE This project requires students to create a design for a “Rock, Paper, Scissors,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT