FOURTH RESUBMISSION BECAUSE PEOPLE GIVE ME THE WRONG PROGRAM/SPAM. please don\'t
ID: 3829474 • Letter: F
Question
FOURTH RESUBMISSION BECAUSE PEOPLE GIVE ME THE WRONG PROGRAM/SPAM. please don't waste my question by giving me a wrong/incomplete program without my specifications.
I will pay $10 paypal for a program that compiles to my specifications.
Use imported Swing class to create Java GUI form to compare three types of loops.
1. for loop
2. while loop
3. do while loop
*****Must Include These Events
Form Load event
While Loop button Click event
For Loop button Click event
Do While Loop button Click event
Clear All button Click event
Attach Java code to form controls so application is user eventdriven.
************Please model the GUI after after these C# outputs with buttons, etc. These are just what I want it to look like. I want the program in java, not C#.
Here is my code so for a console app, I need it to be a GUI app
import java.text.SimpleDateFormat;
import java.util.Date;
public class CompareLoops {
//Declare & Initialize Variables
static double forLoopElapsedTime = 0;
static double whileLoopElapsedTime = 0;
static double doWhileLoopElapsedTime = 0;
//For Loop - Calculate Elapsed Time
public static void calculateForLoopElapsedTime()
{
System.out.println(" ==== For Loop Execution Time ======");
System.out.println("Start Time = " + new SimpleDateFormat("hh:mm:ss a").format(new Date()));
double startTime = System.currentTimeMillis();
long total = 0;
for (int i = 0; i < 10000000; i++)
{
total += i;
}
System.out.println("End Time = " + new SimpleDateFormat("hh:mm:ss a").format(new Date()));
double stopTime = System.currentTimeMillis();
forLoopElapsedTime = (stopTime - startTime)/1000;
System.out.println("While loop average elapsed time = " + forLoopElapsedTime + " seconds");
System.out.println("Completed Loops = " + total);
}
//While Loop - Calculate Elapsed Time
public static void calculateWhileLoopElapesdTime()
{
System.out.println(" ==== While Loop Execution Time ======");
System.out.println("Start Time = " + new SimpleDateFormat("hh:mm:ss a").format(new Date()));
double startTime = System.currentTimeMillis();
long total = 0;
long i = 0;
while(i < 10000000){
total += i;
i++;
}
System.out.println("End Time = " + new SimpleDateFormat("hh:mm:ss a").format(new Date()));
double stopTime = System.currentTimeMillis();
whileLoopElapsedTime = (stopTime - startTime)/1000;
System.out.println("Do While loop average elapsed time = " + whileLoopElapsedTime + " seconds");
System.out.println("Completed Loops = " + total);
}
//Do While Loop - Calculate Elapsed Time
public static void calculateDoWhileLoopElapsedTime()
{
System.out.println(" ==== Do While Loop Execution Time ======");
System.out.println("Start Time = " + new SimpleDateFormat("hh:mm:ss a").format(new Date()));
double startTime = System.currentTimeMillis();
long total = 0;
long i = 0;
do{
total += i;
i++;
}while(i < 10000000);
System.out.println("End Time = " + new SimpleDateFormat("hh:mm:ss a").format(new Date()));
double stopTime = System.currentTimeMillis();
doWhileLoopElapsedTime = (stopTime - startTime)/1000;
System.out.println("For loop average elapsed time = " + doWhileLoopElapsedTime + " seconds");
System.out.println("Completed Loops = " + total);
}
//Compare Elapsed Time
public static void compareElaspedTime()
{
System.out.print(" ");
if(forLoopElapsedTime < whileLoopElapsedTime){
if(forLoopElapsedTime < doWhileLoopElapsedTime){
System.out.println("Fastest execution time : For Loop " +forLoopElapsedTime+ " seconds");
}else{
System.out.println("Fastest execution time : Do While Loop " +doWhileLoopElapsedTime+ " seconds");
}
}else{
if(whileLoopElapsedTime < doWhileLoopElapsedTime){
System.out.println("Fastest execution time : While Loop " +whileLoopElapsedTime+ " seconds");
}else{
System.out.println("Fastest execution time : Do While Loop " +doWhileLoopElapsedTime+ " seconds");
}
}
}
public static void main(String[] args)
{
System.out.println("Average Elapsed Time for 10,000,000 loops in seconds");
System.out.println(" _________________________________ ");
calculateForLoopElapsedTime();
calculateWhileLoopElapesdTime();
calculateDoWhileLoopElapsedTime();
compareElaspedTime();
}
}
FOURTH RESUBMISSION BECAUSE PEOPLE GIVE ME THE WRONG PROGRAM/SPAM. please don't waste my question by giving me a wrong/incomplete program without my specifications.
Form when initially opened Compare Loop Statements Start Time End Time Elapsed Time number of seconds Completed Loops Do While Gear All While Loop For Loop Loop Elapsed Time for 10.000 Loops (in fraction of seconds Form after While Loop button is clicked Compare Loop Statements Start Time 11:45:52 AM End Time 11:45:53 AM Elapsed Time 1.406232000 number of seconds Completed Loops 10000000 Do While For Loop Clear All While Loop Loop Elapsed Time for 10 million Loops n number of seconds 1.406232000Explanation / Answer
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class Example extends JFrame {
public Example() {
initUI();
}
public final void initUI() {
JPanel panel = new JPanel();
getContentPane().add(panel);
panel.setLayout(null);
panel.setToolTipText("A Panel container");
JButton button = new JButton("Button");
button.setBounds(100, 60, 100, 30);
button.setToolTipText("A button component");
panel.add(button);
setTitle("Tooltip");
setSize(300, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
public void run() {
Example ex = new Example();
ex.setVisible(true);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.