I need the solution of questions 34 Its Writing a code for t


I need the solution of questions 3,4
It\'s Writing a code for the program Java Luna
3. Write a program that use a generate method gemerateNumber to generate a 4 digit number and pass it to a method rotatcRight that returns the number rotated by one digit to the right. Sample run: The randon generated nunber iss 3427 The hunter rotated two digita isi 2 The nunber rotated three digits 1 4273 The nunber rotated four digits is 3427 4. Write a program that helps teachers test their students in their knowledge with colors and shapes. The program consists of two classes Colorshape and testColorShape. Class ColorShape has two instant variables choiceColor and choiceShape (both int). Your class Mould also have a constractor and setMethod for the instant variables In your test class you should use Frames to show a shape of certain ol (for example a red square). You need to start first by asking about the shape and then about the color using J0ptionPane. Whether the answer is wrong or right the user should be shown another question (new colored shape) and you need to state that the answer was correct or incorrect. If the student enters a 0 as an answer (either fr color or shape) fr·question the program should exit mportant Notes: 1. Your need to generane the shapes and colors randomly using random 2. In onder to show the new shape for the new question, you need to set the IFrame as invisible, change the settings of your JPrame and then set it back to visible using the following command Application NtVisiblefalse), invisible Application wrVisitletin\"), v \"ible 3. When the user input a zeno in any field, the program will esit 4 If you faced a problem in closing the Prames use the following command 5. Your frame should be of reasonable sine and the shapes should be clear and 6 The wser should enter both choices then the program specifies if the answer System.esito centered is cormect or not

Solution

Please follow the code and comments for description :

CODE :

import java.util.Random; // package to get the reandom number

public class RandClass { // class to run the code

    public static void main(String[] args) { // driver method

        int number = (int) (Math.random() * 9000) + 1000; // line to generate the random number of 4 digits.
        System.out.println(\"The random number generated is : \" + number); // print the random number
        int rem, count = 0; // local varaibles
        while (count < 4) { // iterate over the count of the digits
            count++; // increment the count
            rem = number % 10; // get the last digit value
            number = number / 10; // get the remaining numbers
            number = rem * 1000 + number; // add the remainder to the first place
            System.out.println(\"The number rotated \" + (count) + \" digits is : \" + number); // print at each iteration
        }
    }
}


OUTPUT :

The random number generated is : 8412
The number rotated 1 digits is : 2841
The number rotated 2 digits is : 1284
The number rotated 3 digits is : 4128
The number rotated 4 digits is : 8412


Hope this is helpful.

 I need the solution of questions 3,4 It\'s Writing a code for the program Java Luna 3. Write a program that use a generate method gemerateNumber to generate a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site