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 can’t 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.
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.
1. 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).
2. 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.
3. Change the app. Include a for loopsuch as:
for (int j = 0; j < 20; j++)
{
// here, display what the student is doing using the whatsUp( ) method
// You should know how to do create an instance of a student,
// and display some basic information
// You will use something like st1.whatsUp() in your statement
}
4. 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.
5. Use integer variables to count the number of times each activity occurs.
6.Use float variables to calculate the percentage.
i have app.jave and student class.
class student
{
String firstName;
String lastName;
int age;
student (String informedFirstName, String
informedLastName, int informedAge)
{
firstName =
informedFirstName;
lastName = informedLastName;
age = informedAge;
}
String getName()
{
return firstName +" " +
lastName;
}
}
public class app
{
public static void main(String args[])
{
student st1 = new student("John", "Smith",
20);
System.out.println(st1.firstName);
}
}
package A1Q3;
import java.util.Random;
class student
{
String firstName;
String lastName;
int age;
student (String informedFirstName, String informedLastName, int informedAge)
{
firstName = informedFirstName;
lastName = informedLastName;
age = informedAge;
}
String getName()
{
return firstName +" " + lastName;
}
public void whatsUp(){
String arr[] = {"reading","interacting with peers","surfing"};
Random r = new Random();
int n = r.nextInt(3);
int count[] = new int[3];
for(int i=0;i<20;++i){
count[n]++;
System.out.println(firstName +" is " + arr[n]);
n = r.nextInt(3);
}
System.out.println(firstName +" was " + arr[0] + " "+count[0]*100.0/20 + " % of the time");
System.out.println(firstName +" was " + arr[1] + " "+count[1]*100.0/20 + " % of the time");
System.out.println(firstName +" was " + arr[2] + " "+count[2]*100.0/20 + " % of the time");
}
}
===================================================
public class app
{
public static void main(String args[])
{
student st1 = new student("John", "Smith", 20);
System.out.println(st1.firstName);
st1.whatsUp();
}
}
============================================
//Random import that will give us the random numbers
import java.util.Random;
class student
{
String firstName;
String lastName;
int age;
student (String informedFirstName, String informedLastName, int informedAge)
{
firstName = informedFirstName;
lastName = informedLastName;
age = informedAge;
}
String getName()
{
return firstName +" " + lastName;
}
//whatsUp method
public void whatsUp(){
//String array that will tell us what a
student can do
String arr[] = {"reading","interacting with
peers","surfing"};
//Random declaration
Random r = new Random();
//Give us the next random 0,1 and 2
int n = r.nextInt(3);
//Count will keep track of which random number was
chosen
int count[] = new int[3];
//Loop 20 times
for(int i=0;i<20;++i){
// if n chosen was 0 then count[0] = 1 , like wise we
keep track of how many times reading, surfing was
chosen
count[n]++;
//Based on the chosen number n, appropriate String is
printed , like if random number is 0 then arr[0] i.e
reading
System.out.println(firstName +" is " + arr[n]);
//Get the next random number either 0,1 or 2
n = r.nextInt(3);
}
//All done, now since we were keeping track of how many
times we chosen reading, surfing etc. We calculate
percentage
//Percentage of reading is (count[0]/20 )* 100, because
count[0] is for reading
System.out.println(firstName +" was " + arr[0] + "
"+count[0]*100.0/20 + " % of the time");
System.out.println(firstName +" was " + arr[1] + " "+count[1]*100.0/20 + " % of the time");
System.out.println(firstName +" was " + arr[2] + " "+count[2]*100.0/20 + " % of the time");
}
}
===================================================
public class app
{
public static void main(String args[])
{
student st1 = new student("John", "Smith", 20);
System.out.println(st1.firstName);
st1.whatsUp();
}
}
==========
See and let me know if its simple now. It doesnt deserve a negative
rating. ANSWER IS Absolutely correct.
Edit: As per
comments--------------------------------------------------------------------------
import java.util.Random;
class student {
String firstName;
String lastName;
int age;
static String arr[] = { "taking quiz", "reading",
"coding Java" };
student(String informedFirstName, String
informedLastName, int informedAge) {
firstName =
informedFirstName;
lastName = informedLastName;
age = informedAge;
}
String getName() {
return firstName + " " +
lastName;
}
public String whatsUp() {
Random r = new Random();
int n = r.nextInt(3);
return arr[n];
}
}
public class app {
public static void main(String args[]) {
student st1 = new student("Zack",
"Smith", 20);
String arr[] = { "taking quiz",
"reading", "coding Java" };
int count[] = new int[3];
for (int i = 0; i < 20; ++i)
{
String str =
st1.whatsUp();
System.out.println((i+1) + " - " + st1.firstName + " is " +
str);
if(str.equals(arr[0]))
count[0]++;
else
if(str.equals(arr[1]))
count[1]++;
else
count[2]++;
}
System.out.println(st1.firstName +
" was " + arr[0] + " " + count[0] * 100.0 / 20 + " % of the
time");
System.out.println(st1.firstName +
" was " + arr[1] + " " + count[1] * 100.0 / 20 + " % of the
time");
System.out.println(st1.firstName +
" was " + arr[2] + " " + count[2] * 100.0 / 20 + " % of the
time");
}
}
======================================================================
Using the classes from Lab 1, app and student, create a solution for implementing some kind...
Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...
Here is the code from the previous three steps:
#include <iostream>
using namespace std;
class Student
{
private:
//class variables
int ID;
string firstName,lastName;
public:
Student(int ID,string firstName,string lastName)
//constructor
{
this->ID=ID;
this->firstName=firstName;
this->lastName=lastName;
}
int getID() //getter method
{
return ID;
}
virtual string getType() = 0; //pure virtual function
virtual void printInfo() //virtual function to print basic details
of a student
{
cout << "Student type: " << getType() <<
endl;
cout << "Student ID: " << ID...
Deliverables
app.java, myJFrame.java, myJPanel.java and student.java as
requested below.
(Use the student.java class that you already have from previous
labs)
Contents
Based on the graphics you learned this week
Create an instance (an object, i.e., st1) of student in
myJPanel
Display his/her basic information
Display for 10 times what he/she is up to (using the method
whatIsUp() that your student class already has)
--------------------------------------------------------------------------------------------------
\\app.java
public class app
{
public static void main(String args[])
{
myJFrame mjf = new myJFrame();...
Key Takeaways
-To create 2 groups of 4 students (8 students in total)
-NEEDS random GPAs for each student
-No arrays
-------------------------------------
app.java, student.java, and
group.java as requested below.
Please use the diagram above to help answer the Question:
Create a project that:
Has a student class
Instance variables for Firstname, last name , and age
random generated GPA
methods to return getinfo and semesterGPA
Build upon the solutions of the previous labs (e.g., using
app.java and student.java)
You will...
For this lab assignment, you will be writing a few classes that can be used by an educator to grade multiple choice exams. It will give you experience using some Standard Java Classes (Strings, Lists, Maps), which you will need for future projects. The following are the required classes: Student – a Student object has three private instance variables: lastName, a String; firstName, a String; and average, a double. It has accessor methods for lastName and firstName, and an accessor...
Basic button tracking
Deliverables
Updated files for
app6.java
myJFrame6.java
myJPanel6.java
student.java
Contents
You can start with the files available here.
public class app6
{
public static void main(String args[])
{
myJFrame6 mjf = new myJFrame6();
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class myJFrame6 extends JFrame
{
myJPanel6 p6;
public myJFrame6 ()
{
super ("My First Frame");
//------------------------------------------------------
// Create components: Jpanel, JLabel and JTextField
p6 = new myJPanel6();
//------------------------------------------------------...
Objectives: GUI Tasks: In Lab 4, you have completed a typical function of music player -- sorting song lists. In this assignment, you are asked to design a graphic user interface (GUI) for this function. To start, create a Java project named CS235A4_YourName. Then, copy the class Singer and class Song from finished Lab 4 and paste into the created project (src folder). Define another class TestSongGUI to implement a GUI application of sorting songs. Your application must provide the...
Create a new project in BlueJ and name it LastName-lab8-appstore, e.g., Smith-lab8-appstore. If your App class from Lab 4 is fully functional, copy it into the project. (You can drag a file from File Explorer onto the BlueJ project window.) Otherwise, use the instructor's App class: Create a new class using the "New Class..." button and name it App. Open the App class to edit the source code. Select and delete all the source code so that the file is...
Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What This Assignment Is About? Classes (methods and attributes) • Objects Arrays of Primitive Values Arrays of Objects Recursion for and if Statements Selection Sort Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.) Use upper case for constants. • Use title case (first letter is upper case) for classes. Use lower case with uppercase...
Java Project In Brief... For this Java project, you will create a Java program for a school. The purpose is to create a report containing one or more classrooms. For each classroom, the report will contain: I need a code that works, runs and the packages are working as well The room number of the classroom. The teacher and the subject assigned to the classroom. A list of students assigned to the classroom including their student id and final grade....