subject

Programming Activity 13-2
/* HanoiClient
* Anderson, Franceschi
*/
import javax. swing. JOptionPane;
import javax. swing. JFrame;
import java. awt. Graphics;
public class HanoiClient extends JFrame
{
private TowersOfHanoi tOfH;
boolean started = false;
public HanoiClient()
{
tOfH = new TowersOfHanoi(4);
setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE);
setSize(500, 300);
setVisible(true);
}
public TowersOfHanoi getTOfH()
{
return tOfH;
}
public void setStarted(boolean b)
{
started = b;
}
public void recursiveTOfH(int numDisks, int fromTower, int toTower, int useTower)
{
// Student writes the body of this method
//
// Using recursion, transfer numDisks disks from the tower
// fromTower to the tower toTower using the tower
// useTower
// The disks are numbered as follows: if we started with n disks,
// the disk at the top is disk # 1
// and the disk at the bottom is disk # n
// We call the moveDisk method inside the body of this method
// The moveDisk method moves one disk and takes 3 arguments:
// an int, representing the disk number to be moved
// an int, representing the tower to move the disk from
// an int, representing the tower to move the disk to
// So if these three variables are:
// diskNumber, fromTower, and toTower
// then the call to moveDisks will be:
// moveDisk(diskNumber, fromTower, toTower);
if (numDisks > 0)
{
// Student code starts here:
// 1. Move (numDisks - 1) disks from fromTower
// to useTower using toTower
// 2. Move one disk from fromTower to toTower
// Print a message to the screen, then
// call moveDisk in order to animate.
// 3. Move (numDisks - 1) disks from useTower to toTower
// using fromTower
}
// Base case: 0 disks to move ==> do nothing
//
// Student code ends here.
}
public void moveDisk(int diskNumber, int fromTower, int toTower)
{
repaint();
try
{
Thread. sleep(1000); // wait for the animation to finish
}
catch (Exception e)
{
}
// update parameters
tOfH. updateTowers(diskNumber, fromTower, toTower);
}
public void paint(Graphics g)
{
if (started)
{
super. paint(g);
tOfH. draw(g);
}
}
public int getNumberOfDisks()
{
boolean goodInput = false;
int numberDisks = 4; // will be reassigned - default is 4
while (!goodInput)
{
try
{
String answer = JOptionPane. showInputDialog(null, "Enter number of disks between 1 and 9");
if (answer != null)
{
numberDisks = Integer. parseInt(answer);
goodInput = true;
}
else
{
System. exit(0);
}
}
catch (Exception e)
{
}
}
return numberDisks;
}
public static void main(String[] args)
{
HanoiClient app = new HanoiClient()
// ask user for number of disks
while (true)
{
int numDisks = app. getNumberOfDisks();
(app. getTOfH()).setDisks(numDisks);
app. setStarted(true);
// start
app. recursiveTOfH((app. getTOfH()).getDisks(), 0, 2, 1);
// finish last step in animation
app. repaint();
System. out. println("Done\n");
// done
try
{
Thread. sleep(5000); // wait for the animation to finish
}
catch (Exception e)
{
}
JOptionPane. showMessageDialog(null, "Done");
}
}
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 02:00
What is the process in which the software development team compiles information to determine the final product.
Answers: 3
question
Computers and Technology, 22.06.2019 07:30
An endless cycle of creation and response on the internet is called
Answers: 1
question
Computers and Technology, 22.06.2019 08:10
Alook-up table used to convert pixel values to output values on a monitor. essentially, all pixels with a value of 190 or above are shown as white (i.e. 255), and all values with a value of 63 or less are shown as black (i.e. 0). in between the pixels are scaled so that a pixel with a value p is converted to a pixel of value 2/127 −+3969). if a pixel has a value of 170 originally, what value will be used to display the pixel on the monitor? if a value of 110 is used to display the pixel on the monitor, what was the original value of the pixel?
Answers: 1
question
Computers and Technology, 24.06.2019 16:50
Develop the program incrementally: a) start by reading and displaying each line of the input file to make sure you are reading the data set correctly. b) use the split string method to extract information from each line into a list. print the list to prove that this step is working correctly. d) convert the exam scores to type int and calculate the student’s average. display those items to prove this step is working correctly. e) create a tuple containing the six items for each student (name, exam scores, exam mean). display the tuples to prove this step is working correctly. (optionally, you may want to have the exam scores in a list so your tuple is (name, scores_list, f) append each tuple to a list. display the list to prove this step is working correctly. g) use the sort list method to re-order the tuples in the list. display the list to prove this step is working correctly. h) use a for statement to display the contents of the list as a table (with appropriate formatting). i) use a for statement to calculate the average of all scores on exam #1, then display the results. note that you could have calculated this average within the first loop, but we are explicitly requiring you to do this calculation by looping though your list of tuples. j) add the logic to calculate the average of all scores on exam #2, then display the results.
Answers: 2
You know the right answer?
Programming Activity 13-2
/* HanoiClient
* Anderson, Franceschi
*/
import...
Questions
question
Mathematics, 13.12.2020 23:00
question
German, 13.12.2020 23:00
question
Mathematics, 13.12.2020 23:00
question
Health, 13.12.2020 23:00