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

The SECONDHAND ROSE RESALE SHOP is having a seven-day sale during which the pric

ID: 3829893 • Letter: T

Question

The SECONDHAND ROSE RESALE SHOP is having a seven-day sale during which the price of any unsold item drops 10 percent each day. Design a class diagram showing the class, the application program, the relationship between the two, and multiplicity. Then write the Java code as described below. File I/O Currently the Second Hand Rose problem has you ask the user for the item number and original price. Modify the program to read this data from a file. First, add the following to the Inventory class: 1. A method that inputs an inventory item from a file, where the file is passed as a parameter. The file contains, on each line, the item number and then the original price of the item. Then modify main() so it does the following 1. open a text file named "inventory.txt" 2. read all the Inventory records from the file by repeatedly calling the appropriate method in the Inventory class (Note that after each read, main() should send the Inventory item to printSaleData() for processing.) An inventory class that contains: 1. an item number and the original price of the item. Include the following: 2. A default constructor that initializes each attribute to some reasonable default value for a non-existent inventory item. 3. Another constructor method that has a parameter for each data member, called the overloaded constructor. This constructor initializes each attribute to the value provided when an object of this type is instantiated. Be sure to incorporate adequate error checking for all numeric attributes. Accessor and mutator methods for each attribute. Be sure to incorporate adequate error checking for all numeric attributes. a. An application program that contains two methods: the main() module and the printSaleData()module. i. The main() module must do the following: 1. create an Inventory object using the default constructor 2. use a loop to get inventory items from the user. The user should enter the item number and the original price of the item. This loop should continue until the user indicates that they have no more items to enter. For each item entered by the user, the code inside the loop should do the following 2 items: 3. set the attributes of the Inventory object by calling the appropriate method in the Inventory class for each item entered by the user 4. send the Inventory items, one at a time, to the printSaleData() module for processing 5. Extra credit for including Javadoc comments. ii. The printSaleData() module must accept an Inventory object and produce a report that shows the item number and the price of an inventory item on each day of the sale, one through seven, using a loop. For example, an item with an original price of $10.00 costs 10 percent less, or $9.00, on the first day of the sale. On the second day of the sale, the same item is 10 percent less than $9.00, or $8.10.

Explanation / Answer

Find the below code as asked in the problem statement:

Inventory.java

*****************

package com.sagar.oracle;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Inventory {


   static double item_number;

   static double original_price;


   //Empty constructor
   public Inventory() {
       super();
   }
   //Overloaded constructor
   public double getItem_number() {
       return item_number;
   }

   //Accessors and mutators
   public void setItem_number(double item_number) {
       this.item_number = item_number;
   }

   public double getOriginal_price() {
       return original_price;
   }

   public void setOriginal_price(double original_price) {
       this.original_price = original_price;
   }

   public static void main(String[] args) {

       try {
           BufferedReader reader = new BufferedReader(new FileReader("inventory.txt"));

           List<String> records = new ArrayList<String>();//Create the array list for the text records to be read

           String line;
           while ((line = reader.readLine()) != null)
           {
               records.add(line);
               //printSaleData(item_number);
           }
           reader.close();
           //return records;
       } catch (FileNotFoundException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }

   }


}

*****************

ApplicationProgram.java

package com.sagar.oracle;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class ApplicationProgram {

   Inventory inventory;

   static Scanner scanner;

   static double item_number;

   static double original_price_of_the_item;

   public ApplicationProgram() {
       super();
   }

   public Inventory getInventory() {
       return inventory;
   }

   public void setInventory(Inventory inventory) {
       this.inventory = inventory;
   }

   public static Scanner getScanner() {
       return scanner;
   }

   public static void setScanner(Scanner scanner) {
       ApplicationProgram.scanner = scanner;
   }

   public static double getItem_number() {
       return item_number;
   }

   public static void setItem_number(double item_number) {
       ApplicationProgram.item_number = item_number;
   }

   public static double getOriginal_price_of_the_item() {
       return original_price_of_the_item;
   }

   public static void setOriginal_price_of_the_item(
           double original_price_of_the_item) {
       ApplicationProgram.original_price_of_the_item = original_price_of_the_item;
   }

   public static void main(String[] args) {
       // TODO Auto-generated method stub

       List<String> records = new ArrayList<String>();//Create the array list for the text records to be read

       int count = 0;

       while(count!=0)

           scanner=new Scanner(System.in);

       System.out.println("Enter the item_number from the user");

       item_number= scanner.nextDouble();
       records.add(String.valueOf(item_number));

       System.out.println("Enter the original price of the item");  

       original_price_of_the_item=scanner.nextDouble();

       records.add(String.valueOf(original_price_of_the_item));

       printSaleData();//processing the data

   }

   private static void printSaleData() {
       // TODO Auto-generated method stub
       if(item_number <= 7 && original_price_of_the_item<=7)
       {
           //Print the reports
           //below is the function for the example of printing the report
           if(item_number == 10.00 || item_number <=9.00){
               System.out.println("First day of the sale");
           }
           else if(item_number == 9.00 || item_number <=8.10){
               System.out.println("Second day of the sale");

           }
       }
   }


}

*********************

P.S KINDLY NOTE THAT THE ABOVE PROGRAM IS WRITTEN AS ASKED IN THE PROBLEM STATEMENT AND NO OUTPUT IS SHOWN SINCE THERE IS NO DATA FILE ATTACHED WHICH HAS TO BE READ

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