So, I'm just starting to work with Java and my second assignment has been to put together program involving two java classes (one data class and one to run). However, after I put together my code and went through to spot-check for errors I right-clicked the code to try and run it but the option was grayed out. My class uses Netbeans IDE by the way, and I'm trying to build the code using Maven. After not being able to run the code, I tried to test it instead and received the following error:
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.2:test (default-cli) on project JavaProgramming-app: No tests were executed Running the "debug test file" option yielded the same result. I tried going through forums here that referenced similar issues and found the common solution to be editing the pom.xml file, but the majority of codes I copied were already present in the file or simply didn't help. Below is first the pom.xml file, followed by the data class "Order", and last will be the run class "OrderTest". Thanks in advance for any help.
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.mycompany</groupId> <artifactId>JavaProgramming-parent</artifactId> <version>1.0-SNAPSHOT</version> </parent> <artifactId>JavaProgramming-app</artifactId> <packaging>nbm-application</packaging> <name>JavaProgramming-app</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <all.clusters>${project.build.directory}/${brandingToken}</all.clusters> </properties> <dependencies> <dependency> <groupId>org.netbeans.cluster</groupId> <artifactId>platform</artifactId> <version>${netbeans.version}</version> <type>pom</type> </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>JavaProgramming-branding</artifactId> <version>${project.version}</version> </dependency> <!-- NbModuleSuite functional in RELEASE70 or later: --> <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-nbjunit</artifactId> <version>${netbeans.version}</version> <scope>test</scope> <!-- beyond platform cluster, this often needs to be dropped down to compile/runtime, some other modules in IDE clusters depend on it --> </dependency> <!-- To use Jelly Tools in your functional tests, add or replace with: <dependency> <groupId>org.netbeans.api</groupId> <artifactId>org-netbeans-modules-jellytools-platform</artifactId> <version>${netbeans.version}</version> <scope>test</scope> </dependency> --> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.netbeans.utilities</groupId> <artifactId>nbm-maven-plugin</artifactId> </plugin> <!-- Permits NbModuleSuite to be run in integration-test phase: --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.12.2</version> <configuration> <systemPropertyVariables> <all.clusters>${all.clusters}</all.clusters> <branding.token>${brandingToken}</branding.token> </systemPropertyVariables> </configuration> </plugin> </plugins> </build> <profiles> <profile> <id>deployment</id> <build> <plugins> <plugin> <groupId>org.apache.netbeans.utilities</groupId> <artifactId>nbm-maven-plugin</artifactId> <executions> <execution> <id>extra</id> <goals> <goal>autoupdate</goal> <goal>webstart-app</goal> <goal>build-installers</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles> </project> package orderAssignment; public class Order { private String customerName, itemID; private double itemPrice, shippingFee, subtotal, totalOrderPrice; private int quantity; public void setCustomerName(String customerName) { this.customerName = customerName; } public String getCustomerName() { return customerName; } public void setItemID(String itemID) { this.itemID = itemID; } public String getItemID() { return itemID; } public void setItemPrice (double itemPrice) { if (itemPrice > 0.0) { this.itemPrice = itemPrice; } } public double getItemPrice() { return itemPrice; } public void setQuantity(int quantity) { if (quantity > 0.0) { this.quantity = quantity; } } public int getQuantity() { return quantity; } public void subtotal (double itemPrice, int quantity) { subtotal = itemPrice * quantity; } public double getSubtotal() { return subtotal; } public void shippingFee(double subtotal) { if (subtotal > 0.0) { shippingFee = subtotal * 0.1; } } public double getShippingFee() { return shippingFee; } public void totalOrderPrice(double subtotal, double shippingFee) { totalOrderPrice = subtotal + shippingFee; } public double getTotalOrderPrice() { return totalOrderPrice; } } package orderAssignment; import java.util.Scanner; public class OrderTest { private String customerName, itemID; private double itemPrice, shippingFee, subtotal; private int quantity, selection1, selection2; Scanner input = new Scanner(System.in); public void main(String[] args) { Order order1 = new Order(); Order order2 = new Order(); System.out.println("Enter the customer name for the first order: "); customerName = input.nextLine(); order1.setCustomerName(customerName); System.out.println("Enter the item ID for the first order: "); itemID = input.nextLine(); order1.setItemID(itemID); System.out.println("Enter the customer name for the second order: "); customerName = input.nextLine(); order2.setCustomerName(customerName); System.out.println("Enter the item ID for the second order: "); itemID = input.nextLine(); order2.setItemID(itemID); System.out.println("Enter the price of the item for the first customer's order: "); itemPrice = input.nextDouble(); order1.setItemPrice(itemPrice); System.out.println("Enter the quantity of items ordered by the first customer: "); quantity = input.nextInt(); order1.setQuantity(quantity); order1.subtotal(itemPrice, quantity); order1.shippingFee(subtotal); System.out.println("Enter the price of the item for the second customer's order: "); itemPrice = input.nextDouble(); order2.setItemPrice(itemPrice); System.out.println("Enter the quantity of items ordered by the second customer: "); quantity = input.nextInt(); order2.setQuantity(quantity); order2.subtotal(itemPrice, quantity); order2.shippingFee(subtotal); order1.totalOrderPrice(subtotal, shippingFee); System.out.printf("Here's the data you entered for the first order:%nCustomer Name: %s%nItem ID: %s%n" + "Item Price: $%.2f%nQuantity: %d%nSubtotal: $%.2f%nShipping Fee: $%.2f%nTotal: $%.2f%n" + "Would you like to make any changes to the item price or quantity? Enter 0 for no or 1 for yes.", order1.getCustomerName(), order1.getItemID(), order1.getItemPrice(), order1.getQuantity(),order1.getSubtotal(), order1.getShippingFee(), order1.getTotalOrderPrice()); selection1 = input.nextInt(); if (selection1 == 0) { System.out.println("%nNo changes made."); } else if (selection1 == 1) { System.out.println("Enter the correct item price for the first customer's order: "); itemPrice = input.nextDouble(); order1.setItemPrice(itemPrice); System.out.println("Enter the correct quantity order for the first order: "); quantity = input.nextInt(); order1.setQuantity(quantity); order1.subtotal(itemPrice, quantity); order1.shippingFee(subtotal); order1.totalOrderPrice(subtotal, shippingFee); System.out.printf("%nHere's the updated data you entered for the first order:%nCustomer Name: %s%nItem ID: %s%n" + "Item Price: $%.2f%nQuantity: %d%nSubtotal: $%.2f%nShipping Fee: $%.2f%nTotal: $%.2f", order1.getCustomerName(), order1.getItemID(), order1.getItemPrice(), order1.getQuantity(),order1.getSubtotal(), order1.getShippingFee(), order1.getTotalOrderPrice()); } else { System.out.println("Invalid input, please try again"); } order2.totalOrderPrice(subtotal, shippingFee); System.out.printf("Here's the data you entered for the second order:%nCustomer Name: %s%nItem ID: %s%n" + "Item Price: $%.2f%nQuantity: %d%nSubtotal: $%.2f%nShipping Fee: $%.2f%nTotal: $%.2f%n" + "Would you like to make any changes to the item price or quantity? Enter 0 for no or 1 for yes.", order2.getCustomerName(), order2.getItemID(), order2.getItemPrice(), order2.getQuantity(),order2.getSubtotal(), order2.getShippingFee(), order2.getTotalOrderPrice()); selection2 = input.nextInt(); if (selection2 == 0) { System.out.println("%nNo changes made."); } else if (selection2 == 1) { System.out.println("Enter the correct item price for the second customer's order: "); itemPrice = input.nextDouble(); order2.setItemPrice(itemPrice); System.out.println("Enter the correct quantity order for the second order: "); quantity = input.nextInt(); order2.setQuantity(quantity); order2.subtotal(itemPrice, quantity); order2.shippingFee(subtotal); order2.totalOrderPrice(subtotal, shippingFee); System.out.printf("%nHere's the updated data you entered for the second order:%nCustomer Name: %s%nItem ID: %s%n" + "Item Price: $%.2f%nQuantity: %d%nSubtotal: $%.2f%nShipping Fee: $%.2f%nTotal: $%.2f", order2.getCustomerName(), order2.getItemID(), order2.getItemPrice(), order2.getQuantity(),order2.getSubtotal(), order2.getShippingFee(), order2.getTotalOrderPrice()); } else { System.out.println("Invalid input, please try again"); System.out.printf("Here's all of the data that you have entered:%n%nOrder 1:%nCustomer Name: %s%nItem ID: %s%n" + "Item Price: $%.2f%nQuantity: %d%nSubtotal: $%.2f%nShipping Fee: $%.2f%nTotal: $%.2f%n%n" + "Order 2:%nCustomer Name: %s%nItem ID: %s%nItem Price: $%.2f%nQuantity: %d%n" + "Subtotal: $%.2f%nShipping Fee: $%.2f%nTotal: $%.2f%n", order1.getCustomerName(), order1.getItemID(), order1.getItemPrice(), order1.getQuantity(), order1.getSubtotal(), order1.getShippingFee(), order1.getTotalOrderPrice(), order2.getCustomerName(), order2.getItemID(), order2.getItemPrice(), order2.getQuantity(), order2.getSubtotal(), order2.getShippingFee(), order2.getTotalOrderPrice()); } } } https://stackoverflow.com/questions/66620707/how-can-i-get-my-java-code-to-build-tried-going-through-multiple-forums-answers March 14, 2021 at 11:05AM
没有评论:
发表评论