Question

In: Computer Science

Exercises 4. Using the IDE make a new project/program by changing SmallIO.java so that integers instead...

Exercises

4. Using the IDE make a new project/program by changing SmallIO.java so that integers instead of Strings are entered by the user.

5. Change the program so that it only loops until the number -999 is entered by the user.

6. Modify the last program so that it (a) keeps and displays a running total and the average so far of the entered numbers (b) displays the largest and the smallest numbers so far of the entered numbers.

NOTE: PART 4 AND 5 HAS BEEN DONE. IN PART 6a TOTAL HAS BEEN DONE YOU HAVE TO CALCULATE AVERAGE AND DO PART B. BELOW IS THE PROGRAM CONTINUE DOING IT FROM WHERE I LEFT. THANKS

package tutorial1;

import java.util.Scanner;

/**
*
* @author ML
*/
public class Tutorial1 {


  
public static void main(String[] args) {
  
Scanner keyboard = new Scanner(System.in);
int a = 0; // initialise to empty string
int total = 0;
  
while (a != -999){
//an infinite loop, use Ctrl-C to quit
System.out.println("Enter a line:"); //prompt
a= keyboard.nextInt(); ///accepts an integer
System.out.println("Your number: " + a);
  
//method caLLS
total = totalaverage(a, total);
System.out.println("Your total is: " + total);
  
System.out.println(); // print a blank line
} //end of while
  
  
}//end of main
// keeps and displays a running total and the average so far of the entered numbers
public static int totalaverage(int a, int total)
{

return total + a ;

  
}
  
  
  
  
  
  
  
}

Solutions

Expert Solution

If you have any problem with the code feel free to comment.i have highlighted the edited codes.

Program

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/**
*
* @author ML
*/
public class Test {

   public static void main(String[] args) {

       Scanner keyboard = new Scanner(System.in);
       int a = 0; // initialise to empty string
       int total = 0;

       // arraylist for holding as much valuye as possible
       ArrayList<Integer> list = new ArrayList<>();

       while (true) {
           // an infinite loop, use Ctrl-C to quit
           System.out.println("Enter a line:"); // prompt
           a = keyboard.nextInt(); /// accepts an integer

           if (a == -999)// quite condition
               break;

           System.out.println("Your number: " + a);

        list.add(a);

           // method caLLS
           total = totalaverage(a, total);
           System.out.println("Your total is: " + total);
           // showing the average in 2 decimal places
           System.out.printf("Average is: %.2f\n", (double) total / (double) list.size());
           // displaying max and min value
           System.out.println("Max value entered: " + Collections.max(list));
           System.out.println("Min value entered: " + Collections.min(list));

           System.out.println(); // print a blank line
       } // end of while

   }// end of main
// keeps and displays a running total and the average so far of the entered numbers

   public static int totalaverage(int a, int total) {

       return total + a;

   }

}

Output


Related Solutions

Modify the classes so that it accepts integers instead of characters. (If you understand the concept...
Modify the classes so that it accepts integers instead of characters. (If you understand the concept of generic classes, convert the Node and Linked List classes to a generic so that they can be instantiated with either integers or characters) JAVA Code class aNode { char data; aNode next; aNode(char mydata) { // Constructor data = mydata; next = null; } }; //----------------------------------------------------- class linkedList { aNode head; // Head of the linked list int size; linkedList() { // Constructor...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
Write this program using an IDE. Comment and style the code according to the CS 200...
Write this program using an IDE. Comment and style the code according to the CS 200 Style Guide. Submit the source code files (.java) below. Make sure your source files are encoded in UTF-8. Some strange compiler errors are due to the text encoding not being correct. Monster collector is a game of chance, where the user tries to collect monsters by guessing the correct numbers between 1 and 5. If the user doesn't guess the incorrect number, you catch...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using...
Using Eclipse IDE Create a Java Program/Class named MonthNames that will display the Month names using an array. 1. Create an array of string named MONTHS and assign it the values "January" through "December". All 12 months need to be in the array with the first element being "January", then "February", etc. 2. Using a loop, prompt me to enter an int variable of 1-12 to display the Month of the Year. Once you have the value, the program needs...
Write a Program using MPLAB IDE and XC8 compiler to do the followings: 1. When the...
Write a Program using MPLAB IDE and XC8 compiler to do the followings: 1. When the Program Starts it should send your Name and ID# to the Serial Port 2. Display the result on Tera Term. 3. Read PORTB buttons in an infinite loop (Main Loop which is the Read Buttons Loop), your program should not block when reading the Buttons except in De-bouncing.. But you need to de-bounce each button when pressed 3.1 If the user presses PORTB, RB0...
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A....
Create a Java Program to calculate luggage costs. USING ECLIPSE IDE The Business Rules are: A. Two bags per person are free. B. The Excess Bag Charge is $75 per bag. The program needs to do the following: 1. In your main method(),    Create integers to store the number of Passengers and also the total number of bags    Prompt for the number of passengers on a ticket.    Prompt for the total number of bags for all passengers...
Create a Java Program to show a savings account balance. using eclipse IDE This can be...
Create a Java Program to show a savings account balance. using eclipse IDE This can be done in the main() method. Create an int variable named currentBalance and assign it the value of 0. Create an int variable named amountToSaveEachMonth. Prompt "Enter amount to save each month:" and assign the result to the int variable in step 2. Create an int variable name numberOfMonthsToSave. Prompt "Enter the number of months to save:" and store the input value into the variable...
Using eclipse IDE, create a java project and call it applets. Create a package and call...
Using eclipse IDE, create a java project and call it applets. Create a package and call it multimedia. Download an image and save it in package folder. In the package, create a java applet where you load the image. Use the drawImage() method to display the image, scaled to different sizes. Create animation in Java using the image. In the same package folder, download a sound. Include the sound in your applets and make it repeated while the applet executes....
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format. Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class,...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a...
Create a new Java project named Program 4 Three Dimensional Shapes. In this project, create a package named threeDimensional and put all 3 of the classes discussed below in this package Include a header comment to EACH OF your files, as indicated in your instructions. Here's a link describing the header. Note that headers are not meant to be in Javadoc format. Note that Javadoc is a huge part of your grade for this assignment. Javadoc requires that every class,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT