• Home

JavaFx Application

you are a winner

Free cell phone

Risk free

For free

Satisfaction guaranteed

Order now

New customers only

No investment

Why pay more?

Pure profit

Click here

Free access

Get paid

For just

Best price

Income from home

you have won

Save up to

Increase traffic

totally free

lottery

congratulations

What are you waiting for

limited time offer

offer

free

credit card

instant approval

big money

send your details

make money

JavaFx Application

INSY 4306 Lab 3

Q1:


(Metric Conversions)

Write an application that will assist the user with metric conversion. Your application should allow the user to specify the names of the units as strings (i.e., centimeters, liters, grams, and so on, for the metric system and inches, quarts, pounds, and so on, for the English system) and should respond to simple questions, such as

“How many inches are in 2 meters?”

“How many liters are in 10 quarts?”

Your application should recognize invalid conversions. For example, the question

“How many feet are in 5 kilograms?”

is not meaningful because “feet” is a unit of length, whereas “kilograms” is a unit of mass.


Sample run 1

Please enter the source unit:

inches

Please enter the destination unit:

feet

Please enter the amount to convert

10

10 inches = 0.8333 feet


Sample run 2

Please enter the source unit:

feet

Please enter the destination unit:

gallons

Please enter the amount to convert

23

invalid conversion


Sample run 3

Please enter the source unit:

liters

Please enter the destination unit:

pints

Please enter the amount to convert

10

10 liters = 21.1338 pints


Sample run 4

Please enter the source unit:

ounces

Please enter the destination unit:

feet

Please enter the amount to convert

100

invalid conversion

Q 2:


(Spam Scanner)
Spam (or junk e-mail) costs U.S. organizations billions of dollars a year in spam-prevention software, equipment, network resources, bandwidth, and lost productivity. Research online some of the most common spam e-mail messages and words and check your own junk e-mail folder. Create a list of 30 words and phrases commonly found in spam messages. Write an application in which the user enters an e-mail message. Then, scan the message for each of the 30 keywords or phrases. For each occurrence of one of these within the message, add a point to the message’s message’s “spam score.” Next, rate the likelihood that the message is spam, based on the number of points it received.

list of spam words can be retrieved from:

http://www.wilsonweb.com/wmt8/spamfilter_phrases.htm


Sample run

Deliverables:

1. Source codes (.java files) – 90%

2. Screenshots of the program output – 10%

Note: Sparingly comment your java source code, save all the files in your_lastname_lab_3 folder, zip it, and upload for grading. Thank you!


Note:

·
if the program runs without any error and correct output. 100%

·
if the program runs without any error and incorrect output. 90%

·
if the program crashes due to error: up to 40% if the algorithm is ok

JavaFx Application

package com.example.spamchecker;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class SpamScanner extends Application {

static TextArea resultField;
static ArrayList<String> spamWordsList;

@Override
public void start(Stage primaryStage) throws Exception {
GridPane pane = new GridPane();
Scene scene = new Scene(pane);

pane.setPadding(new Insets(20));
pane.setHgap(10);
pane.setVgap(10);

TextArea inputText = new TextArea();
inputText.setWrapText(true);
pane.add(inputText, 0, 1, 3, 3);
Button checkButton = new Button(“Scan message”);
pane.add(checkButton, 0, 4);
Label label1 = new Label(“Score: “);
pane.add(label1, 1, 4);
Label label2 = new Label(“Spam likelihood: “);
pane.add(label2, 2, 4);
Button clearButton = new Button(“Clear”);
pane.add(clearButton, 3, 4);
resultField = new TextArea();
resultField.setPrefRowCount(3);
resultField.setEditable(false);
pane.add(resultField, 0, 5);
primaryStage.setTitle(“Spam Scanner”);
primaryStage.setScene(scene);
primaryStage.show();

readTextFile();

checkButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
String text = inputText.getText();
if (text == null || text.equals(“”)) {
resultField.setText(“Input can’t be blank!”);
} else {
String regex = “^[A-Za-z\\s]+$”;
Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(text);
if (matcher.find()) {
int spamScore = 0;
text = text.toLowerCase();
if (spamWordsList != null) {
for (String phrase : spamWordsList) {
if (text.contains(phrase.toLowerCase())) {
spamScore++;
}
}
if (spamScore == 0) {
resultField.setText(“Spam score is 0\n” + “The input doesn’t look like a spam message\n”);
} else {
if (spamScore > 0 && spamScore <= 3) {
resultField.setText(“Spam score is ” + spamScore + “\nThe message has some spammy words which can be avoided”);
} else if (spamScore > 3 && spamScore <= 6) {
resultField.setText(“Spam score is ” + spamScore + “\nThe message looks more like a spam”);
} else {
resultField.setText(“Spam score is ” + spamScore + “\nThis is definitely SPAM!!!”);
}
}
}
} else {
resultField.setText(“Invalid characters found! Type alphabets and spaces only”);
}
}
}
});

clearButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
inputText.setText(“”);
resultField.setText(“”);
}
});
}

static void readTextFile() {
try {
File file = new File(“C:\\Users\\singh\\OneDrive\\Documents\\spam.txt”);
Scanner scanner = new Scanner(file);
spamWordsList = new ArrayList<>();
while (scanner.hasNext()) {
spamWordsList.add(scanner.nextLine());
}
resultField.setText(“spam.txt file read successfully! Type the mail and press check button”);
} catch (FileNotFoundException ex) {
resultField.setText(“spam.txt file not found”);
}
}

public static void main(String[] args) {
launch(args);
}
}