0

I work for the imaging department at the university I go to and one of the things we have to do is constantly copy/paste these canned responses when dealing with tickets before doubling back and filling in all the empty spaces with the information specific to that ticket. It was tedious enough to inspire me to make a java project in my free time to generate these responses with all the information filled in in an effort to save some time/practice coding.

In this project are two classes, one that holds all my ticket info and one that runs the main part of the program (Ticket.java and ThingThatWork.java respectively).

Ticket.java

package quickResponse;

import java.util.Scanner;

public class Ticket {
    Scanner scanner = new Scanner(System.in);   
    String make;
    String model;
    String whiteTag;
    String poNumber;
    String SN;
    String signatureName;
    
    public Ticket() {
        setMake("");
        setModel("");
        setWhiteTag("");
        setSN("");
        setSignatureName("");
    }
    
    public Ticket(String make, String model, String whiteTag) {
        setMake(make);
        setModel(model);
        setWhiteTag(whiteTag);
        setSN(SN);
        setSignatureName(signatureName);
    }
    
    public String getMake() {
        return make;
    }
    
    public String getModel() {
        return model;
    }
    
    public String getWhiteTag() {
        return whiteTag;
    }
    
    public String getPoNumber() {
        return poNumber;
    }
    public String getSN() {
        return SN;
    }
    public String getSignatureName() {
        return signatureName;
    }
    
    public void setMake(String make) {
        this.make = make;
    }
    
    public void setModel(String model) {
        this.model = model;
    }
    
    public void setWhiteTag(String whiteTag) {
        this.whiteTag = whiteTag;
    }
    
    public void setPoNumber(String poNumber) {
        this.poNumber = poNumber;
    }
    public void setSN(String SN) {
        this.SN = SN;
    }
    public void setSignatureName(String signatureName) {
        this.signatureName = signatureName;
    }
    
    public void ticketInfo(boolean typeOfImage) {
            scanner.nextLine();
            System.out.println("Make: ");
            setMake(scanner.nextLine());
            System.out.println("Model: ");
            setModel(scanner.nextLine());
            System.out.println("White Tag: ");
            setWhiteTag(scanner.nextLine());
            System.out.println("Serial Number: ");
            setSN(scanner.nextLine());
            if(typeOfImage == true) {
                System.out.println("PO Number: ");
                setPoNumber(scanner.nextLine());
        }
            System.out.println("Enter Name: ");
            setSignatureName(scanner.nextLine());
    }
    
    public boolean imageOrReimage() {
        int bool = 0;
        while(bool != 1 || bool != 2) {
            System.out.println("Is this computer for imaging or reimaging?");
            System.out.println("1. Imaging");
            System.out.println("2. Reimaging");
            bool = scanner.nextInt();
            
            if(bool >= 3) {
                System.out.println("Not a valid selection!");
            }
            else {
                if(bool == 1) {
                    return true;
                }
                if(bool == 2) {
                    return false;
                }
            }
        }
        return false;
    }
    
    public String desktopOrLaptop() {
        int bool = 0;
        while(bool != 1 || bool != 2) {
            System.out.println("Is this a laptop or desktop?");
            System.out.println("1. Laptop");
            System.out.println("2. Desktop");
            bool = scanner.nextInt();
            
            if(bool >= 3) {
                System.out.println("Not a valid selection!");
            }
            else {
                if(bool == 1) {
                    return "laptop";
                }
                if(bool == 2) {
                    return "desktop";
                }
            }
        }
        return " ";
    }
    
    
    
    public String generateTitle(boolean imageOrReimage) {
        if(imageOrReimage == true) {
            return "Image | "+getMake()+" "+getModel()+" | WT#: "+getWhiteTag()+" | PO#: "+getPoNumber();
        }
        else {
            return "Reimage | "+getMake()+" "+getModel()+" | WT#: "+getWhiteTag();
        }
    }
    
    public String generateMessageBody(boolean imageOrReimage, String desktopOrLaptop) {
        if (imageOrReimage == true) {
            return "Hello,\n\nWe've recieved a new "+getMake()+" "+getModel()+" with white inventory tag #"+
                    getWhiteTag()+" and PO#"+getPoNumber()+". Before we can begin working on this device, "+
                    "could you please answer the following questions for us:\n\n*Who will this "+desktopOrLaptop+
                    " be used by?\n*Where will this "+desktopOrLaptop+" be located?\n*Will any additional "+
                    "programs need to be installed? Please provide any licensing information for paid programs "+
                    "such as Adobe Acrobat Pro.\n\nThanks,\n"+getSignatureName()+"\nTechnology Support"
                    +"\nThe University of Tyler at Texas.";
        }
        else {
            return "Hello,\n\nWe have picked up a "+getMake()+" "+getModel()+" with white inventory tag #"+
                    getWhiteTag()+".\n\nJust for confirmation before we begin the reimaging process,"+
                    " could you please answer the following questions:\n\n*Will any data need to be"+
                    " backed up before it is wiped and reimaged?\n*Who will this device belong to, along"+
                    " with their room number location?\n*Will any additional programs need to be installed?"+
                    " Please provide the licensing information for paid programs such as Adobe Acrobat Pro."+
                    "\n\nThanks,\n"+getSignatureName()+"\nTechnology Support\nThe University of Texas at Tyler";
        }
    }
    
    public String generateWorkNotes(boolean imageOrReimage) {
        String string;
        string = "Make: "+getMake()+"\nModel: "+getModel()+"\nWhite Tag: "+getWhiteTag()
            +"\nS/N: "+getSN();
        if(imageOrReimage == true) {
            string = string+"\nPO Number: "+getPoNumber();
        }
        return string;
    }
    
    @Override
    public String toString() {
        return "Make: "+getMake()+"\nModel: "+getModel()+"\nWhite Tag: "+getWhiteTag()
            +"\nS/N: "+getSN()+"\nPO Number: "+getPoNumber();   
    }
    @Override
    public boolean equals(Object o) {
        return toString().equals(o.toString());
    }
}

ThingThatWorks.java

package quickResponse;

public class ThingThatWorks {

    public static void main(String[] args) {
        Ticket newTicket = new Ticket();
        boolean imageOrReimage = false;
        String desktopOrLaptop = "";
        imageOrReimage = newTicket.imageOrReimage();
        newTicket.ticketInfo(imageOrReimage);
        
        if(imageOrReimage == true) 
            desktopOrLaptop = newTicket.desktopOrLaptop();
        
        System.out.println();
        System.out.println(newTicket.generateTitle(imageOrReimage));
        System.out.println();
        System.out.println(newTicket.generateMessageBody(imageOrReimage, desktopOrLaptop));
        System.out.println();
        System.out.println("---------------------------");
        System.out.println(newTicket.generateWorkNotes(imageOrReimage));
        
    }

}

I want to be able to transform this into either a runnable JAR or an .exe file so I can run it on my work computer when making tickets. Unfortunately what youtube videos I've watched aren't clear and when I just export the project as a runnable .jar file from Eclipse, it gives me a nonspecific JNI error (a JNI error has occurred, please check your installation and try again) and a nonspecific Java Exception error (A Java Exception has occurred). I'm not sure where I'm going wrong, nor am I sure if I have everything I need written in my code to throw up a cmd window, allow me to input what I need, and hang there long enough to let me copy it.

Any help would be appreciated.

Edit: Managed to get the errors to go away when I realized I was writing this in Java 17 and then compiling it via Java 8. I installed Java 17, re-exported the program, and now it does nothing when running instead of giving me errors.

One thing I have tried is running it via command line, but no matter what I do it gives me the error "Unable to access jarfile"

Edit 2: Adam's initial answer ended up being the key, I was trying to run it as java 8 when it complied as java 17. After ensuring that I was using the right version and not an outdated install, I managed to get the program working from command line.

Thank you all for the help

Manthor
  • 23
  • 4
  • Your `ThingThatWorks.java` file contains a class with a different name. Is this a typo from writing this question or was it the same way on your system? – Locke Sep 23 '22 at 18:51
  • It's the same way as on my system. I'm not sure what mean by that it 'contains a class with a different name,' unless you mean the class name itself. – Manthor Sep 23 '22 at 18:58
  • Ironically I made a typo in my previous comment in the way I thought you might have. The issue is that Java expects a file named `Xyz.java` to have a class `Xyz`. However since `ThingThatWorks` is in a file called `ThingsThatWork.java` it will be expecting the class inside it to be called `ThingsThatWork`. – Locke Sep 23 '22 at 19:00
  • Ah, okay, I see what you mean now. In this case, yes I did make a typo when writing out my question and added an extra s. The class file in Eclipse is ThingThatWorks. – Manthor Sep 23 '22 at 19:12

1 Answers1

0

Ok, try the following when compiling:

  1. Open a command line and use the cd command to change to the directory with the java and class files
  2. run the command

fsutil file createnew manifest.man 0

  1. open the created manifest and add the following to it:

Manifest-Version: 1.0

Main-Class: ProgramJava

Created-By: 1.8.0_144 (Oracle Corporation)

  1. Go back to the command line and run the command

jar cmf manifest.man Program.jar *.class

  1. Done. You can run it using the command

java -jar Program.jar

or

java -cp Program.jar ProgramJava

Adam
  • 186
  • 1
  • 4
  • 20
  • Hey, thank you for the suggestion but your first answer ended up actually being the key, the other half of it was me fucking up the .bat file to run the program. – Manthor Sep 23 '22 at 21:09