Question
convert Java to C++ rewrite code with C++ import java.awt.Color; import java.awt.Graphics; import java.awt.HeadlessException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.Timer; public
convert Java to C++
rewrite code with C++
import java.awt.Color;
import java.awt.Graphics;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame; import javax.swing.JOptionPane;
import javax.swing.Timer;
public class WithdrawThread extends JFrame implements Runnable { private Account account;
private double amount;
public WithdrawThread(Account account, double amount) {
this.account = account;
this.amount = amount;
setSize(360, 300);
setVisible(true);
setTitle("Withdraw");
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE); }
public void withdraw(double amount) {
double bal = account.getBalance();
if (amount > bal) {
System.out.print("Wrong amount");
}
bal -= amount;
account.setBalance(bal);
notifyAll();
System.out.print( "Withdraw " + amount + " new balance in thread number " + Thread.currentThread().getId() + " balance is " + bal); }
public synchronized void run() {
try { Thread.sleep(100); }
catch (InterruptedException e) {
e.printStackTrace(); }
try { withdraw(amount);
} catch (InterruptedException e) {
e.printStackTrace(); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started