Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, I\'ve been having a some trouble with creating the methods for number of tra

ID: 3631329 • Letter: H

Question

Hi, I've been having a some trouble with creating the methods for number of transactions and number of units sold. Any help or advice would be greatly appreciated!

import java.io.*;
import java.util.Scanner;
/////////////////////////////////////////////////////////////////////////
class Hw11
{
//-----------------------------------------------------------------------
public static void main ( String [] args ) throws Exception
{
Item s1 = new Item("water",1.29);
Item s2 = new Item("tissue",1.84);

System.out.println();
s1.buy(1);
System.out.println();
s2.buy(4);
System.out.println();
report();

Item.setTaxRate(0.0825);
s2.setUnitPrice(2.05);

System.out.println();
s2.buy(3);
System.out.println();
report();
System.out.println();
}
//-----------------------------------------------------------------------
private static void report()
{
System.out.println("*** Transactions: " + Item.transactions());
System.out.println("*** Total units sold: " + Item.totalUnits());
}
//-----------------------------------------------------------------------
} // end class Hw11
/////////////////////////////////////////////////////////////////////////
class Item
{
private String name;
private double unitPrice;
private static double taxRate = 0.05;
private static int transactions = 0;
private static int totalUnits = 0;
//----------------------------------------------------------------------
public Item (String name, double unitPrice)
{
this.name = name;
this.unitPrice = unitPrice;
}
//-----------------------------------------------------------------------
public void buy(int amount)
{
double net = unitPrice * amount;
double gross = net * taxRate;
totalUnits = amount;

System.out.printf("%s %d unit(s) at unit price $%.2f", name, amount, unitPrice);
System.out.printf("$ %.2f net", net);
System.out.printf(" %.2f tax", taxRate);
System.out.printf("$ %.2f gross ", gross);
}
//----------------------------------------------------------------------
public static void setTaxRate(double newTaxRate)
{
taxRate = newTaxRate;
System.out.println("*** Tax rate changed to " + newTaxRate);
}
//-----------------------------------------------------------------------
public void setUnitPrice(double s)
{
s = unitPrice;
}
//-----------------------------------------------------------------------
public int getTransactions()
{
return transactions;
}
//-----------------------------------------------------------------------
public static void transactions(int count)
{
count = totalUnits;
}
//-----------------------------------------------------------------------
public static void totalUnits(int quantity)
{
quantity = totalUnits;
}
//-----------------------------------------------------------------------
} // end class Item
/////////////////////////////////////////////////////////////////////////



Explanation / Answer

I have done the solution on my computer. Rate me lifesaver and I'll share it with you through email or cramster inbox. I am just tired of me answering the questions and other people getting ratings. That is why I'm doing this.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote