Question
Lesson 2 Lab Assignment - Java: Random Behavior What Will You Learn Use of more sophisticated methods Use of random numbers Contents Using the classes
Lesson 2 Lab Assignment - Java: Random Behavior
What Will You Learn
Use of more sophisticated methods
Use of random numbers
Contents
Using the classes from Lab 1, app and student, create a solution for implementing some kind of random behavior for your student. Suppose the student can be reading, surfing the web, or interacting with other students. You will need to check now and then to see what the student is doing. You will be asking the instance of the student class and what it is doing at certain time intervals.
You Will Need To:
Create a method in the class student that returns what the student is doing.
Have this method generate the behavior randomly. It cant return the same thing every time.
Implement a for loop in the application to call for the student behavior 20 times.
In a 20 minute period, you are going to check once a minute = 20 times.
Give a total count for each activity.
Calculate and display the percentage, of the twenty behaviors displayed, spent on each activity.
NOTES:
Do not add any new attributes or variables to the student class.
The only change to the student class should be the addition of the method.
No need to work with TIME functions in Java. We are making a simulation as if every count of the for loop is one minute.
Generate a report in the end summarizing what the student did in class.
Example:
John is reading
John is reading
..
John is interacting with peers
John is surfing
---------------------------------------
Suggestions
If you need some help, see below for some suggestions:
My suggestion below is a step-by-step solution. Try to implement each step, one at a time.
Start with one of the examples from lesson 01. The new method whatsUp() is one more method in the student class. The student class should still have everything as before (first name, etc, getName() methods, same constructor).
Create a method called whatsUp( ) in the student class. This method is going to return what the student is doing in class. At first, make it return always the same thing, a string for instance, surfing the web." Later, I will suggest how to return different things.
Change the app. Include a for loop, such as:
for (int j = 0; j
If you made it here and read my example with random numbers above, try to change the whatsUp method so that it returns different behaviors randomly.
Use integer variables to count the number of times each activity occurs.
Use float variables to calculate the percentage.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started