Question
In Java. This is supposed to be a runable JAR file on windows 10. I cant seem to get it to run on eclipse or
In Java. This is supposed to be a runable JAR file on windows 10. I cant seem to get it to run on eclipse or the CMD line. please look at my code to see what i am missing or not understanding. thanks.
There are 5 classes below 1 is an fxml file.
--------------------------------------------------------------------------------
//Controller.java
package com.paycheck.controller;
import com.paycheck.entity.Employee; import com.paycheck.entity.Paycheck; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.DatePicker; import javafx.scene.control.TextField; import javafx.scene.text.Font; import javafx.stage.FileChooser;
import java.io.*; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List;
public class Controller {
@FXML public Button openBtnId;
@FXML public Button printPaycheckId;
@FXML public TextField nameId;
@FXML public DatePicker dateOfBirthId;
@FXML public TextField addressId;
@FXML public TextField yearsOfExperience;
@FXML public TextField welcomeId;
private Employee employee;
public void printPaycheckBtnAction(ActionEvent event) { if(employee != null) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Save Paycheck"); fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Text Files", "*.txt")); File file = fileChooser.showSaveDialog(null); if(file != null){ SaveFile(employee.toString(), file); } System.out.println(employee.toString()); } }
private void SaveFile(String content, File file){ try { FileWriter fileWriter = new FileWriter(file); fileWriter.write(content); fileWriter.close(); } catch (IOException ex) { } }
public void openBtnAction(ActionEvent actionEvent) { if (nameId.getText().isEmpty() || addressId.getText().isEmpty() || yearsOfExperience.getText().isEmpty()) { welcomeId.setFont(new Font("System", 15)); welcomeId.setText("Please input all fields"); return; }
FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("Open Resource File"); fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Text Files", "*.txt")); File selectedFile = fileChooser.showOpenDialog(null); if (selectedFile != null) {
welcomeId.setFont(new Font("System", 23)); welcomeId.setText("Welcome!");
List
}
private List
try (BufferedReader br = new BufferedReader(new FileReader(file))) { String line; while ((line = br.readLine()) != null) { list.add(line); } } catch (IOException e) { e.printStackTrace(); } return list; }
private int findWage(List
wage = Integer.parseInt(list.get(i).substring(list.get(i).indexOf('$'), list.get(i).length()).replaceAll("[^0-9]", "").trim()); break; } else { from = Integer.parseInt(list.get(i).substring(0, list.get(i).indexOf('')).trim()); to = Integer.parseInt(list.get(i).substring(list.get(i).indexOf('') + 1, list.get(i).indexOf('$')).trim()); } if ((experience >= from && experience <= to)) { wage = Integer.parseInt(list.get(i).substring(list.get(i).indexOf('$'), list.get(i).length()).replaceAll("[^0-9]", "").trim()); break; } } return wage; }
}
--------------------------------------------------------------------
//Employee.java
package com.paycheck.entity;
import static com.paycheck.entity.Paycheck.COUNT_ON_MONTH;
public class Employee { private String name; private String dateOfBirth; private String address; private int yearsOfExperience;
private Paycheck paycheck;
public Employee(String name, String dateOfBirth, String address, int yearsOfExperience) { this.name = name; this.dateOfBirth = dateOfBirth; this.address = address; this.yearsOfExperience = yearsOfExperience; }
public Employee(String name, String dateOfBirth, String address, int yearsOfExperience, Paycheck paycheck) { this.name = name; this.dateOfBirth = dateOfBirth; this.address = address; this.yearsOfExperience = yearsOfExperience; this.paycheck = paycheck; }
public String getName() { return name; }
public String getDateOfBirth() { return dateOfBirth; }
public String getAddress() { return address; }
public int getYearsOfExperience() { return yearsOfExperience; }
public Paycheck getPaycheck() { return paycheck; }
public void setPaycheck(Paycheck paycheck) { this.paycheck = paycheck; }
@Override public String toString() { return name + "\t\t" + "Sallary:$"+getPaycheck().grossPay()*COUNT_ON_MONTH + ' ' + address + "\t\t\t"+ String.format("FederalTax: $%.2f", getPaycheck().federalTax()) + ' ' + "\t\t\t\t\t" + String.format("Social Security: $%.2f", getPaycheck().socialSecurity()) +' ' + "\t\t\t\t\t" + String.format("Medicare: $%.2f", getPaycheck().medicare()) + ' ' + "\t\t\t\t\t" + String.format("Net Pay: $%.2f", getPaycheck().netPay()); } }
---------------------------------------------------------------------------------------------------------------
//Paycheck.java
package com.paycheck.entity;
public class Paycheck { static final int COUNT_ON_MONTH = 12; private double wage;
public Paycheck(double wage) { this.wage = wage; }
final double FED_TAX_10 = 0.10; final double FED_TAX_15 = 0.15; final double FED_TAX_25 = 0.25; final double FED_TAX_28 = 0.28; final double FED_TAX_33 = 0.33; final double FED_TAX_35 = 0.35; final double FED_TAX_39 = 0.396;
final double BRACKET_10 = 192; final double BRACKET_15 = 969; final double BRACKET_25 = 3354; final double BRACKET_28 = 7850; final double BRACKET_33 = 16163; final double BRACKET_35 = 34917; final double BRACKET_39 = 35058;
public double federalTax(){ double gross = grossPay();
if(gross>BRACKET_10 || gross
private double calcFederalTax(double tax){ return grossPay()*tax; }
public double grossPay(){ return wage/COUNT_ON_MONTH; }
public double socialSecurity(){ return grossPay()*0.12; }
public double medicare(){ return grossPay()*0.0145; }
public double netPay(){ return grossPay()-(federalTax()+socialSecurity()+medicare()); } }
-------------------------------------------------------------------------------------------------
//THIS IS THE fxml FILE
------------------------------------------------------------------
//Main.java
package com.paycheck;
import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage;
public class Main extends Application {
@Override public void start(Stage primaryStage) throws Exception{ Parent root = FXMLLoader.load(getClass().getResource("fxml/sample.fxml")); primaryStage.setTitle("Paycheck"); primaryStage.setScene(new Scene(root, 300, 300)); //primaryStage.setResizable(false); }
public static void main(String[] args) { launch(args); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started