SlideShare a Scribd company logo
1 of 11
Download to read offline
Answer:
Note: programming specifications and the printing statements are provided in the question itself
Program code:
import java.util.*;
import java.io.*;
//Implementing Projecto2 class
public class Project02
{
//begins main program for the class
public static void main(String[] args)
{
//creating the Scanner object
Scanner keyboards = new Scanner(System.in);
//getting file name as input
System.out.print("Enter an inventory filename: ");
String fnames = keyboards.nextLine();
//Implementing the product array list
ArrayList products1 = loadProductsS(fnames);
//calling the below functions
generateSummaryReportGen(products1);
highestAvgRatingCalc(products1);
lowestAvgRating(products1);
largestTotalDollarAmount(products1);
smallestTotalDollarAmount(products1);
}
//function definition for the class generateSummaryReportGen
public static void generateSummaryReportGen (ArrayList Products11)
{
int counters = 0;
System.out.println("Product Inventory Summary Report");
System.out.println("----------------------------------------------------------------------------------");
System.out.println();
System.out.printf("%-33s%-10s%-6s%-7s%-7s%-7s%-7s", "Product Name", "I Code",
"Type", "Rating", "# Rat.", "Quant.", "Price");
System.out.println();
System.out.printf("%-33s%-10s%-6s%-7s%-7s%-7s%-7s", "-------------------------------", "----
-----", "----", "------", "------", "------", "------");
System.out.println();
while(counters < Products11.size())
{
System.out.printf("%-33s%-10s%-6s%-7s%6s%7s%7s", Products11.get(counters).getName(),
Products11.get(counters).getInventoryCode(), Products11.get(counters).getType(),
Products11.get(counters).getAvgUserRating(), Products11.get(counters).getUserRatingCount(),
Products11.get(counters).getQuantity(), Products11.get(counters).getPrice());
System.out.println();
counters++;
}
System.out.println("----------------------------------------------------------------------------------");
System.out.println("Total products in the database: " + Products11.size());
}
//function definition for the class loadProductsS
public static ArrayList loadProductsS(String fnames)
{
//declares variables
int a = 0;
Integer b = 0;
//creates array list objects
ArrayList products11 = new ArrayList();
try
{
Scanner inFiles = new Scanner(new File(fnames));
while (inFiles.hasNext())
{
int counters = 0;
String name = inFiles.nextLine();
String code = inFiles.nextLine();
int quantity = inFiles.nextInt();
double price = inFiles.nextDouble();
String type = inFiles.next();
Product productObjectS = new Product(name, code, quantity, price, type);
while(inFiles.hasNextInt() && counters==0)
{
a = inFiles.nextInt();
if(a != -1)
{
b = new Integer(a);
productObjectS.addUserRating(b);
}
else
{
counters = 1;
}
}
products11.add(productObjectS);
if(inFiles.hasNext())
{
inFiles.nextLine();
}
}
inFiles.close();
}
catch (FileNotFoundException e) {
System.out.println("ERROR: " + e);
}
return products11;
}
//function definition for the class void highestAvgRatingCalc
public static void highestAvgRatingCalc(ArrayList products11)
{
//declares variables
int counters = 0;
int a = 1;
//checks the counters product size
while (counters <= products11.size()-1)
{
if(products11.get(counters).getAvgUserRating().length() >
products11.get(a).getAvgUserRating().length())
{
a = counters;
}
else
{
}
counters++;
}
System.out.println("Highest Average User Rating In Stock: " + products11.get(a).getName() +
" ("+products11.get(a).getAvgUserRating() + ")");
}
//function definiton for the lowestAvgRating()
public static void lowestAvgRating(ArrayList products11)
{
//declares variables
int counters = 0;
int a = 1;
while (counters <= products11.size()-1)
{
if(products11.get(counters).getAvgUserRating().length() products11)
{
int counters = 0;
int a = 1;
while (counters <= products11.size()-1){
if((products11.get(counters).getPrice())*(products11.get(counters).getQuantity()) >
((products11.get(a).getPrice())*(products11.get(a).getQuantity())))
{
a=counters;
}
else{
}
counters++;
}
System.out.println("Item With The Largest Total Dollar Amount In Inventory: " +
products11.get(a).getName() + " ($" +
((products11.get(a).getPrice())*(products11.get(a).getQuantity())) + ")");
}
//function definition for smallestTotalDollarAmount
public static void smallestTotalDollarAmount(ArrayList products11)
{
int counters = 0;
int a = 1;
while (counters <= products11.size()-1)
{
if((products11.get(counters).getPrice())*(products11.get(counters).getQuantity()) <
((products11.get(a).getPrice())*(products11.get(a).getQuantity())))
{
a=counters;
}
else
{
}
counters++;
}
System.out.println("Item With The Smallest Total Dollar Amount In Inventory: " +
products11.get(a).getName() + " ($" +
((products11.get(a).getPrice())*(products11.get(a).getQuantity())) + ")");
}
}
Sample Output:
C:jdk1.6bin>javac Product.java
C:jdk1.6bin>javac Project02.java
C:jdk1.6bin>java Project02
Enter an inventory filename: input.txt
Product Inventory Summary Report
--------------------------------------------------------------------------------
--
Product Name I Code Type Rating # Rat. Quant. Price
------------------------------- --------- ---- ------ ------ ------ ------
The Shawshank Redemption C0000001 DVD *** 4 100 19.95
The Dark Knight C0000003 DVD *** 3 50 19.95
Casablanca C0000007 DVD **** 4 137 9.95
The Girl With The Dragon Tattoo C0000015 Book *** 3 150 14.95
Vertigo C0000023 DVD **** 6 55 9.95
A Game of Thrones C0000019 Book 0 100 8.95
--------------------------------------------------------------------------------
--
Total products in the database: 6
Highest Average User Rating In Stock: Casablanca (****)
Lowest Average User Rating In Stock: A Game of Thrones ()
Item With The Largest Total Dollar Amount In Inventory: The Girl With The Dragon
Tattoo ($2242.5)
Item With The Smallest Total Dollar Amount In Inventory: Vertigo ($547.25)
C:jdk1.6bin>javac Project02.java
Solution
Answer:
Note: programming specifications and the printing statements are provided in the question itself
Program code:
import java.util.*;
import java.io.*;
//Implementing Projecto2 class
public class Project02
{
//begins main program for the class
public static void main(String[] args)
{
//creating the Scanner object
Scanner keyboards = new Scanner(System.in);
//getting file name as input
System.out.print("Enter an inventory filename: ");
String fnames = keyboards.nextLine();
//Implementing the product array list
ArrayList products1 = loadProductsS(fnames);
//calling the below functions
generateSummaryReportGen(products1);
highestAvgRatingCalc(products1);
lowestAvgRating(products1);
largestTotalDollarAmount(products1);
smallestTotalDollarAmount(products1);
}
//function definition for the class generateSummaryReportGen
public static void generateSummaryReportGen (ArrayList Products11)
{
int counters = 0;
System.out.println("Product Inventory Summary Report");
System.out.println("----------------------------------------------------------------------------------");
System.out.println();
System.out.printf("%-33s%-10s%-6s%-7s%-7s%-7s%-7s", "Product Name", "I Code",
"Type", "Rating", "# Rat.", "Quant.", "Price");
System.out.println();
System.out.printf("%-33s%-10s%-6s%-7s%-7s%-7s%-7s", "-------------------------------", "----
-----", "----", "------", "------", "------", "------");
System.out.println();
while(counters < Products11.size())
{
System.out.printf("%-33s%-10s%-6s%-7s%6s%7s%7s", Products11.get(counters).getName(),
Products11.get(counters).getInventoryCode(), Products11.get(counters).getType(),
Products11.get(counters).getAvgUserRating(), Products11.get(counters).getUserRatingCount(),
Products11.get(counters).getQuantity(), Products11.get(counters).getPrice());
System.out.println();
counters++;
}
System.out.println("----------------------------------------------------------------------------------");
System.out.println("Total products in the database: " + Products11.size());
}
//function definition for the class loadProductsS
public static ArrayList loadProductsS(String fnames)
{
//declares variables
int a = 0;
Integer b = 0;
//creates array list objects
ArrayList products11 = new ArrayList();
try
{
Scanner inFiles = new Scanner(new File(fnames));
while (inFiles.hasNext())
{
int counters = 0;
String name = inFiles.nextLine();
String code = inFiles.nextLine();
int quantity = inFiles.nextInt();
double price = inFiles.nextDouble();
String type = inFiles.next();
Product productObjectS = new Product(name, code, quantity, price, type);
while(inFiles.hasNextInt() && counters==0)
{
a = inFiles.nextInt();
if(a != -1)
{
b = new Integer(a);
productObjectS.addUserRating(b);
}
else
{
counters = 1;
}
}
products11.add(productObjectS);
if(inFiles.hasNext())
{
inFiles.nextLine();
}
}
inFiles.close();
}
catch (FileNotFoundException e) {
System.out.println("ERROR: " + e);
}
return products11;
}
//function definition for the class void highestAvgRatingCalc
public static void highestAvgRatingCalc(ArrayList products11)
{
//declares variables
int counters = 0;
int a = 1;
//checks the counters product size
while (counters <= products11.size()-1)
{
if(products11.get(counters).getAvgUserRating().length() >
products11.get(a).getAvgUserRating().length())
{
a = counters;
}
else
{
}
counters++;
}
System.out.println("Highest Average User Rating In Stock: " + products11.get(a).getName() +
" ("+products11.get(a).getAvgUserRating() + ")");
}
//function definiton for the lowestAvgRating()
public static void lowestAvgRating(ArrayList products11)
{
//declares variables
int counters = 0;
int a = 1;
while (counters <= products11.size()-1)
{
if(products11.get(counters).getAvgUserRating().length() products11)
{
int counters = 0;
int a = 1;
while (counters <= products11.size()-1){
if((products11.get(counters).getPrice())*(products11.get(counters).getQuantity()) >
((products11.get(a).getPrice())*(products11.get(a).getQuantity())))
{
a=counters;
}
else{
}
counters++;
}
System.out.println("Item With The Largest Total Dollar Amount In Inventory: " +
products11.get(a).getName() + " ($" +
((products11.get(a).getPrice())*(products11.get(a).getQuantity())) + ")");
}
//function definition for smallestTotalDollarAmount
public static void smallestTotalDollarAmount(ArrayList products11)
{
int counters = 0;
int a = 1;
while (counters <= products11.size()-1)
{
if((products11.get(counters).getPrice())*(products11.get(counters).getQuantity()) <
((products11.get(a).getPrice())*(products11.get(a).getQuantity())))
{
a=counters;
}
else
{
}
counters++;
}
System.out.println("Item With The Smallest Total Dollar Amount In Inventory: " +
products11.get(a).getName() + " ($" +
((products11.get(a).getPrice())*(products11.get(a).getQuantity())) + ")");
}
}
Sample Output:
C:jdk1.6bin>javac Product.java
C:jdk1.6bin>javac Project02.java
C:jdk1.6bin>java Project02
Enter an inventory filename: input.txt
Product Inventory Summary Report
--------------------------------------------------------------------------------
--
Product Name I Code Type Rating # Rat. Quant. Price
------------------------------- --------- ---- ------ ------ ------ ------
The Shawshank Redemption C0000001 DVD *** 4 100 19.95
The Dark Knight C0000003 DVD *** 3 50 19.95
Casablanca C0000007 DVD **** 4 137 9.95
The Girl With The Dragon Tattoo C0000015 Book *** 3 150 14.95
Vertigo C0000023 DVD **** 6 55 9.95
A Game of Thrones C0000019 Book 0 100 8.95
--------------------------------------------------------------------------------
--
Total products in the database: 6
Highest Average User Rating In Stock: Casablanca (****)
Lowest Average User Rating In Stock: A Game of Thrones ()
Item With The Largest Total Dollar Amount In Inventory: The Girl With The Dragon
Tattoo ($2242.5)
Item With The Smallest Total Dollar Amount In Inventory: Vertigo ($547.25)
C:jdk1.6bin>javac Project02.java

More Related Content

Similar to AnswerNote programming specifications and the printing statement.pdf

Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Sunil Kumar Gunasekaran
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Mario Fusco
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)
Alok Kumar
 
Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
anushkaent7
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
Tomek Kaczanowski
 

Similar to AnswerNote programming specifications and the printing statement.pdf (20)

Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Advance MapReduce Concepts - Module 4
Advance MapReduce Concepts - Module 4Advance MapReduce Concepts - Module 4
Advance MapReduce Concepts - Module 4
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Design pattern - part 3
Design pattern - part 3Design pattern - part 3
Design pattern - part 3
 
Awt components
Awt componentsAwt components
Awt components
 
Cambio de bases
Cambio de basesCambio de bases
Cambio de bases
 
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
Java programs - bubble sort, iterator, linked list, hash set, reverse string,...
 
Java 8 lambda expressions
Java 8 lambda expressionsJava 8 lambda expressions
Java 8 lambda expressions
 
That’s My App - Running in Your Background - Draining Your Battery
That’s My App - Running in Your Background - Draining Your BatteryThat’s My App - Running in Your Background - Draining Your Battery
That’s My App - Running in Your Background - Draining Your Battery
 
Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
 
Flink Batch Processing and Iterations
Flink Batch Processing and IterationsFlink Batch Processing and Iterations
Flink Batch Processing and Iterations
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 
The uniform interface is 42
The uniform interface is 42The uniform interface is 42
The uniform interface is 42
 
Important java programs(collection+file)
Important java programs(collection+file)Important java programs(collection+file)
Important java programs(collection+file)
 
Main class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdfMain class --------------------------import java.awt.FlowLayout.pdf
Main class --------------------------import java.awt.FlowLayout.pdf
 
Lab4
Lab4Lab4
Lab4
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React Alicante
 

More from anushasarees

Properties of enantiomers Their NMR and IR spec.pdf
                     Properties of enantiomers Their NMR and IR spec.pdf                     Properties of enantiomers Their NMR and IR spec.pdf
Properties of enantiomers Their NMR and IR spec.pdf
anushasarees
 
  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf
anushasarees
 
There are so many java Input Output classes that are available in it.pdf
There are so many java Input Output classes that are available in it.pdfThere are so many java Input Output classes that are available in it.pdf
There are so many java Input Output classes that are available in it.pdf
anushasarees
 
The main organelles in protein sorting and targeting are Rough endop.pdf
The main organelles in protein sorting and targeting are Rough endop.pdfThe main organelles in protein sorting and targeting are Rough endop.pdf
The main organelles in protein sorting and targeting are Rough endop.pdf
anushasarees
 
Successfully supporting managerial decision-making is critically dep.pdf
Successfully supporting managerial decision-making is critically dep.pdfSuccessfully supporting managerial decision-making is critically dep.pdf
Successfully supporting managerial decision-making is critically dep.pdf
anushasarees
 
SolutionTo know that the team has identified all of the significa.pdf
SolutionTo know that the team has identified all of the significa.pdfSolutionTo know that the team has identified all of the significa.pdf
SolutionTo know that the team has identified all of the significa.pdf
anushasarees
 

More from anushasarees (20)

Properties of enantiomers Their NMR and IR spec.pdf
                     Properties of enantiomers Their NMR and IR spec.pdf                     Properties of enantiomers Their NMR and IR spec.pdf
Properties of enantiomers Their NMR and IR spec.pdf
 
O2 will be released as Na+ will not get reduce bu.pdf
                     O2 will be released as Na+ will not get reduce bu.pdf                     O2 will be released as Na+ will not get reduce bu.pdf
O2 will be released as Na+ will not get reduce bu.pdf
 
Huntingtons disease and other hereditary diseas.pdf
                     Huntingtons disease and other hereditary diseas.pdf                     Huntingtons disease and other hereditary diseas.pdf
Huntingtons disease and other hereditary diseas.pdf
 
ionic character BaF MgO FeO SO2 N2 .pdf
                     ionic character BaF  MgO  FeO  SO2  N2  .pdf                     ionic character BaF  MgO  FeO  SO2  N2  .pdf
ionic character BaF MgO FeO SO2 N2 .pdf
 
Nitrogen can hold up to 4 bonds. In sodium amide.pdf
                     Nitrogen can hold up to 4 bonds.  In sodium amide.pdf                     Nitrogen can hold up to 4 bonds.  In sodium amide.pdf
Nitrogen can hold up to 4 bonds. In sodium amide.pdf
 
C. hydrogen bonding. between N and H of differen.pdf
                     C. hydrogen bonding.  between N and H of differen.pdf                     C. hydrogen bonding.  between N and H of differen.pdf
C. hydrogen bonding. between N and H of differen.pdf
 
  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf  import java.util.;import acm.program.;public class FlightPla.pdf
  import java.util.;import acm.program.;public class FlightPla.pdf
 
We Know that    Amines are generally basic in naturebecause of th.pdf
We Know that    Amines are generally basic in naturebecause of th.pdfWe Know that    Amines are generally basic in naturebecause of th.pdf
We Know that    Amines are generally basic in naturebecause of th.pdf
 
There are so many java Input Output classes that are available in it.pdf
There are so many java Input Output classes that are available in it.pdfThere are so many java Input Output classes that are available in it.pdf
There are so many java Input Output classes that are available in it.pdf
 
Three are ways to protect unused switch ports Option B,D and E is.pdf
Three are ways to protect unused switch ports Option B,D and E is.pdfThree are ways to protect unused switch ports Option B,D and E is.pdf
Three are ways to protect unused switch ports Option B,D and E is.pdf
 
The water turns green because the copper(II)sulfate is breaking apar.pdf
The water turns green because the copper(II)sulfate is breaking apar.pdfThe water turns green because the copper(II)sulfate is breaking apar.pdf
The water turns green because the copper(II)sulfate is breaking apar.pdf
 
The mutation is known as inversion. In this a segment from one chrom.pdf
The mutation is known as inversion. In this a segment from one chrom.pdfThe mutation is known as inversion. In this a segment from one chrom.pdf
The mutation is known as inversion. In this a segment from one chrom.pdf
 
The main organelles in protein sorting and targeting are Rough endop.pdf
The main organelles in protein sorting and targeting are Rough endop.pdfThe main organelles in protein sorting and targeting are Rough endop.pdf
The main organelles in protein sorting and targeting are Rough endop.pdf
 
Successfully supporting managerial decision-making is critically dep.pdf
Successfully supporting managerial decision-making is critically dep.pdfSuccessfully supporting managerial decision-making is critically dep.pdf
Successfully supporting managerial decision-making is critically dep.pdf
 
SolutionTo know that the team has identified all of the significa.pdf
SolutionTo know that the team has identified all of the significa.pdfSolutionTo know that the team has identified all of the significa.pdf
SolutionTo know that the team has identified all of the significa.pdf
 
Solutiona) Maximum bus speed = bus driver delay + propagation del.pdf
Solutiona) Maximum bus speed = bus driver delay + propagation del.pdfSolutiona) Maximum bus speed = bus driver delay + propagation del.pdf
Solutiona) Maximum bus speed = bus driver delay + propagation del.pdf
 
Solution Polymerase chain reaction is process in which several co.pdf
Solution Polymerase chain reaction is process in which several co.pdfSolution Polymerase chain reaction is process in which several co.pdf
Solution Polymerase chain reaction is process in which several co.pdf
 
Doubling [NO] would quadruple the rate .pdf
                     Doubling [NO] would quadruple the rate           .pdf                     Doubling [NO] would quadruple the rate           .pdf
Doubling [NO] would quadruple the rate .pdf
 
Correct answer F)4.0 .pdf
                     Correct answer F)4.0                            .pdf                     Correct answer F)4.0                            .pdf
Correct answer F)4.0 .pdf
 
D.) The system is neither at steady state or equi.pdf
                     D.) The system is neither at steady state or equi.pdf                     D.) The system is neither at steady state or equi.pdf
D.) The system is neither at steady state or equi.pdf
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 

AnswerNote programming specifications and the printing statement.pdf

  • 1. Answer: Note: programming specifications and the printing statements are provided in the question itself Program code: import java.util.*; import java.io.*; //Implementing Projecto2 class public class Project02 { //begins main program for the class public static void main(String[] args) { //creating the Scanner object Scanner keyboards = new Scanner(System.in); //getting file name as input System.out.print("Enter an inventory filename: "); String fnames = keyboards.nextLine(); //Implementing the product array list ArrayList products1 = loadProductsS(fnames); //calling the below functions generateSummaryReportGen(products1); highestAvgRatingCalc(products1); lowestAvgRating(products1); largestTotalDollarAmount(products1); smallestTotalDollarAmount(products1); } //function definition for the class generateSummaryReportGen public static void generateSummaryReportGen (ArrayList Products11) { int counters = 0; System.out.println("Product Inventory Summary Report"); System.out.println("----------------------------------------------------------------------------------"); System.out.println(); System.out.printf("%-33s%-10s%-6s%-7s%-7s%-7s%-7s", "Product Name", "I Code", "Type", "Rating", "# Rat.", "Quant.", "Price"); System.out.println();
  • 2. System.out.printf("%-33s%-10s%-6s%-7s%-7s%-7s%-7s", "-------------------------------", "---- -----", "----", "------", "------", "------", "------"); System.out.println(); while(counters < Products11.size()) { System.out.printf("%-33s%-10s%-6s%-7s%6s%7s%7s", Products11.get(counters).getName(), Products11.get(counters).getInventoryCode(), Products11.get(counters).getType(), Products11.get(counters).getAvgUserRating(), Products11.get(counters).getUserRatingCount(), Products11.get(counters).getQuantity(), Products11.get(counters).getPrice()); System.out.println(); counters++; } System.out.println("----------------------------------------------------------------------------------"); System.out.println("Total products in the database: " + Products11.size()); } //function definition for the class loadProductsS public static ArrayList loadProductsS(String fnames) { //declares variables int a = 0; Integer b = 0; //creates array list objects ArrayList products11 = new ArrayList(); try { Scanner inFiles = new Scanner(new File(fnames)); while (inFiles.hasNext()) { int counters = 0; String name = inFiles.nextLine(); String code = inFiles.nextLine(); int quantity = inFiles.nextInt(); double price = inFiles.nextDouble(); String type = inFiles.next(); Product productObjectS = new Product(name, code, quantity, price, type); while(inFiles.hasNextInt() && counters==0)
  • 3. { a = inFiles.nextInt(); if(a != -1) { b = new Integer(a); productObjectS.addUserRating(b); } else { counters = 1; } } products11.add(productObjectS); if(inFiles.hasNext()) { inFiles.nextLine(); } } inFiles.close(); } catch (FileNotFoundException e) { System.out.println("ERROR: " + e); } return products11; } //function definition for the class void highestAvgRatingCalc public static void highestAvgRatingCalc(ArrayList products11) { //declares variables int counters = 0; int a = 1; //checks the counters product size while (counters <= products11.size()-1) { if(products11.get(counters).getAvgUserRating().length() >
  • 4. products11.get(a).getAvgUserRating().length()) { a = counters; } else { } counters++; } System.out.println("Highest Average User Rating In Stock: " + products11.get(a).getName() + " ("+products11.get(a).getAvgUserRating() + ")"); } //function definiton for the lowestAvgRating() public static void lowestAvgRating(ArrayList products11) { //declares variables int counters = 0; int a = 1; while (counters <= products11.size()-1) { if(products11.get(counters).getAvgUserRating().length() products11) { int counters = 0; int a = 1; while (counters <= products11.size()-1){ if((products11.get(counters).getPrice())*(products11.get(counters).getQuantity()) > ((products11.get(a).getPrice())*(products11.get(a).getQuantity()))) { a=counters; } else{ } counters++; } System.out.println("Item With The Largest Total Dollar Amount In Inventory: " +
  • 5. products11.get(a).getName() + " ($" + ((products11.get(a).getPrice())*(products11.get(a).getQuantity())) + ")"); } //function definition for smallestTotalDollarAmount public static void smallestTotalDollarAmount(ArrayList products11) { int counters = 0; int a = 1; while (counters <= products11.size()-1) { if((products11.get(counters).getPrice())*(products11.get(counters).getQuantity()) < ((products11.get(a).getPrice())*(products11.get(a).getQuantity()))) { a=counters; } else { } counters++; } System.out.println("Item With The Smallest Total Dollar Amount In Inventory: " + products11.get(a).getName() + " ($" + ((products11.get(a).getPrice())*(products11.get(a).getQuantity())) + ")"); } } Sample Output: C:jdk1.6bin>javac Product.java C:jdk1.6bin>javac Project02.java C:jdk1.6bin>java Project02 Enter an inventory filename: input.txt Product Inventory Summary Report -------------------------------------------------------------------------------- -- Product Name I Code Type Rating # Rat. Quant. Price ------------------------------- --------- ---- ------ ------ ------ ------ The Shawshank Redemption C0000001 DVD *** 4 100 19.95
  • 6. The Dark Knight C0000003 DVD *** 3 50 19.95 Casablanca C0000007 DVD **** 4 137 9.95 The Girl With The Dragon Tattoo C0000015 Book *** 3 150 14.95 Vertigo C0000023 DVD **** 6 55 9.95 A Game of Thrones C0000019 Book 0 100 8.95 -------------------------------------------------------------------------------- -- Total products in the database: 6 Highest Average User Rating In Stock: Casablanca (****) Lowest Average User Rating In Stock: A Game of Thrones () Item With The Largest Total Dollar Amount In Inventory: The Girl With The Dragon Tattoo ($2242.5) Item With The Smallest Total Dollar Amount In Inventory: Vertigo ($547.25) C:jdk1.6bin>javac Project02.java Solution Answer: Note: programming specifications and the printing statements are provided in the question itself Program code: import java.util.*; import java.io.*; //Implementing Projecto2 class public class Project02 { //begins main program for the class public static void main(String[] args) { //creating the Scanner object Scanner keyboards = new Scanner(System.in); //getting file name as input System.out.print("Enter an inventory filename: "); String fnames = keyboards.nextLine(); //Implementing the product array list ArrayList products1 = loadProductsS(fnames); //calling the below functions
  • 7. generateSummaryReportGen(products1); highestAvgRatingCalc(products1); lowestAvgRating(products1); largestTotalDollarAmount(products1); smallestTotalDollarAmount(products1); } //function definition for the class generateSummaryReportGen public static void generateSummaryReportGen (ArrayList Products11) { int counters = 0; System.out.println("Product Inventory Summary Report"); System.out.println("----------------------------------------------------------------------------------"); System.out.println(); System.out.printf("%-33s%-10s%-6s%-7s%-7s%-7s%-7s", "Product Name", "I Code", "Type", "Rating", "# Rat.", "Quant.", "Price"); System.out.println(); System.out.printf("%-33s%-10s%-6s%-7s%-7s%-7s%-7s", "-------------------------------", "---- -----", "----", "------", "------", "------", "------"); System.out.println(); while(counters < Products11.size()) { System.out.printf("%-33s%-10s%-6s%-7s%6s%7s%7s", Products11.get(counters).getName(), Products11.get(counters).getInventoryCode(), Products11.get(counters).getType(), Products11.get(counters).getAvgUserRating(), Products11.get(counters).getUserRatingCount(), Products11.get(counters).getQuantity(), Products11.get(counters).getPrice()); System.out.println(); counters++; } System.out.println("----------------------------------------------------------------------------------"); System.out.println("Total products in the database: " + Products11.size()); } //function definition for the class loadProductsS public static ArrayList loadProductsS(String fnames) { //declares variables int a = 0;
  • 8. Integer b = 0; //creates array list objects ArrayList products11 = new ArrayList(); try { Scanner inFiles = new Scanner(new File(fnames)); while (inFiles.hasNext()) { int counters = 0; String name = inFiles.nextLine(); String code = inFiles.nextLine(); int quantity = inFiles.nextInt(); double price = inFiles.nextDouble(); String type = inFiles.next(); Product productObjectS = new Product(name, code, quantity, price, type); while(inFiles.hasNextInt() && counters==0) { a = inFiles.nextInt(); if(a != -1) { b = new Integer(a); productObjectS.addUserRating(b); } else { counters = 1; } } products11.add(productObjectS); if(inFiles.hasNext()) { inFiles.nextLine(); } } inFiles.close(); }
  • 9. catch (FileNotFoundException e) { System.out.println("ERROR: " + e); } return products11; } //function definition for the class void highestAvgRatingCalc public static void highestAvgRatingCalc(ArrayList products11) { //declares variables int counters = 0; int a = 1; //checks the counters product size while (counters <= products11.size()-1) { if(products11.get(counters).getAvgUserRating().length() > products11.get(a).getAvgUserRating().length()) { a = counters; } else { } counters++; } System.out.println("Highest Average User Rating In Stock: " + products11.get(a).getName() + " ("+products11.get(a).getAvgUserRating() + ")"); } //function definiton for the lowestAvgRating() public static void lowestAvgRating(ArrayList products11) { //declares variables int counters = 0; int a = 1; while (counters <= products11.size()-1) {
  • 10. if(products11.get(counters).getAvgUserRating().length() products11) { int counters = 0; int a = 1; while (counters <= products11.size()-1){ if((products11.get(counters).getPrice())*(products11.get(counters).getQuantity()) > ((products11.get(a).getPrice())*(products11.get(a).getQuantity()))) { a=counters; } else{ } counters++; } System.out.println("Item With The Largest Total Dollar Amount In Inventory: " + products11.get(a).getName() + " ($" + ((products11.get(a).getPrice())*(products11.get(a).getQuantity())) + ")"); } //function definition for smallestTotalDollarAmount public static void smallestTotalDollarAmount(ArrayList products11) { int counters = 0; int a = 1; while (counters <= products11.size()-1) { if((products11.get(counters).getPrice())*(products11.get(counters).getQuantity()) < ((products11.get(a).getPrice())*(products11.get(a).getQuantity()))) { a=counters; } else { } counters++; }
  • 11. System.out.println("Item With The Smallest Total Dollar Amount In Inventory: " + products11.get(a).getName() + " ($" + ((products11.get(a).getPrice())*(products11.get(a).getQuantity())) + ")"); } } Sample Output: C:jdk1.6bin>javac Product.java C:jdk1.6bin>javac Project02.java C:jdk1.6bin>java Project02 Enter an inventory filename: input.txt Product Inventory Summary Report -------------------------------------------------------------------------------- -- Product Name I Code Type Rating # Rat. Quant. Price ------------------------------- --------- ---- ------ ------ ------ ------ The Shawshank Redemption C0000001 DVD *** 4 100 19.95 The Dark Knight C0000003 DVD *** 3 50 19.95 Casablanca C0000007 DVD **** 4 137 9.95 The Girl With The Dragon Tattoo C0000015 Book *** 3 150 14.95 Vertigo C0000023 DVD **** 6 55 9.95 A Game of Thrones C0000019 Book 0 100 8.95 -------------------------------------------------------------------------------- -- Total products in the database: 6 Highest Average User Rating In Stock: Casablanca (****) Lowest Average User Rating In Stock: A Game of Thrones () Item With The Largest Total Dollar Amount In Inventory: The Girl With The Dragon Tattoo ($2242.5) Item With The Smallest Total Dollar Amount In Inventory: Vertigo ($547.25) C:jdk1.6bin>javac Project02.java