Question

Create four classes, Trainee, JumpingCalculator, JumpingTraining, and TrainProgLoader. Save them to Trainee.java, JumpingCalculator.java, JumpingTraining.java, and TrainProgLoader.java....

Create four classes, Trainee, JumpingCalculator, JumpingTraining, and TrainProgLoader. Save them to Trainee.java, JumpingCalculator.java, JumpingTraining.java, and TrainProgLoader.java. Code the classes as specified as follows. Compile and run to test the program.

Trainee Class: This class represents a trainee.

Fields :

A private int data field named id;

A private String data field named name; o a private boolean data field named jumpTrain; o a private static int data field named numOfTrainee;

Methods:

A constructor that takes id and name as the parameters, and increments numOfTrainee by 1

A getName method that returns the name;

A static getNumOfTrainee method that returns the numOfTrainee field;

A setJumTrain method that takes a boolean parameter and sets the jumpTrain field;

A printInfo method that prints the three data fields: id, name, jumpTrain

JumpingCalculator Class: This class conducts the calculations.

Field:

A public static final double data field name g and is given a value 9.8. It is the gravity force.

Methods:

All the following three methods take two double parameters: velocity and angle. The angle is in degree. To convert degree to radians, use double Math.toRadians(degree). Read Projectile Motion Calculator to understand how the calculations are done.

A public static method distance that return a double value as the range of projectile;

A public static method timeOfFlight that return a double value as the time of flight;

A public static method height that return a double value as the maximum height.

JumpingTraining Class: This is the jumping training class that guides the user to pass the training.

Fields:

A public static final double data field named theDistance and is given a value 100.0.

Methods:

A public static method named run that takes no parameter and return a boolean value: true for pass and false for fail. o the run method first shows information on the criteria of passing the training, then prompts the user to input two double data: the velocity and the angle in degree;

The run method then calls the three methods in JumpingCalculator class, to calculate and display the jumping distance, jumping time, and jumping height;

The run method then decides whether the user passes the training or not, by checking if the jumping distance is within the specific range (between 95.0 and 105.0 in this case).

If the user passed the training, then terminates the method and returns true;

If the user failed the training, then asks the user if he would exit or continue.

If the user chooses to continue, then read the user's input again;

If the user chooses to exit, then terminate the method and return false.

TrainProgLoader Class: This class creates trainees and loads the JumpingTraining class.

Fields:

A public static final int data field named SIZE and is given a value of 3;

Methods:

The main method that does the following:

Creates a Trainee array containing a number of SIZE trainees (in this case 3 trainees);

Create the three members of the Trainee array, with id 1, 2, 3, and name "Neo", "Morpheus", and "Trinity";

Call the currentTrainee method to obtain user's choice of the id of current trainee;

If the user is a valid trainee (id exists), say hello to him, then load the jumping training program by calling the JumpingTraining class's run method;

Assign jumping training result (true=pass, false=fail) to the trainee by calling the trainee's setjumpTrain method;

Print the latest information of the trainee by calling the trainee's printInfo method.

a public static method named currentTrainee that:

Takes a Trainee array as the parameter;

Shows the number of trainees by calling Trainee's getNumOfTrainee method;

Shows each trainee's information by calling the trainee's printInfo method;

Asks the user to choose who he is, by giving the id number;

If the user's input is valid (id exists), then return the id number as an int value;

If the user's input is invalid, then ask the user to choose again;

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

Program

Trainee.java

/**
* Create a class Trainee
* with id,name and test status
* Her get and set trainee details
* @author deept
*
*/
public class Trainee {
   //Attributes
   private int id;
   private String name;
   private boolean jumpTrain;
   private static int numOfTrainee;
   //Constructor
   public Trainee(int id,String name) {
       this.id=id;
       this.name=name;
       numOfTrainee+=1;
       jumpTrain=false;
   }
   //Get name of the trainee
   public String getName() {
       return name;
   }
   //Get number of trainees
   public int getNumOfTrainee() {
       return numOfTrainee;
   }
   //Get id of the trainee
   public int getId() {
       return id;
   }
   //Set trainee test result
   public void setJumpTrain(boolean jumpTrain) {
       this.jumpTrain=jumpTrain;
   }
   //Display trainee detailes
   public void printInfo() {
       System.out.print("ID: "+id+", Name: "+name+", TestPassed=");
       if(jumpTrain) {
           System.out.println("True");
       }
       else {
           System.out.println("False");
       }
   }
}

JumpingCalculator.java

/**
* Class do calculatiions
* Here find juming distane , time and height
* @author deept
*
*/
public class JumpingCalculator {
   public static final double g=9.8;
   //Method return projectile distance
   public static double distance(double velocity,double angle) {
       return (2*Math.pow(velocity,2)*Math.sin(Math.toRadians(angle))*Math.cos(Math.toRadians(angle)))/g;
   }
   //Method return time taken
   public static double timeOfFlight(double velocity,double angle) {
       return (2*velocity*Math.sin(Math.toRadians(angle)))/g;
   }
   //Method return height
   public static double height(double velocity,double angle) {
       return (Math.pow(velocity,2)*Math.pow(Math.sin((2*Math.toRadians(angle))),2))/(2*g);
   }
}

JumpingTraining.java

import java.util.Scanner;
/**
* Class to rumn a test on trainee
* @author deept
*
*/
public class JumpingTraining {
   static final double theDistance=100.00;
   //Method get velocity and angle
   //Then calculate distance and check he/she passed or failes test
   public static boolean run() {
       char ch='N';
       Scanner sc=new Scanner(System.in);
       System.out.println("Criteria to pass the test:\n   Jumping distance between 95.00 and 105.00\n");
       do {
           System.out.print("Enter velocity: ");
           double velocity=sc.nextDouble();
           System.out.print("Enter angle in degree: ");
           double angle=sc.nextDouble();
           double distance=JumpingCalculator.distance(velocity, angle);
           double timeOfFlight=JumpingCalculator.timeOfFlight(velocity, angle);
           double height=JumpingCalculator.height(velocity, angle);
           if(distance>=95.00 && distance<=105.00) {
              
               return true;
           }
           else {
               sc.nextLine();
               System.out.println(distance);
               System.out.println("You failed!!!");
               System.out.print("\nDo you want to conitnue?(Y/N): ");
               ch=Character.toUpperCase(sc.nextLine().charAt(0));
               if(ch=='N') {
                   return false;
               }
           }
       }while(ch=='Y');
       return false;
   }
}

TrainProgLoader.java

import java.util.Scanner;
/**
* Driver class Create trainess set their test status and print information
* @author deept
*
*/
public class TrainProgLoader {
   public static final int SIZE=3;

   public static void main(String[] args) {
       //Creates a Trainee array containing a number of SIZE trainees
       Trainee[] trainees=new Trainee[] {new Trainee(1,"Neo"),new Trainee(2,"Morpheus"),new Trainee(3,"Trinity")};
       //Get a trainee
       int ind=currentTrainee(trainees);
       //Say hello
       System.out.println("\nHello "+trainees[ind].getName());
       //Set his training status
       trainees[ind].setJumpTrain(JumpingTraining.run());
       //Display trainee information
       System.out.println();
       trainees[ind].printInfo();
   }
   /*
   * Get id of the trainee
   * Check valid then return it's index
   * Otherwise repeat until get correct id
   */
public static int currentTrainee(Trainee[] trainees) {
   Scanner sc=new Scanner(System.in);
   int id;
   do {
       System.out.print("Enter id of the trainee: ");
       id=sc.nextInt();
       for(int i=0;i<trainees[0].getNumOfTrainee();i++) {
           if(trainees[i].getId()==id) {
               return i;
           }
       }
       System.out.println("\nInvalid id.Please try again...");
   }while(true);
}
}

-------------------------------------------------------------------

Output

Enter id of the trainee: 4

Invalid id.Please try again...
Enter id of the trainee: 3

Hello Trinity
Criteria to pass the test:
   Jumping distance between 95.00 and 105.00

Enter velocity: 34
Enter angle in degree: 60

ID: 3, Name: Trinity, TestPassed=True

Add a comment
Know the answer?
Add Answer to:
Create four classes, Trainee, JumpingCalculator, JumpingTraining, and TrainProgLoader. Save them to Trainee.java, JumpingCalculator.java, JumpingTraining.java, and TrainProgLoader.java....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create an abstract Student class for Parker University. The class contains fields for student ID number,...

    Create an abstract Student class for Parker University. The class contains fields for student ID number, last name, and annual tuition. Include a constructor that requires parameters for the ID number and name. Include get and set methods for each field; the setTuition() method is abstract. Create three Student subclasses named UndergraduateStudent, GraduateStudent, and StudentAtLarge, each with a unique setTuition() method. Tuition for an UndergraduateStudent is $4,000 per semester, tuition for a GraduateStudent is $6,000 per semester, and tuition for...

  • 1. Employees and overriding a class method The Java program (check below) utilizes a superclass named...

    1. Employees and overriding a class method The Java program (check below) utilizes a superclass named EmployeePerson (check below) and two derived classes, EmployeeManager (check below) and EmployeeStaff (check below), each of which extends the EmployeePerson class. The main program creates objects of type EmployeeManager and EmployeeStaff and prints those objects. Run the program, which prints manager data only using the EmployeePerson class' printInfo method. Modify the EmployeeStaff class to override the EmployeePerson class' printInfo method and print all the...

  • C++ Please create the class named BankAccount with the following properties below: // The BankAccount class...

    C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (name & ID), keeps track of a user's available balance. // It also keeps track of how many transactions (deposits and/or withdrawals) are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Please define method definitions for Accessors and Mutator functions below Private member variables string getName(); // No set...

  • LAB: Pet information (derived classes)

    LAB: Pet information (derived classes)The base class Pet has private fields petName, and petAge. The derived class Dog extends the Pet class and includes a private field for dogBreed. Complete main() to:create a generic pet and print information using printInfo().create a Dog pet, use printInfo() to print information, and add a statement to print the dog's breed using the getBreed() method.Ex. If the input is:Dobby 2 Kreacher 3 German Schnauzerthe output is:Pet Information:     Name: Dobby    Age: 2 Pet Information:     Name: Kreacher    Age: 3    Breed: German SchnauzerPetInformation.javaimport java.util.Scanner; public class PetInformation {    public static void main(String[] args) {       Scanner scnr = new Scanner(System.in);       Pet myPet = new Pet();       Dog myDog = new Dog();              String petName, dogName, dogBreed;       int petAge, dogAge;       petName = scnr.nextLine();       petAge = scnr.nextInt();       scnr.nextLine();...

  • This assignment attempts to model the social phenomenon twitter. It involves two main classes: Tweet and...

    This assignment attempts to model the social phenomenon twitter. It involves two main classes: Tweet and TweetManager. You will load a set of tweets from a local file into a List collection. You will perform some simple queries on this collection. The Tweet and the TweetManager classes must be in separate files and must not be in the Program.cs file. The Tweet Class The Tweet class consist of nine members that include two static ones (the members decorated with the...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

  • I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime)...

    I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime) Create three files to submit: • Payroll class.java -Base class definition • PayrollOvertime.jave - Derived class definition • ClientClass.java - contains main() method Implement the two user define classes with the following specifications: Payroll class (the base class) (4 pts) • 5 data fields(protected) o String name - Initialized in default constructor to "John Doe" o int ID - Initialized in default constructor to...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • Create a class Team to hold data about a college sports team. The Team class holds...

    Create a class Team to hold data about a college sports team. The Team class holds data fields for college name (such as Hampton College), sport (such as Soccer), and team name (such as Tigers). Include a constructor that takes parameters for each field, and get methods that return the values of the fields. Also include a public final static String named MOTTO and initialize it to Sportsmanship! Save the class in Team.java. Create a UML class diagram as well.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT