Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

I am supposed to call two service classes from one client(main) class?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to do the following: If you guys can help, that would be great

PART I

1. the total sales for each week?
2. the average daily sales for each week?
3.The total sales for all the week?
4.the average weekly sales?

PART II

readText(): Read text line-by-line and print it as it appears in the given data file, also print number of line read from the data file?

storeTokens(): open file again, read the whole line and tokenize it; and store tokens in an array
of strings (call it words or tokens array). the punctuation marks may be a comma, semicolon, question mark, colon, or a period (',' ':', ';', '.').

printToken(): print all extracted words; 10 words to a line. Also print the total number of words stored in the array.

alphabetizeTokens(): alphabetize the words and again print them using printToken() method mentioned above. Print 10 words to a line again.

doFrequency(); compute frequency and print each unique word along with its frequency in the
data file under appropriate headings as shown in the sample output. Number the output lines.

AND SO FAR I HAVE THE FOLLOWING CODE :

// this is for part I service class, in this class all I need to do is some how do the summary:
// number of weeks data processed:
//total sales for all weeks:
//average weekly sales:


import java.io.*;
import java.util.*;
import java.text.DecimalFormat;

public class Sales
{
double lab = 0;

private String FileName;

// getting the file
public Sales(String inFileName)
{
FileName = inFileName;
}

private Scanner keyboard = new Scanner(System.in);

public Sales ()
{
//calling the topOfPageInfo method
topOfPageInfo();
}
public static void topOfPageInfo()
{
final String MY_NAME = "sheharyar Alam";
final String DASHES = "---------------------------------------------------";
System.out.println ("\t" + DASHES + "\n\t\t\tName: " + MY_NAME);
System.out.println ("\t\t\tlab #: 1");
System.out.println ("\t\t\tDue Date: 01/31/2008");

GregorianCalendar today = new GregorianCalendar();
DecimalFormat twoDigits = new DecimalFormat ("00");
System.out.println ("\n\t\t\tToday's Date: "
+ twoDigits.format(today.get(Calendar.MONTH)+1)
+ '/' +twoDigits.format(today.get(Calendar.DAY_OF_MONTH))
+ '/' +twoDigits.format(today.get(Calendar.YEAR)));
System.out.println("\t\t\tAnd Time Now is: " + twoDigits.format(today.get(Calendar.HOUR))
+ ':' + twoDigits.format(today.get(Calendar.MINUTE))
+ ':' +twoDigits.format(today.get(Calendar.SECOND)));
System.out.println("\t" + DASHES + "\n");
}

public void readData() throws IOException
{
int i=0;
// opening the file

String inFile = "SalesData.txt";
try
{
Scanner x = new Scanner(new File (inFile));
String week1 = x.next();
// token(sales1) printed with dilimeters

StringTokenizer st = new StringTokenizer(week1,",");
week1 = x.next();
// tokens(sales1) printed without dilimeters
StringTokenizer str = new StringTokenizer(week1,",");

Scanner y = new Scanner(new File (inFile));
String week2 = y.next();

StringTokenizer stg = new StringTokenizer(week2,",");
week2= y.next();

// tokens(sales2) printed without dilimeters
StringTokenizer sti = new StringTokenizer(week2,",");


while( str.hasMoreTokens())
{ String totsales = str.nextToken();

lab = lab + Double.parseDouble(totsales);

i++;
}

System.out.println(" Week #1 Data ");
System.out.println(" --------------");
System.out.println("");
System.out.println("Sales for Week 1:" + week1);
System.out.println("");
System.out.println("Total Sales for Week 1 = "+"$"+lab);
System.out.println("Average Daily Sales of Week 1 = "+"$"+lab/7);
System.out.println("");

System.out.println("----------------------------------------------------------------------");

System.out.println(" Week #2 Data ");
System.out.println(" --------------");
System.out.println("");
System.out.println("Sales for Week 2:" + week2);
System.out.println("");
System.out.println("Total Sales for Week 2 = "+"$"+lab);
System.out.println("Average Daily Sales of Week 2 = "+"$"+lab/7);
System.out.println("");
System.out.println("------------------------------------------------------------------------------");
System.out.println(" Summary ");
System.out.println(" ---------");
System.out.println("");
System.out.println(" Number of Weeks Data Processed ="+"$");
System.out.println("");
System.out.println(" Total Sales for all Week ="+"$");
System.out.println(" Average Weekly Sales ="+"$");

}
catch(Exception a)
{
System.out.println("File not found");

}
}


}

PART II

// I have the service class but its not doing what I want it to do
//readText()
//storeTokens()
//printToken()
//alphabetizeToken()
//doFrequency()

import java.util.StringTokenizer;
import java.io.*;
import java.util.*;

public class TokenS
{
double lab = 0;

private String FileName;
// getting the file
public TokenS(String inFileName)
{
FileName = inFileName;
}
public TokenS()
{
}

public void readText() throws IOException
{
int i = 0;

String inFile = "sample.txt";

try
{
Scanner Tokens = new Scanner(new File (inFile));
String Token = Tokens.next();
// token(sales1) printed with dilimeters
StringTokenizer st = new StringTokenizer(Token,",");
Token = Tokens.next();
// tokens(sales1) printed without dilimeters
StringTokenizer str = new StringTokenizer(Token,",");

while( str.hasMoreTokens())
{ String totsales = str.nextToken();

lab = lab + Double.parseDouble(totsales);

i++;
}

System.out.println(" Number of Lines Read = 4 ");
System.out.println("_____________________________________________");
System.out.println("");
System.out.println(" All Words without Punctuation Marks ");
System.out.println(Token);
}

catch(Exception a)
{
System.out.println("File not found");

}

}
}

AND SO HERE THE MAIN CLASS (CLIENT CLASS)

import java.util.Scanner;
import java.io.*;

public class SalesS
{
public static void main (String[] args) throws IOException
{
Sales mysale = new Sales();
//mysale.topOfPageInfo();
mysale.readData();

TokenS mytoken = new TokenS();
mytoken.readText();

}
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may want to consider reading this. We're happy to help you, but we're not gonna do the work for you. so, ask focused questions. Tell us what the problem is SPECIFICALLY - a generic "this doesn't work - please fix it" will fall on deaf ears. Even if someone DOES post a solution, more often than not a moderator will delete it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic