
Need it asap please !!!
Will rate your answer!!!
Run the following Java code and explain what it does. Give the resulting image from the code using inputs 3,960 1,234 222,222 13,780
interface ArrayStackADT
{
public void pop();
public void push(Object a);
public void display();
public boolean isEmptyStack();
public boolean isFullStack();
}
class ArrayStackDataStrucClass<T> implements ArrayStackADT
{
// An object of type T is declared
final static int n=100;
T stack[];
int top=-1;
// Default constructor
ArrayStackDataStrucClass() {
this.stack = (T[]) new Integer[100];
}
//Overloaded Constructor
ArrayStackDataStrucClass(T obj[]) {
this.stack = obj;
}
@Override
public void push(Object obj)
{
T t1= (T) obj;
try
{
if(!isFullStack())
{
stack[++top]=t1;
}
}
catch(Exception e)
{
System.out.println("e");
}
}
@Override
public void pop()
{
T popper = null;
if(top<0)
{
System.out.println("Stack underflow");
return;
}
else
{
popper=stack[top];
top--;
//System.out.println("Popped element:" +popper);
}
}
@Override
public void display()
{
if(!isEmptyStack())
{
String str=" ";
for(int i=0; i<=top; i++)
str=str+" "+stack[i]+" <--";
System.out.println("Elements are:"+str);
}
}
@Override
public boolean isEmptyStack() {
if(top<0)
{
System.out.println("Stack is empty");
return true;
}
return false;
}
@Override
public boolean isFullStack() {
if(top==(n-1))
{
System.out.println(" Stack Overflow");
return true;
}
return false;
}
T peek()
{
if(!isEmptyStack())
{
return stack[top];
}
return null;
}
}
public class PrimeFactorizationDemoClass {
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr={2960,1234,222222,13780};
for(int ii=0;ii<arr.length;ii++)
{
int inputNum = arr[ii];
int num = inputNum;
Integer intObj1[] = new Integer[100];
try {
ArrayStackDataStrucClass<Integer> obj1 = new ArrayStackDataStrucClass(intObj1);
int top=-1, i;
// Print the number of 2s that divide n
while (num % 2 == 0) {
obj1.push(2);
num /= 2;
top++;
}
// num must be odd at this point. So we can
// skip one element (Note i = i +2)
for ( i = 3; i <= Math.sqrt(num); i += 2) {
// While i divides n, print i and divide n
while (num % i == 0) {
obj1.push(i);
num /= i;
top++;
}
}
// This condition is to handle the case whien
// num is a prime number greater than 2
if (num > 2)
{
obj1.push(num);
top++;
}
System.out.print("Prime Factor for "+inputNum+" is : ");
while(top != -1)
{
System.out.print(obj1.peek() );
if(top != 0)
System.out.print(" * " );
obj1.pop();
top--;
}
}catch(Exception e)
{
System.out.println(e.getMessage());
}
System.out.println("");
}
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

- Please help me with this. I am really struggling Please help me modify my java matching with the image provide below or at least fix the errors import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Game extends JFrame implements ActionListener { int hallo[][] = {{4,6,2}, {1,4,3}, {5,5,1}, {2,3,6}}; int rows = 4; int cols = 3; JButton pics[] = new JButton[rows*cols]; public Game() { setSize(600,600); JPanel grid = new JPanel(new GridLayout(rows,cols)); int m = 0; for(int i = 0; iarrow_forwardPlease help me with my assignment for computer science as I had all the dialog box pop up for me except for "Whew" what am I doing wrong? I am including with this message the coding block for the assignment. import java.awt.event.*;import javax.swing.*;public class MouseWhisperer extends JFrame implements MouseListener {MouseWhisperer() {super("COME CLOSER");setSize(300,100);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);addMouseListener(this);setVisible(true);}public void mouseClicked(MouseEvent e) { setTitle("OUCH"); }public void mousePressed(MouseEvent e) { setTitle("LET GO"); }public void mouseReleased(MouseEvent e) { setTitle("WHEW"); }public void mouseEntered(MouseEvent e) { setTitle("I SEE YOU"); }public void mouseExited(MouseEvent e) { setTitle("COME CLOSER"); }public static void main(String[] args) { new MouseWhisperer(); }} Please advice.arrow_forwardJava. See the attached image for the task.arrow_forward
- Computer Science Questionarrow_forwardDraw the four endpoints of the rectangles given in the java statements. 1. g.drawRect(600, 0, 200, 450)arrow_forwardIn Java import java.util.Scanner;public class Image {int numberOfPhotos; // photos on rolldouble fStop; // light let it 1.4,2.0,2.8 ... 16.0int iso; // sensativity to light 100,200, 600int filterNumber; // 1-6String subjectMatter;String color; // black and white or colorString location;boolean isblurry;public String looksBlurry(boolean key){if ( key == true){return "Photo is Blurry";}else{return "Photo is Clear";}}public void printPhotoDetails (String s1){Scanner br= new Scanner(System.in);String subjectMatter=s1;System.out.println("Data of Nature photos:");System.out.println("Enter number of photos:");numberOfPhotos= br.nextInt();int i=1;while(true){System.out.println("Enter Filter number of photos"+i+":");filterNumber= br.nextInt();System.out.println("Enter colour of photo"+i+ ":");String color= br.next();System.out.println("Enter focal length of photo"+i+":");fStop= br.nextInt();System.out.println("Enter location of photo"+i+":");String location= br.next();System.out.println("Enter…arrow_forward
- JAVA SWINGI have definied a straight TUBE as: int rectWidth = 25; // replace 50 with the desired width of the rectangleint rectHeight = 200; // replace 200 with the desired height of the rectangleint rectX = (this.getWidth() - rectWidth) / 2;int rectY = (this.getHeight() - rectHeight) / 2;game.fillRect(rectX, rectY, rectWidth, rectHeight);I need L tube, which connects the straight tubes. How to define L tubes?arrow_forwardIn Java, design a class that models a 6-sided die. The die will be used in a game. Simulate a roll of the die, return a random value from {1,2,3,4,5,6}.arrow_forwardYou have to use comment function to describe what each line does import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class PreferenceData { private final List<Student> students; private final List<Project> projects; private int[][] preferences; private static enum ReadState { STUDENT_MODE, PROJECT_MODE, PREFERENCE_MODE, UNKNOWN; }; public PreferenceData() { super(); this.students = new ArrayList<Student>(); this.projects = new ArrayList<Project>(); } public void addStudent(Student s) { this.students.add(s); } public void addStudent(String s) { this.addStudent(Student.createStudent(s)); } public void addProject(Project p) { this.projects.add(p); } public void addProject(String p) { this.addProject(Project.createProject(p)); } public void createPreferenceMatrix() { this.preferences = new…arrow_forward
- can you please solve this ? Adopting suitable Java primitives and based on the least significant digit of your ID, implement one of the following shapes: (the car image is the one i need) b) Snapshot the output of a) c) Use suitable rendering to fill-in the shape suitably using suitable and well aligned-texture to reflect the real shape of your drawing.arrow_forwardJava programarrow_forwardJava. Please use the template in the picture.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





