Write a Java program for a college's admission office.
Your program should print a message "Accept" if the student has any of the following:
If the student does not meet any of the qualifications, print
"Reject".
Name the class file Admissions.java and save it in
your cs201 directory.
You can compose the admission condition by ANDing and ORing simpler
conditions. You will need to OR four conditions corresponding to the four
cases mentioned above. Each of the four conditions is, in turn, a combination
of two other conditions (one for the grade point average and one for the
admission test score).
To AND two or more simple conditions use the syntax
if (condition1 && condition2 && condition3) ... |
To OR two or more simple conditions use the syntax
if (condition1 || condition2 || condition3) ... |
Modify your program to be run from console but provide a graphics interface to read the point average and the admission test score. For this you will need to perform the following steps:
import javax.swing.JOptionPane; // graphics dialog package
public class Admissions2
{
public static void main(String[] args)
{
// enter the grade point average
String s = JOptionPane.showInputDialog("Enter the point average");
double gpa = Double.parseDouble(s); // parse the input string to double
// enter the admission test score
s = JOptionPane.showInputDialog("Enter the admission test score");
int ats = Integer.parseInt(s); // parse the input string to int
// put your conditional statements
// from the first task here
// use the following code to print the rejection message
JOptionPane.showMessageDialog(null, "Reject", "Results",
JOptionPane.INFORMATION_MESSAGE);
// use the following code to print the acceptance message
JOptionPane.showMessageDialog(null, "Accept", "Results",
JOptionPane.INFORMATION_MESSAGE);
}
}
|
Now do the compilation and launch from the command line interface.
cd "My Documents"\NetBeansProjects\Admissions2 |
PATH_TO_JAVA\javac Admissions2.java |
C:\"Program Files"\Java\jdk1.8.0_77\bin\java |
On your Windows system the path is mostly likely different. Find it with "My Computer" tool by exploring the "Program Files" folder.
Hence, to run the code I would enter the following instruction:C:\"Program Files"\Java\jdk1.8.0_77\bin\java Admissions2 |
PATH_TO_JAVA\java Admissions2 |
You can launch the application designed in Part II not just from a command line, but also over the network. Even more wonderful, is that no modification of the Java program is needed. This is possible due to the Java Network Launch Protocol (JNLP) that is supported by the Java plugin and most of the browsers. Change to your public_html folder on cs2.uwsuper.edu server.
Main-Class: Admissions2 |
jar -cvfm Admissions2.jar Admissions2.mf Admissions2.class |
<?xml version="1.0" encoding="ISO-8859-1"?> <jnlp spec="1.0+" codebase="http://cs2.uwsuper.edu/~your_login/"> <information> <title>Admissions Office</title> <vendor>CSCI 201</vendor> <description>Launching the Admission Application</description> </information> <resources> <j2se version="1.5+"/> <jar href="Admissions2.jar"/> </resources> <application-desc main-class="Admissions2"> </application-desc> </jnlp> |
http://cs2.uwsuper.edu/~your_login/admissions2.jnlp |
Does not work? Your browser has to be configured for Java Web Start. With modern browsers this step is most likely not needed, so skip it. Otherwise, You need to associate the application/x-java-jnlp-file MIME type with the javaws application (part of JRE). The configuration should be automatic after installing the JDK. If not, in the Firefox browser open the Edit -> Preferences menu and click on Downloads icon. Click the button View and edit Actions... in the Download Actions section. Make sure the following entry is set in the Actions table:
Extension | File Type | MIME Type | Action |
---|---|---|---|
JNLP | JNLP file | application/x-java-jnlp-file | PATH_TO_JAVAWS/javaws(.eve) |
Still does not work? You computer might be needed to be configured to run applets from external sites. Google for information on how to enable this feature (after all, I told you that this is a challenge).