Write and submit one complete Java program to solve the following requirements. Your program will employ packages (that is, source directories), and contain multiple source files. Because you are using packages, your code should be in a directory named “Greenhouse.” You should be able to compile your code using the command “javac Greenhouse\*.java” from a directory just below the Greenhouse directory.
In the program for this assignment, class names have been specified. You mustuse the supplied class name for both class and source file name (i.e. Animal will be in a file Animal.java). If a program specifies multiple classes, then each class should be in its own separate source file.
Greenhouse is a house in which many events could happen, for example, doors may open and close, windows may open and close, fans may turn on or off, lights may turn on or off, an alarm may sound, the thermostat may turn on or off, watering machines may start or stop, and so on. Each event has its own timer and jobs (hint: use a superclass with separate subclasses, and a thread). For example, the alarm may sound five times when the thermostat has failed, and the fans may not come on until this situation is resolved, even if the fans are supposed to be on. Different events may have different priorities.
At the very beginning, a greenhouse (i.e., an object/instance of the Greenhouseclass) has to read the operating plan from the file greenhouse_plan.txt. The contents and format of the file are listed below. Note: You cannot alter the format of this file, but you may add additional events when testing.
greenhouse_plans.txt:
priority=*,10
priority=Light,5
priority=Bell,1
priority=Thermostat,2
event=Thermostat,1000,*
event=Light,1000,1000
priority=Water,5
event=Water,3000,5000
test=Bell,1000
failed=Thermostat,7000
event=Water,8000,5000
event=Fan,10000,2000
The event file means the following. Priority events are ranked on a scale from 1 to 10, 1 being the highest. Events indicate the element that is the source of the event, such at the Water or Fan, with the first number representing when the event started (in ms) and the second number representing for how long the event goes on. For example, 'event=Light, 1000, 1000' means that the Light element will activate 1000ms into the program running and last for 1000ms before turning off.
The greenhouse should be able to restart the process if either of two conditions are met: (1) the user asks the greenhouse to do so; (2) the greenhouse catches an exception when doing jobs according to greenhouse_plan.txt —for example, if an event is not able to start because no specific event class is implemented. If the second condition occurs, the greenhouse will restart the process, skipping the instruction that caused the problem.
Provide the means to read classes from the file, and create classes from their names (hint: Class.forName()). Use the same methods to provide the capability to add new Event classes, and to modify any Event classes without recompiling the Greenhouse class. Note: You should not use inner classes for designing and developing Event classes. Test your program by adding at least two Eventclasses, and make any necessary changes to greenhouse_plan.txt.
Before the greenhouse restarts everything, it first has to turn off all events. You may need to use ArrayList or Vector to store the events (and scheduling information). Doing so will avoid the need for additional variables to represent different events, and will also allow you to have new Event classes anytime you want.
The following information has been provided for the question above:
NOTE: As per the question requirement, you have to put two classes(StudentGrades and StudentGradesTest ) in a single .java in this assignment. So, I placed complete executable code in a single class, that is "StudentGrades".
Screen shot of Java code:
Output:
Text format code:
//Header file section
import java.util.Random;
//Create a class name, StudentGrades
public class StudentGrades {
// 1) Declare variables
// a) Initialized the private class variable name
// 'studentCounter' (int) is initialized to zero.
private static int studentCounter = 0;
// b)Declare a private instance variable
// called ‘studentName’ (string)
private String studentName;
// c) Declare a private instance variable
// called 'scores'[array of double]
private double[] scores;
// d) Declare a private instance variable
// called 'courseLetterGrade
private String[][] coursesLetterGrade;
// 2) Method definition of getLetterGrade: It is used
score
// to return the corresponding letter grade
public static String getLetterGrade(double score) {
if ((score >= 90) & (score <= 100)) {
return "A";
} else if ((score >= 80) & (score <= 89.99))
{
return "B";
} else if ((score >= 70) & (score <= 79.99))
{
return "C";
} else if ((score >= 60) & (score <= 69.99))
{
return "D";
} else {
return "F";
}
}
// 3) Constructor with a parameter: It is used to
// increase the value of 'studentCounter'
public StudentGrades(String name) {
studentName = name;
studentCounter += 1;
coursesLetterGrade = new String[2][2];
}
// 4) Constructor with three parameters: It is used to
// increase the value of 'studentCounter'
public StudentGrades(String studentName, double[] scores,
String[] courses)
{
this.studentName = studentName;
this.scores = scores;
coursesLetterGrade = new
String[scores.length][2];
for (int i = 0; i < courses.length; i++) {
coursesLetterGrade[i][0] = courses[i];
coursesLetterGrade[i][1] =
getLetterGrade(scores[i]);
}
studentCounter += 1;
}
// 5) Method definition of getName: It returns
// the value of name
public String getName() {
return studentName;
}
// 6) Method definition of getAverageScore: It
// returns the average score
public double getAverageScore() {
double average = 0.0;
for (double score : scores) {
average += score;
}
return average / scores.length;
}
// 7) Method definition of displayGrades: It is used
// to display the student name, course name, letter
// grades and scores in a tabular format
public void displayGrades() {
System.out.println("Student Name: " +
studentName);
System.out.println(String.format("%-25s%20s%10s",
"Course Name", "Letter Grade",
"Score"));
for (int i = 0; i < scores.length; i++) {
System.out.println(
String.format("%-25s%16s%14.2f",
coursesLetterGrade[i][0],
coursesLetterGrade[i][1],
scores[i]));
}
}
// 8) Method definition of getStudentCounter: It
// returns the current value of 'studentCounter'
public static int getStudentCounter() {
return studentCounter;
}
// main method
public static void main(String[] args) {
try {
// Initialize an array of 5 student names
String[] names = { "Adam Smith", "Nusair
Ahmed",
"Muhammad Mustafa", "Christian
Thomsen",
"Debashish Roy" };
// Initialize an array of 5 courses
String[] courses = { "Java programming", "Data
Science",
"Database Systems", "Computer
Organization",
"Data Structure" };
// Initialize an array of , ns
double[] ns = { 90, 55, 35, 80, 99 };
for (int i = 0; i < names.length;
i++)
{
double[] nc = new
double[5];
Random random = new Random();
nc[0] = random.nextInt(9) + 40;
nc[1] = random.nextInt(9) + 60;
nc[2] = random.nextInt(9) + 70;
nc[3] = random.nextInt(9) + 80;
nc[4] = random.nextInt(9) + 90;
// Create a class name object
StudentGrades studentGrades = new
StudentGrades(
names[i], nc, courses);
studentGrades.displayGrades();
// Display output through call the
methods
System.out.println();
System.out.println(studentGrades.getName()
+ " Average Score: "
+
studentGrades.getAverageScore());
System.out.println(studentGrades.getName()
+ " Average Grade: "
+
StudentGrades.getLetterGrade(
studentGrades.getAverageScore()));
}
} catch (ArrayIndexOutOfBoundsException e)
{
}
}
}
Write and submit one complete Java program to solve the following requirements. Your program will employ...
4.3Learning Objective: To read and write text files. Instructions: This is complete program with one Java source code file named H01_43.java (your main class is named H01_43). Problem: Write a program that prompts the user for the name of a Java source code file (you may assume the file contains Java source code and has a .java filename extension; we will not test your program on non-Java source code files). The program shall read the source code file and output...
Your software should: Ask the user for the source directory and a destination. The source is the directory to be copied; the destination is the directory that will be the parent of the new copy. First your program should make a new directory in the new location with the same name as the source directory. (You may need to do something special for root directories if you are copying an entire disk. A root directory has no parent directory, and...
Convert Project #1 into a GUI program, following the following requirements: Provide two text fields: one receives the length of the sequence, and the second receive the sequence (each number separated by a comma). There may, or may not, be space in between the comma and the number element. Provide a clear button that has an event listener attached to it. When pressed, the two text fields are emptied. The event listener should be defined and implemented as an anonymous...
What to submit: your answers to exercises 2. Write a Java program to perform the following tasks: The program should ask the user for the name of an input file and the name of an output file. It should then open the input file as a text file (if the input file does not exist it should throw an exception) and read the contents line by line. It should also open the output file as a text file and write...
JAVA PROGRAM. Write a program to implement a class Clock whose getHours and getMinutes methods return the current time at your location. Also include a getTime method that returns a string with the hours and minutes by calling the getHours and getMinutes methods. Provide a subclass WorldClock whose constructor accepts a time offset. For example, if you livein California, a new WorldCLock(3) should show the time in NewYork, three time zones ahead. Include an Alarm feature in the Clock class....
Write a complete Java program in a file caled Module1Progrom.java that reads all the tokens from a file named dota.txt that is to be found in the same directory as the running program. The program should ignore al tokens that cannot be read as an integer and read only the ones that can. After reading all of the integers, the program should print all the integers back to the screen, one per line, from the smalest to the largest. For...
Prelab Exercises Your task is to write a Java program that will print out the following message (including the row of equal marks): Computer Science, Yes!!!! ========================= An outline of the program is below. Complete it as follows: a. In the documentation at the top, fill in the name of the file the program would be saved in and a brief description of what the program does. b. Add the code for the main method to do the printing. //...
For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...
Java coding help!
Write a program to simulate a bank which includes the following. Include a commented header section at the top of each class file which includes your name, and a brief description of the class and program. Create the following classes: Bank Customer Account At a minimum include the following data fields for each class: o Bank Routing number Customer First name Last name Account Account number Balance Minimum balance Overdraft fee At a minimum write the following...
Need to write the program..
In java language.
And That the program should be according to given scenario..
You need to design and implement the following structure for your organization. You must follow the instructions given below 1 - Name of you organization is your surname. For example, if your name is "Qasim Ali", then "Ali" will be organization name. 2- Organization and Person must be interfaces. 3 - Staff and infrastructure must be abstract classes. 4 - Rest of...