Add appropriate descriptive comments to each line of the code, explaining why the code is in the application.
import java.text.NumberFormat;
public class LineItem implements Cloneable {
private Product product;
private int quantity;
private double total;
public LineItem() {
this.product = new Product();
this.quantity = 0;
this.total = 0;
}
public LineItem(Product product, int quantity) {
this.product = product;
this.quantity = quantity;
}
public void setProduct(Product product) {
this.product = product;
}
public Product getProduct() {
return product;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public int getQuantity() {
return quantity;
}
public double getTotal() {
this.calculateTotal();
return total;
}
private void calculateTotal() {
total = quantity * product.getPrice();
}
public String getFormattedTotal() {
NumberFormat currency = NumberFormat.getCurrencyInstance();
return currency.format(this.getTotal());
}
@Override
public String toString() {
return
"Code: " + product.getCode() + "\n" +
"Description: " + product.getDescription() + "\n" +
"Price: " + product.getFormattedPrice() + "\n" +
"Quantity: " + quantity + "\n" +
"Total: " + this.getFormattedTotal() + "\n";
}
// overrides to stop error message
@Override
public Object clone() throws CloneNotSupportedException
{
LineItem li = (LineItem) super.clone();
Product p = (Product) product.clone();
li.setProduct(p);
return li;
}
}
import java.text.NumberFormat;
// Declaring a class for representing a lineItem
public class LineItem implements Cloneable {
// instance members of class
private Product product;
private int quantity;
private double total;
// Default Constructor
public LineItem() {
this.product = new Product();
this.quantity = 0;
this.total = 0;
}
// Parameterized constructor
public LineItem(Product product, int quantity) {
this.product = product;
this.quantity = quantity;
}
// method to set the product
public void setProduct(Product product) {
this.product = product;
}
// method to get the product
public Product getProduct() {
return product;
}
// method to set the quantity
public void setQuantity(int quantity) {
this.quantity = quantity;
}
// method to get the quantity
public int getQuantity() {
return quantity;
}
// method to calculate total amount from line item
public double getTotal() {
this.calculateTotal();
return total;
}
// this is a private method, which calculates the total
// price for this lineitem and updates it.
private void calculateTotal() {
total = quantity * product.getPrice();
}
// This method is used to get a prettify string
representation
// of the line item's cost with currency symbol
public String getFormattedTotal() {
NumberFormat currency = NumberFormat.getCurrencyInstance();
return currency.format(this.getTotal());
}
// This method returns the string representation of the
lineItem
// object. It prints the details in proper order.
@Override
public String toString() {
return
"Code: " + product.getCode() + "\n" +
"Description: " + product.getDescription() + "\n" +
"Price: " + product.getFormattedPrice() + "\n" +
"Quantity: " + quantity + "\n" +
"Total: " + this.getFormattedTotal() + "\n";
}
// overrides to stop error message
// Clone method is used to create the exact copy of lineItem
object
// along with the instance members
@Override
public Object clone() throws CloneNotSupportedException
{
LineItem li = (LineItem) super.clone();
Product p = (Product) product.clone();
li.setProduct(p);
return li;
}
}
Add appropriate descriptive comments to each line of the code, explaining why the code is in...
Add appropriate descriptive comments to each line of code in the project explaining why the code is in the application. public class FutureValueFrame extends JFrame { private JTextField investmentField; private JTextField interestRateField; private JComboBox yearsComboBox; private JList futureValueList; private DefaultListModel futureValueModel; public FutureValueFrame() { initComponents(); } private void initComponents() { try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { System.out.println(e); } setTitle("Future Value Calculator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationByPlatform(true); investmentField = new JTextField(); interestRateField = new JTextField();...
Add appropriate descriptive comments to EACH line of the code in the project explaining why the code is in the application. import java.io.*; public class ExceptionTesterApp { public static void main(String[] args) { System.err.println("In main: calling method1."); method1(); System.err.println("In main: returned from method1."); } public static void method1() { System.err.println("\tIn method1: calling method2."); try { method2(); } catch (FileNotFoundException e) { System.err.println(e.toString()); } System.err.println("\tIn method1: returned from method2."); } public static void method2() throws FileNotFoundException { System.err.println("\t\tIn method2: calling method3.");...
Course,java
import java.util.ArrayList;
import java.util.Arrays;
/*
* To change this license header, choose License Headers in
Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author fenghui
*/
public class Course {
private String cName;
private ArrayList<Subject>
cores;
private ArrayList<Major>
majors;
private ArrayList<Subject>
electives;
private int cCredit;
public Course(String n, int cc){
cName = n;
cCredit =
cc;
cores = new
ArrayList<Subject>(0);
majors =...
Hello everybody. Below I have attached a code and we are
supposed to add comments explaining what each line of code does.
For each method add a precise description of its purpose, input and
output. Explain the purpose of each member variable. . Some help
would be greaty appreciated. (I have finished the code below with
typing as my screen wasnt big enough to fit the whole code
image)
}
public void withdrawal (double amount) {
balance -=amount;
}...
Can someone please help me add appropriate descriptive comments to each line of code in the project explaining why the code is in the application. import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; public class BookManager { private List<Book> bookList; public BookManager() { bookList = new BookCatalog().getCatalog(); } public List<Book> getBooks(Predicate<Book> condition) { List<Book> books = new ArrayList<>(); for (Book b: bookList) { if (condition.test(b)) { books.add(b); } } return books; } } import java.util.List; public class BookManagerApp { public...
JAVA Use the class, Invoice, provided to create an array of Invoice objects. Class Invoice includes four instance variables; partNumber (type String), partDescription (type String), quantity of the item being purchased (type int0, and pricePerItem (type double). Perform the following queries on the array of Invoice objects and display the results: Use streams to sort the Invoice objects by partDescription, then display the results. Use streams to sort the Invoice objects by pricePerItem, then display the results. Use streams to...
Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...
Java/LinkedList Need help with a few of the TODO parts, more info below in comments in bold. Thanks, package lab4; import java.util.IdentityHashMap; public class IntNode implements Cloneable { private int data; private IntNode next; public IntNode(int d, IntNode n) { data = d; next = n; } public IntNode getNext() { return next; } /// Override methods from Object @Override ...
I need a shoppingcartmanager.java that contains a main method for this code in java Itemtopurchase.java public class ItemToPurchase { // instance variables private String itemName; private String itemDescription; private int itemPrice; private int itemQuantity; // default constructor public ItemToPurchase() { this.itemName = "none"; this.itemDescription = "none"; this.itemPrice = 0; this.itemQuantity = 0; } public ItemToPurchase(String itemName, int itemPrice, int itemQuantity,String itemDescription) { ...
Use java and continue stage 2 and 3
stage 1 code
public abstract class BabyItem {
protected String name;
public BabyItem() {
name="";
}
public BabyItem(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
}
public abstract double getCost();
}
========================================================================================
public class BabyFood extends BabyItem {
private int numberOfJars;
private double pricePerDozen;
public BabyFood() {
super();
numberOfJars = 0;
pricePerDozen = 0;
}
public BabyFood(int numberOfJars, double pricePerDozen) {...