So this application gets input from the user and converts it into a string. It then uses various methods to set instance variables of this class and ends up printing those classes to display information to the user about that products.
I am getting a logical error. My output is this:package javaapplication5; import java.text.NumberFormat; import java.util.Scanner; public class Product { private String product; private String description; private double price; public Product() { String product = ""; String description = ""; double price = 0.0; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); Product productObject = new Product(); System.out.println("Enter a product for information. Choose either Java or C++"); String productName = sc.next(); productObject.setProductInfo(productName); System.out.println("Prduct: " + productObject.getProduct() + " Description: " + productObject.getDescription() + " Price " + productObject.getPrice()); public void setProductInfo(String product) { Product productObject = new Product(); String productName = productObject.getProduct(); if(product.equalsIgnoreCase("java")) { productObject.setProduct("Murach's Java Programing"); productObject.setDescription("Learn java with this fabulous book"); productObject.setPrice(49.95); } else if(product.equalsIgnoreCase("C++")) { productObject.setProduct("Murach's C++ Programing"); productObject.setDescription("Learn C++ with this fabulous book"); productObject.setPrice(39.95); } else productObject.setProduct("Unkown"); } public String getProduct() { return product; } public void setProduct(String product) { this.product = product; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } }
Enter a product for information. Choose either Java or C++ java Prduct: null Description: null Price 0.0