Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need this one to be done in ECLIPSE OXIGEN. With the window Builder option. Pl

ID: 3919595 • Letter: I

Question

I need this one to be done in ECLIPSE OXIGEN. With the window Builder option. Please help on this one. Is to get ready for my final test, and I have to use Window Builder Option in eclipse. Thanks

I did provide the pics at the bottom.

Spring 2018 CSIS 1410 Final Skills being tested Loops Branches Action Listeners GUI Construction and Properties Attention to Detail · Project Overview Create a coin flipper program that can either flip the coin one at a time or a batch of flips. Below is the interface. Run Multiple Flips Heads Tails:

Explanation / Answer

**********************************************

Flips.java

import java.util.Arrays;

import java.util.Random;

public class Flips {

int hCount = 0;

int tCount = 0;

String[] hAndT;

int no_of_flips = 1;

public Flips(int n) {

if(n > 0)

no_of_flips = n;

System.out.println(no_of_flips + "");

hAndT = flipCoin();

}

public String[] flipCoin() {

String[] coins = new String[no_of_flips];

Random rand = new Random();

for (int i = 0; i < coins.length; i++) {

int flips = rand.nextInt(2);

if (flips == 0) {

coins[i] = "Tail";

} else {

coins[i] = "Head";

}

}

return coins;

}

public void headsCount() {

System.out.println();

System.out.println("Heads");

System.out.println("=====");

for (int i = 0; i < hAndT.length; i++) {

if (hAndT[i].equals("Head")) {

System.out.println("index " + i);

hCount++;

}

}

System.out.println("Total Heads: " + hCount);

}

public void tailsCount() {

System.out.println();

System.out.println("Tails");

System.out.println("=====");

for (int i = 0; i < hAndT.length; i++) {

if (hAndT[i].equals("Tail")) {

System.out.println("index " + i);

tCount++;

}

}

System.out.println("Total Tails: " + tCount);

}

public static void main(String[] args) {

}

}

**********************************************

CF.java

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.net.MalformedURLException;

import java.net.URL;

import java.util.Arrays;

import javax.swing.Icon;

import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JTextField;

import javax.swing.JPanel;

public class CF extends JFrame implements ActionListener {

JFrame window;

JPanel panel;

Icon icon, iconHead, iconTail, iconMultiple;

JLabel iconLabel;

JLabel tailsLabel;

JLabel headsLabel;

JButton clickButton;

JTextField textField;

JLabel lblLName;

public CF() throws MalformedURLException {

URL imageURL = new URL("file:///Users/Vipul/Desktop/que.png");

icon = new ImageIcon(imageURL);

URL imageURLHead = new URL("file:///Users/Vipul/Desktop/head.png");

iconHead = new ImageIcon(imageURLHead);

URL imageURLTail = new URL("file:///Users/Vipul/Desktop/tail.png");

iconTail = new ImageIcon(imageURLTail);

URL imageURLMultiple = new URL("file:///Users/Vipul/Desktop/multiple.png");

iconMultiple = new ImageIcon(imageURLMultiple);

iconLabel = new JLabel(icon);

window = new JFrame("Coin-Flipping Flips");

window.getContentPane().add(iconLabel);

window.pack();

window.setSize(500, 500);

window.setResizable(false);

window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

window.setLocationRelativeTo(null);

panel = new JPanel();

panel.setLayout(null);

window.add(panel);

lblLName = new JLabel("No of Flips: ");

lblLName.setBounds(50, 10, 100, 30);

textField = new JTextField(8);

textField.setBounds(150, 10, 100, 30);

textField.setText("1");

lblLName.setLabelFor(textField);

panel.add(lblLName);

panel.add(textField);

headsLabel = new JLabel("Heads: ");

headsLabel.setBounds(50, 400, 150, 30);

tailsLabel = new JLabel("Tails: ");

tailsLabel.setBounds(200, 400, 150, 30);

clickButton = new JButton("Flip");

clickButton.setBounds(350, 400, 80, 30);

clickButton.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

int n = Integer.parseInt(textField.getText());

Flips flip = new Flips(n);

flip.headsCount();

headsLabel.setText("Heads: " + flip.hCount);

flip.tailsCount();

tailsLabel.setText("Tails: " + flip.tCount);

if(n > 1) {

iconLabel.setIcon(iconMultiple);

} else {

iconLabel.setIcon(icon);

if(flip.hCount == 1)

iconLabel.setIcon(iconHead);

else

iconLabel.setIcon(iconTail);

}

}

});

panel.add(clickButton);

//panel.add(flipsLabel);

panel.add(tailsLabel);

panel.add(headsLabel);

window.setVisible(true);

}

public static void main(String[] args) {

}

@Override

public void actionPerformed(ActionEvent e) {

}

}

**********************************************

CFGame.java

import java.net.MalformedURLException;

public class CFGame {

public static void main(String[] args) throws MalformedURLException {

CF newGame = new CF();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote