Yes, I am new to Java as you will see from my post. I have done most of the work therefore; I am not interested in someone to doing my work for me rather I am looking for a new set of eyes. My program is to keep track of product information; I constructed this program from scratch. The output I am currently getting producing is as follows:
HP ENVY x360 TouchSmart, [price = 0.00]
Enter discount percentage [0-10]:
HP ENVY x360 TouchSmart, [price = 0.00]
Now if you are asking, No, that is not the correct output. Obviously, there should be amounts in place of the zeros. Would someone be so kind and look at this program to see what I am doing wrong? Maybe it is my logic?
This is my tester--
import java.util.Scanner;
public class ProductTester {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Product product = new Product("200.00", 0);
String formatString = "HP ENVY x360 TouchSmart, [price = %.2f]";
System.out.printf(formatString, product.getPrice());
//user input the discount amount
System.out.println("\nEnter discount percentage [0 - 100]: ");
double discount = input.nextDouble();
System.out.printf(formatString, product.getTotal());
}
}
Class--
public class Product {
private String product;
private double price;
private double discount;
private double total;
public Product(final String product, double price)
{
this.product = product; // assign product name
}
public void setPrice(double price)
{
this.price = price;
}
public double getPrice()
{
return price;
}
public double total(double amount)
{
total = (discount * price) - price;
return total;
}
public double getTotal(){
return total;
}
}
We all have been here where I am at, it is my hope that one day I will be able to help someone that needs help. After all, we all are here to learn from each other.