Question

In: Computer Science

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 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.

Solutions

Expert Solution

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 (note: mouse pointers are not visible while taking screenshots)*/


Related Solutions

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...
In java processing 3, write a program that draws a circle. The center of the circle...
In java processing 3, write a program that draws a circle. The center of the circle would be first point on the canvas where the mouse is pressed on it. While the mouse is pressed, the circle can be drawn by moving the mouse cursor farther than the first point that mouse was pressed (circle center). As soon as the code is run, a timer at the bottom of the canvas should start working. Also, the radius of the circle...
Write a program in java that does the following: Create a StudentRecord class that keeps the...
Write a program in java that does the following: Create a StudentRecord class that keeps the following information for a student: first name (String), last name (String), and balance (integer). Provide proper constructor, setter and getter methods. Read the student information (one student per line) from the input file “csc272input.txt”. The information in the file is listed below. You can use it to generate the input file yourself, or use the original input file that is available alone with this...
Write the program in java Write a program that does basic encrypting of text. You will...
Write the program in java Write a program that does basic encrypting of text. You will ask the user the filename of a text file which contains a few sentences of text. You will read this text file one character at a time, and change each letter to another one and write out to an output file. The conversion should be done a -> b, b->c , … z->a, A->B, B->C, …. Z->A. This means just shift each letter by...
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 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 the program in java. Develop a class RentCabin that does the following: (use JavaDoc comments)...
write the program in java. Develop a class RentCabin that does the following: (use JavaDoc comments) // declare the constructor that sets the type and rate based in the sqft parm        // set values based on sqft <1000 is small with $100 per night, // sqft between 1000 and 2000, mid-sized $200 per night, and // over 2000 as a large cabin with $300 per night        //declare getRate        //declare getType        //declare setRate with int rate parm...
Write a complete Java program that does the following: Open an input file named data.txt that...
Write a complete Java program that does the following: Open an input file named data.txt that consists of a series of unknown number of integers. If data.txt does not exist, give an appropriate error message and terminate the program. Define a constant MAX of value 100 and create an array of size MAX to hold items from the input file. Make sure your program will not generate ArrayIndexOutOfBounds exception. Open an output file named result.txt and write the array elements...
Write a simple Java program that does the following: 1) Declare a constant of type String...
Write a simple Java program that does the following: 1) Declare a constant of type String to hold the words "Oakland University". 2) Declare variables of the type stated, and Prompt the user to enter in the following information and store in the variables a. Their current GPA on a 4.0 scale, into a variable of type double b. The number of credits they have so far into a variable of type int c. The amount of tuition they paid...
write a Java program Write a program to assign a letter grade according to the following...
write a Java program Write a program to assign a letter grade according to the following scheme: A: total score >= 90 B: 80 <= total score < 90 C: 70 <= total score < 80 D: 60 <= total score < 70 F: total score < 60 Output - the student's total score (float, 2 decimals) and letter grade Testing - test your program with the following input data: test1 = 95; test2 = 80; final = 90; assignments...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT