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("")

help me solve this using pde processing java

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

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);
  
}

/*OUTPUT*/


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 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...
Write a program that does the following. It will ask the user to enter an integer...
Write a program that does the following. It will ask the user to enter an integer larger than 1, and the if entered integer is not larger than 1, it keeps prompting the user. After the user enters a valid integer, the program prints all the prime factors of the integer (including the repeated factors). For example, if the entered integer is 24, the program prints: 2 2 2 3 Run your program with the test cases where the entered...
Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored...
Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored in memory with base addresses at 1000, 2000 and 3000 respectively. int absoluteDifference(int x, int y) { int r; if (x > y) r = x - y; else r = y - x; return r; } int main() { for (int i=0; i < 10; i++) { int a = array1[i]; int b = array2[i]; int c = absoluteDifference(a, b); array3[i] = c;...
Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored...
Write the LEGv8 assembly program for following c program. Assume array1, array2 and array3 are stored in memory with base addresses at 1000, 2000 and 3000 respectively. int absoluteDifference(int x, int y) { int r; if (x > y) r = x - y; else r = y - x; return r; } int main() { for (int i=0; i < 10; i++) { int a = array1[i]; int b = array2[i]; int c = absoluteDifference(a, b); array3[i] = c;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT