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

. (a) Write a class that manages the inventory of TVs: each account should have

ID: 3725547 • Letter: #

Question

. (a) Write a class that manages the inventory of TVs: each account should have a manufactur name, size of the TV, number of TVs in stock, and the price of the TV. It should have constructor(s), getter and setter methods , toString method, a finalPrice() method, and an he finalPrice() method should accept a sales tax rate as a parameter and () method should receive the number of TVs return the final price = price + tax. The inventory bought and update the stock for that TV. (b) Write a driver to the class. It should read data from the keyboard and print before and after purchase information. PROGRAMS ATTACHED. Here is an example of the output Enter manufacturer name: sony Enter Price: $1000 Enter size of the TV: 60 Enter number of units in stock: 10 sony $1000.0 10 How many do you want to buy? 4 What is the tax rate? 10 Total price: $4400.0 We have 6 sony Tvs in stock 60 inches

Explanation / Answer

import java.util.*;

class TVInventory
{
private String manufacturerName;
private double price;
private int unitsInStock;
private int size;

public TVInventory(String manufacturerName,double price,int unitsInStock,int size)//constructor
{
this.manufacturerName = manufacturerName;
this.price = price;
this.unitsInStock = unitsInStock;
this.size = size;
}
//set and get methods
public void setManufacturerName(String manufacturerName)
{
this.manufacturerName = manufacturerName;
}
public String getManufacturerName()
{
return manufacturerName;
}
public void setPrice(double price)
{
this.price = price;
}
public double getPrice()
{
return price;
}
public void setUnitsInStock(int unitsInStock)
{
this.unitsInStock = unitsInStock;
}
public int getUnitsInStock()
{
return unitsInStock;
}
public void setSize(int size)
{
this.size = size;
}
public int getSize()
{
return size;
}
public double finalPrice(double salesTaxRate) // compute price after tax
{
return price + price*salesTaxRate/100;
}
public void inventory(int tvsBought) // update inventory
{
unitsInStock = unitsInStock -tvsBought;
}

public String toString()
{
return " "+manufacturerName +" $"+price+"   "+unitsInStock+" "+size+" inches";
}
}

class Test
{
public static void main (String[] args)
{
  Scanner input = new Scanner(System.in);
  
  System.out.println("Enter manufacturer name : ");
  String manufacturerName = input.nextLine();
  
  System.out.println("Enter Price : $");
  double price = input.nextDouble();
  
  System.out.println("Enter size of tv : ");
  int size = input.nextInt();
  
  System.out.println("Enter number of units in stock : ");
  int unitsInStock = input.nextInt();
  
  TVInventory tv1 = new TVInventory(manufacturerName,price,size,unitsInStock);
  
  System.out.println(tv1);
  
  System.out.println("How many do you want to buy : ");
  int n = input.nextInt();
  
  tv1.inventory(n);
  System.out.println("What is the tax rate : ");
  double taxRate = input.nextDouble();
  
  System.out.println("Total Price : $"+tv1.finalPrice(taxRate)*n);
  
  System.out.println("We have "+tv1.getUnitsInStock()+" "+tv1.getManufacturerName()+" tvs in stock");
  
}
}

Output:

Enter manufacturer name :sony
Enter Price : $1000.0
Enter size of tv :60
Enter number of units in stock :10

sony $1000.0   10 60 inches
How many do you want to buy :4
What is the tax rate :10
Total Price : $4400.0
We have 6 sony tvs in stock