Question

In: Computer Science

Write a program that does the following:  Assume the canvas size of 500X500.  The...

Write a program that does the following:  Assume the canvas size of 500X500.  The program asks the user to enter a 3 digit number.  The program then checks the value of the first and last digit of the number.  If the first and last digits are even, it makes the background green and displays the three digit number at the mouse pointer.  If the two digits are odd, it makes the background red and displays the three digit number at the mouse pointer.  If the first digit is odd and the third is even, it makes the background blue and display the three digit number at the mouse pointer.  The number entered by the user is displayed at the mouse pointer at all times irrespective of the location of the mouse pointer. Hint: import javax.swing.JOptionPane; JOptionPane.showInputDialog("")

please help me solve this using processing java pde

Solutions

Expert Solution

Working code implemented in Java PDE and appropriate comments provided for better understanding.

main.pde:

import javax.swing.JOptionPane;

int number;
color c;

void setup(){
  size(500,500);
  //asking, reading number
  number=Integer.parseInt(JOptionPane.showInputDialog("Enter a three digit number: "));
  //assuming user will always enter a valid three digit number
  //fetching first digit by integer division of number by 100
  int first=number/100;
  //fetching last digit by modulo division by 10
  int last=number%10;
  
  //if first and last digits are even, assigning green color to c
  if(first%2==0 && last%2==0){
    c=color(0,255,0);
  }
  //if first and last digits are odd, assigning red color to c
  else if(first%2!=0 && last%2!=0){
    c=color(255,0,0);
  }
  //if first digit is odd and last digits is even, assigning blue color to c
  else if(first%2!=0 && last%2==0){
    c=color(0,0,255);
  }
  //there is still one more case which is not mentioned in the question, that is
  //if first digit is even and second is odd, since not specified any other, I'm 
  //using a default gray color
  else{
    c=color(200,200,200);
  }
}



void draw(){
  //using c as background color
  background(c);
  //using black fill color
  fill(0);
  //drawing number at mouse position
  text(""+number,mouseX,mouseY);
  
}

Sample Output Screenshots:


Related Solutions

Write a program that does the following:  Assume the canvas size of 500X500.  The...
Write a program that does the following:  Assume the canvas size of 500X500.  The program asks the user to enter a 3 digit number.  The program then checks the value of the first and last digit of the number.  If the first and last digits are even, it makes the background green and displays the three digit number at the mouse pointer.  If the two digits are odd, it makes the background red and displays...
Write a program in java processing. Write a program that does the following: · Assume the...
Write a program in java processing. Write a program that does the following: · Assume the canvas size of 500X500. · The program asks the user to enter a 3 digit number. · The program then checks the value of the first and last digit of the number. · If the first and last digits are even, it makes the background green and displays the three digit number at the mouse pointer. · If the two digits are odd, it...
You are to write a C++ program which does the following: Reads in the size of...
You are to write a C++ program which does the following: Reads in the size of a list of characters. Reads in the list of characters. Prints the list of characters in the opposite order read in. Prints the list of characters in the order read in. Sorts the list. Prints the sorted list. You may assume there will be no more than 1000 characters in the list. (You should use a constant to make this limit easily changeable.) You...
Write a program to insert the following elements into a hash table of size 17. The...
Write a program to insert the following elements into a hash table of size 17. The hash function is X mod 17 where X is the input element.   6, 12, 34, 29, 28, 11, 23, 7, 0, 33, 30, 45 Use linear probing to resolve any collisions.
Write an HTML/Javascript canvas program that displays a black dot in the center after the user...
Write an HTML/Javascript canvas program that displays a black dot in the center after the user presses the 's' button on the keyboard. Hint: Canvas size should be 500x500 and the black dot should only appear after pressing 's'.
Program specifics: Write a C++ program that does the following: a. Asks the user for the...
Program specifics: Write a C++ program that does the following: a. Asks the user for the distance to the pin and the depth of the green (both in yards). (Note: The pin is the hole in the green and the depth is the diameter of the green, assuming it is circular.) b. Asks the user for an integer club number from 2 to 10, where 10 is the pitching wedge (this club lifts the ball out of rough, sand, etc)....
Write a program that does the following in C++ 1 ) Write the following store data...
Write a program that does the following in C++ 1 ) Write the following store data to a file (should be in main) DC Tourism Expenses 100.20 Revenue 200.50 Maryland Tourism Expenses 150.33 Revenue 210.33 Virginia Tourism Expenses 140.00 Revenue 230.00 2 ) Print the following heading: (should be in heading function) Store name | Profit [Note: use setw to make sure all your columns line up properly] 3 ) Read the store data for one store (should be in...
Program a solver for the Towers of Hanoi problem presented below. Submit the following to canvas:...
Program a solver for the Towers of Hanoi problem presented below. Submit the following to canvas: Hanoi.java, Driver.java (contains your main method). This is an individual project. Students may discuss solutions to the problem but may not share code with one another. I will discuss this project during our next lecture. Rules: a) There are three Pillars (Pillar1, Pillar2, Pillar3). b) There are N number of disks of increasing size (disk size is indicated by an integer). c) At the...
Write a C program that does the following In this part, you will write more complicated...
Write a C program that does the following In this part, you will write more complicated functions. They will require parameters and return values. The purpose is to give you experience with these components, and to show you how functions can be used to break your code down into smaller parts. You will also get some more experience with iterating through arrays.Open repl project Lab: User-Defined Functions 2. Write a program that does the following: 1.(20 pts.) Allows the user...
Write a java program that does the following: a) The user will enter data such as...
Write a java program that does the following: a) The user will enter data such as client name and client balance. The user can stop inputting data by entering "stop". The program should store the user inputs as a data member of an array. The type of this array is a class named ClientData. Below the output should be displayed by the program. The parts in bold are inputs from the user and not hard coded in the program Client...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT