Question

In: Computer Science

Assignment Purpose The purpose of this lab is to write a well-commented java program that demonstrates...

Assignment Purpose

The purpose of this lab is to write a well-commented java program that demonstrates the use of loops, and generation of random integers.

Instructions

  1. You are taking some time off from your paint business and currently are on vacation in Bahamas.
  2. You decide to write a Java program that generates 10 random numbers between 1 and 20 (all integers).
  3. You cannot use arrays (even if you know what they are) to store these numbers.
  4. It then picks up the largest number among them and prints a multiplication table until that number.
  5. While your program is generating random numbers, it keeps tracks of number of 6’s generated.
    1. If more than two 6’s are generated, your program should print “HURRAY!! DOUBLE SIXES GENERATED”.
    2. If two 6’s are not generated, it should print “SORRY!! DOUBLE SIXES NOT ENCOUNTERED”.

Sample Output 1

/*******************Bahamas Vacation Report BEGIN***************\

Generating random numbers……

4 6 3 11 9 2 6 20 11 3

“HURRAY!! DOUBLE SIXES GENERATED”

Largest random number is:           11

The multiplication table is as follows:

1    2          3          4          5          6      7          8          9          10

2    4          6          8          10        12      14        16        18        20

3    6          9          12        15        18      21        24        27        30

.

.

11 22        33        44        55        66      77        88        99        110

/*******************Bahamas Vacation Report END ***************\

Sample Output 2

/*******************Bahamas Vacation Report BEGIN***************\

Generating random numbers……

4 6 3 11 9 2 2 20 11 3

“SORRY!! DOUBLE SIXES NOT ENCOUNTERED”

Largest random number is:           11

The multiplication table is as follows:

1    2          3          4          5          6      7          8          9          10

2    4          6          8          10        12      14        16        18        20

3    6          9          12        15        18      21        24        27        30

.

.

11 22        33        44        55        66      77        88        99        110

/*******************Bahamas Vacation Report END ***************\

Solutions

Expert Solution

A complete functional program is given below in java. Also a screenshot of output is attached below.

import java.io.*;
import java.util.*;

public class Main{
  
public static void main(String args[])
{
//creating object of random class
Random rnd = new Random();
  
//creating a vector to store random numbers
Vector <Integer> v = new Vector();   
  
int min=1,max=20,count=0;
  
System.out.println("*******************Bahamas Vacation Report BEGIN***************");
System.out.println("Generating random numbers……");
  
/*this loop will generate random numbers between 1 and 20
add the generated random number in the vector
and check if the number is equal to 6, if yes: counter ++ */
for(int i=0;i<10;i++)
{   
int rand = rnd.nextInt((max-min)+1)+min;   
v.add(rand);
if(rand==6){
count++;
}
}
  
//printing the random numbers
//toString() and replace() methods are used to print
//vector elements without "[]" and comma.
System.out.println(v.toString().replace("[","").replace("]","").replace(",",""));
  
  
//checking if no of sixes is>2
if(count>=2)
{
System.out.println(" “HURRAY!! DOUBLE SIXES GENERATED” ");
}
else{
System.out.println(" “SORRY!! DOUBLE SIXES NOT ENCOUNTERED” ");
}
  
  
//finding and printing the maximum from random numbers
int largest = Collections.max(v);   
System.out.println("Largest random number is: "+largest);
  
//this loop will print the tables from 1 to largest number
for(int i=1;i<=largest;i++)
{
for(int j=1;j<=largest;j++)
{
System.out.print(i*j+"\t");
if(j>largest)
break;
}
System.out.println();
}
System.out.println("*******************Bahamas Vacation Report END ***************");
}
  
  
}


Related Solutions

Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of one dimensional arrays and methods.(Need Comment, Write by Java Code) Instructions Write a method rotateArray that is passed to an array, x, of integers (minimum 7 numbers) and an integer rotation count, n. x is an array filled with randomly generated integers between 1 and 100. The method creates a new array with the items of x moved forward by...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use and re-use of methods with input validation. Instructions It is quite interesting that most of us are likely to be able to read and comprehend words, even if the alphabets of these words are scrambled (two of them) given the fact that the first and last alphabets remain the same. For example, “I dn'ot gvie a dman for a man taht...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of one dimensional arrays and methods. Instructions Write a method rotateArray that is passed to an array, x, of integers (minimum 7 numbers) and an integer rotation count, n. x is an array filled with randomly generated integers between 1 and 100. The method creates a new array with the items of x moved forward by n Elements that are rotated...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of two dimensional arrays, input validation, and methods. (Write by Java Code, Need Comment) Instructions A theater seating chart is implemented as a two-dimensional array of ticket prices, like this: Seat Ticket Price 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of one dimensional arrays and methods. Instructions Write a method rotateArray that is passed to an array, x, of integers (minimum 7 numbers) and an integer rotation count, n. x is an array filled with randomly generated integers between 1 and 100. The method creates a new array with the items of x moved forward by n Elements that are rotated...
Assignment Purpose Write a well commented java program that demonstrates the use and re-use of methods...
Assignment Purpose Write a well commented java program that demonstrates the use and re-use of methods with input validation. Instructions It is quite interesting that most of us are likely to be able to read and comprehend words, even if the alphabets of these words are scrambled (two of them) given the fact that the first and last alphabets remain the same. For example, “I dn'ot gvie a dman for a man taht can olny sepll a wrod one way.”...
JAVA Lab Assignment #13:  Looping Lab with both types of loops. This lab demonstrates the use of...
JAVA Lab Assignment #13:  Looping Lab with both types of loops. This lab demonstrates the use of the While Loop and the Do While Loop as error checking mechanisms. You will be using each of these loops to solve the same problem. Please put them both in the same program. When you test the code, you will not see a difference in the way they execute - but there will be a difference in the logic when writing the code. You...
***This is done with Java programming*** Write a well-documented (commented) program, “ISBN,” that takes a 9-digit...
***This is done with Java programming*** Write a well-documented (commented) program, “ISBN,” that takes a 9-digit integer as a command-line argument, computes the checksum, and prints the ISBN number. You should use Java’s String data type to implement it. The International Standard Book Number (ISBN) is a 10-digit code that uniquely specifies a book. The rightmost digit is a checksum digit that can be uniquely determined from the other 9 digits, from the condition that d1 + 2d2 +3d3 +...
JAVA Write a program that demonstrates how various exceptions are caught with catch (Exception exception) This...
JAVA Write a program that demonstrates how various exceptions are caught with catch (Exception exception) This time, define classes ExceptionA (which inherits from class Exception) and ExceptionB (which inherits from class ExceptionA). In your program, create try blocks that throw exceptions of types ExceptionA, ExceptionB, NullPointerException and IOException. All exceptions should be caught with catch blocks specifying type Exception.
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT