Results 1 to 4 of 4
Thread: copying information
- 04-27-2012, 05:48 AM #1
Member
- Join Date
- Apr 2012
- Posts
- 17
- Rep Power
- 0
- 04-27-2012, 05:51 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: copying information
Please post the code that you have written so far. So we can have a check on what you are doing there.
Website: Learn Java by Examples
- 04-27-2012, 06:07 AM #3
Member
- Join Date
- Apr 2012
- Posts
- 17
- Rep Power
- 0
Re: copying information
ok here you go i forgot my actually code on the pc at school so i need to start over
this is the part im asking aboutJava Code:import java.io.*; import java.util.Scanner; import java.text.DecimalFormat; public class SalesStats { public static void main(String[] args) throws IOException { // Create a Divisions object. Divisions d = new Divisions(); // Read the values from the file into d. readValues(d); // Display the values in d. displaySales(d); // Display the quarterly increase or decrease. displayQtrDifference(d); // Display the total sales by quarter. displaySalesByQtr(d); // Display the quarterly increase or decrease // by quarter. displayCompanyQtrDifference(d); // Display the average sales per quarter. displayAverageSalesPerQtr(d); // Display the division with the highest sales // by quarter. displayHighestDivisionPerQtr(d); } /** * readValues method. * Reads the values from Sales.txt into the object. */ public static void readValues(Divisions d) throws IOException { /* Missing code starts here */ Scanner keyboard = new Scanner(System.in); File file = new File("Sales.txt"); Scanner inputFile = new Scanner(file); while(inputFile.hasNext()) { String Sales = inputFile.nextLine(); inputFile.close(); } /* Missing code ends here */ } /** * displayValues method. * Displays a list of sales figures by division. */ public static void displaySales(Divisions d) { System.out.println("SALES AMOUNTS BY DIVISION"); System.out.println("========================="); /* Missing code starts here */ /* Missing code ends here */ } /** * displayQtrDifference method. * Displays the quareterly increase or decrease for each * division, starting at quarter 2. */ public static void displayQtrDifference(Divisions d) { System.out.println("QUARTERLY INCREASE/DECREASE BY DIVISION"); System.out.println("======================================="); /* Missing code starts here */ /* Missing code ends here */ } /** * displaySalesByQtr method. * Displays total sales by quarter. */ public static void displaySalesByQtr(Divisions d) { DecimalFormat dollar = new DecimalFormat("#,##0.00"); System.out.println("SALES AMOUNTS BY QUARTER"); System.out.println("========================"); for (int qtr = 1; qtr <= 4; qtr++) { System.out.println("Quarter " + qtr + ": $" + dollar.format(d.totalQuarterSales(qtr))); } System.out.println(); } /** * displayCompanyQtrDifference method. * Displays the quareterly increase or decrease for the * company, starting at quarter 2. */ public static void displayCompanyQtrDifference(Divisions d) { double increase; DecimalFormat dollar = new DecimalFormat("#,##0.00"); System.out.println("QUARTERLY INCREASE/DECREASE FOR THE COMPANY"); System.out.println("==========================================="); /* Missing code starts here */ /* Missing code ends here */ } /** * displayAverageSalesPerQuarter method. * Displays the average sales for all divisions per quarter. */ public static void displayAverageSalesPerQtr(Divisions d) { /* Missing code starts here */ /* Missing code ends here */ } /** * displayHighestDivisionPerQtr method. * Displays the division with the highest sales per quarter. */ public static void displayHighestDivisionPerQtr(Divisions d) { System.out.println("DIVISION WITH THE HIGHEST SALES PER QUARTER"); System.out.println("==========================================="); /* Missing code starts here */ /* Missing code ends here */ } }
Java Code:public static void readValues(Divisions d) throws IOException { /* Missing code starts here */ Scanner keyboard = new Scanner(System.in); File file = new File("Sales.txt"); Scanner inputFile = new Scanner(file); while(inputFile.hasNext()) { String Sales = inputFile.nextLine(); inputFile.close(); } /* Missing code ends here */ }
- 04-27-2012, 07:11 AM #4
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: copying information
The following code will store data read from the Sales.txt document into an ArrayList. Use ArrayList if we are not sure the size of our data are. We can just add data into an ArrayList.
Java Code:public static void readValues(Divisions d) throws IOException { ArrayList list = new ArrayList(); File file = new File("Sales.txt"); Scanner inputFile = new Scanner(file); while(inputFile.hasNext()) { String sales = inputFile.nextLine(); list.add(sales); } }Website: Learn Java by Examples
Similar Threads
-
signer information does not match signer information of other classes
By swyatt in forum New To JavaReplies: 5Last Post: 04-27-2011, 09:14 PM -
add to a zip file without copying it.
By yurabita in forum New To JavaReplies: 5Last Post: 08-21-2010, 03:16 AM -
Not Copying Libraries!?!
By Atriamax in forum NetBeansReplies: 0Last Post: 10-13-2009, 07:56 AM -
Copying a derectory
By linux1man in forum New To JavaReplies: 10Last Post: 01-15-2009, 07:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks