JAVA Assignment: Only Need Answer for the FIRST PROGRAM! (implement the matrix u
ID: 3776560 • Letter: J
Question
JAVA Assignment: Only Need Answer for the FIRST PROGRAM! (implement the matrix using Swing)
Overview
For this assignment, you will submit two separate programs. Both programs will create a random matrix of 1s and 0s as illustrated in the textbook and the assignment example linked later in these instructions. The first program will implement the matrix using Swing. The second program will implement the matrix using JavaFX.
Instructions
In this assignment, you will develop multiple methods:
The main method
A method for greeting the user when the program begins
A method for creating and displaying the matrix
CHI Exercise!4-07 -lol- 011000101 01010000 1101001 0010010 000111000 x10-01-1000 0000110000 -| 1 0 1 1 1 0 0 1 0 0 0000-b, 1 1 1 1 1 0010100011 0101100110 1010010101 1111000000 0001000001 1100001011Explanation / Answer
import javax.swing.JOptionPane;
import javax.swing.*;
public class RandomMatrix {
// Main method
public static void main(String[] args) {
//Enter a number
String matrix = JOptionPane.showInputDialog("Enter no of rows:");
int m = Integer.parseInt(matrix);
String matrix1 = JOptionPane.showInputDialog("Enter no of columns");
int n = Integer.parseInt(matrix1);
//Display the matrix
generateMatrix(m,n);
}
//generate random 0's and 1's
public static void generateMatrix(int m,int n) {
//First For Loop to Represent the Operation for Row to Run "n" Number of Times (n rows)
for(int i = 1; i <= m; i++)
{
//Second For Loop to Represent the Operation for "n" Number of Columns for each row (n columns)
for(int j = 1; j <= n; j++)
{
//Generate Random Number 0 or 1
System.out.print((int)(Math.random() * 2) + " ");
}
//print to next line for new row
System.out.println();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.