Question: 1. Create a method called whatsUp ( ) in the student class. This method is going to return what the student is doing in class.
1. 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." The Answer Code MUST CONTAIN whatsUp method.
2. Change the app: include a for loop.
Create a method in the class student that returns what the student is doing.
This method has to 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 for 20 times.
In a 20 minute period, you are going to check every minute = 20 times.
(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 has done in class.
Example:
John is reading
John is reading
..
John is interacting with peers
John is surfing
package lab01;
class Student{
String name;
int age;
public Student() {
}
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public String toString(){
return "Name: "+this.name + " " ;
}
}
public class Lab01 {
public static void FindYoungest(Student s1[]){
int index = -1;
int age = Integer.MAX_VALUE;
for(int i=0;i if(s1[i].age < age){ age = s1[i].age; index = i; } } if(index!=-1){ System.out.println("The Youngest is:"); System.out.println(s1[index].toString()); } } public static void FindOldest(Student s1[]){ int index = -1; int age = Integer.MIN_VALUE; for(int i=0;i if(s1[i].age > age){ age = s1[i].age; index = i; } } if(index!=-1){ System.out.println("The Oldest is:"); System.out.println(s1[index].toString()); } } public static void main(String[] args) { Student st1 = new Student("John Smith",20); Student st2 = new Student("Zack Mills ",40); Student st3 = new Student("Fred Fonz",30); Student sArray[] = {st1,st2,st3}; FindYoungest(sArray); FindOldest(sArray); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
