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

I need to write a program that will allow a person to enter the number of votes

ID: 3620834 • Letter: I

Question

I need to write a program that will allow a person to enter the number of votes received for works of art. The program will then print out which piece is the winner. Once the user presses the "calculate" button, the program will update the window to indicate which piece received more votes. There should be a checkbox for each piece. Those pieces that are winners should have their checkbox marked. There can be ties as well. I have some code already but I am stuck. Feel free to do whatever you need to the code as I need help with this pretty bad. This is all in a GUI.

So it should look like this with the ending program:

Enter the number of votes for piece 1: 80 check boxes go here
Enter the number of votes for piece 2: 92 check boxes go here. Check mark
Enter the number of votes for piece 3: 74 check boxes go here
"Calculate Button" Piece 2 is the winner.

import javax.swing.JFrame;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;

public class ArtPrize {

private JLabel inputLabel, inputLabel2, inputLabel3, resultLabel;
private JTextField ArtPrize;


public static void main (String[] args)
{
int piece1, piece2, piece3, num = 0;

Scanner scan = new Scanner (System.in);

piece1 = scan.nextInt();
piece2 = scan.nextInt();
piece3 = scan.nextInt();

if(piece1>piece2 && piece1>piece3)
num = piece1;

if(piece2>piece3 && piece2>piece1)
num = piece2;

if(piece3>piece1 && piece3>piece2)
num = piece3;

String tieMessage = null;

if (piece1 == piece2) {
if (piece1 == piece3) {
tieMessage = "It's a tie between pieces 1,2 and 3";
} else {
tieMessage = "It's a tie between pieces 1 and 2";
}
} else if (piece1 == piece3) {
tieMessage = "It's a tie between pieces 1 and 3";
} else if (piece3 == piece2) {
tieMessage = "It's a tie between pieces 2 and 3";
}

if (tieMessage == null) {
// TODO
// USE YOUR LOGIC TO CHECK FOR MAXIMUM VOTES.
}
}


}

{
JFrame frame = new JFrame ("Art Prize");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

ArtPrizePanel = new ArtPrizePanel();

frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
{

inputLabel = new JLabel ("Enter the number of votes for piece 1:");
inputLabel2 = new JLabel ("Enter the number of votes for piece 2:");
inputLabel3 = new JLabel ("Enter the number of votes for piece 3:");
resultLabel = new JLabel ("-----");

ArtPrize = new JTextField (5);
ArtPrize.addActionListener (new ArtListener());

add (inputLabel);
add (inputLabel2);
add (inputLabel3);
add (resultLabel);

setPreferredSize (new Dimension(300, 200));
setBackground (Color.white);
}


Explanation / Answer

Dear User,

I hope the bellow information will helps to You !


import javax.swing.*;
import javax.swing.JOptionPane;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JCheckBox;
import java.awt.FlowLayout;


class ArtPrizeDemo extends JFrame
{
int num;
String result;
public ArtPrizeDemo()
{
String firstpiece = JOptionPane.showInputDialog("Enter first piece of votes : " );
int piece1 = Integer.parseInt(firstpiece);

String secondpiece = JOptionPane.showInputDialog("Enter second piece of votes : " );
int piece2 = Integer.parseInt(secondpiece);

String thirdpiece = JOptionPane.showInputDialog("Enter third piece of votes : " );
int piece3 = Integer.parseInt(thirdpiece);

if(piece1>piece2 && piece1>piece3)
{
num = piece1;
result = "piece 1";
}
else if(piece2>piece3 && piece2>piece1)
{
num = piece2;
result = "piece 2";
}
if(piece3>piece1 && piece3>piece2)
{
num = piece3;
result = "piece3 ";
}
JOptionPane.showMessageDialog(null," Enter the number of votes for piece 1 : " + piece1 + " " + " Enter the number of votes for piece 2 " + piece2 + " " + " Enter the number of votes for piece 3 : " + piece3+ " " + "Winner is " + result);


}

}

class ArtPrize
{
public static void main(String[] args)

{
ArtPrizeDemo frm = new ArtPrizeDemo();
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setSize(350,100);
frm.setVisible(true);
}

}