URGENT Check this code for me please
Dear whoeverthisreads, please read and see at the bottom my sourcecode, or whatever I could make of it until (even with help) I failed to see any solution. Please copy, paste and run to see if you can manage to adjust the program to make it work in the way as described. And I think I made it unnecessarily complicated. Whatever you can do for me, I will be very, very grateful.
Prem Pradeep, email: [email protected]
(A beginning dutch Java student who is running out of time and hope)
Catalogue Manager
Specification:
a) Develop an object to represent to encapsulate an item in a catalogue. Each CatalogueItem has three pieces of information: an alphanumeric catalogue code, a name, and a price (in dollars and cents), that excludes sales tax. The object should also be able to report the price, inclusive of a 15% sales tax, and the taxed component of the price.
b) Work out a way to be able to support the inc tax/ex tax price accessors, and the tax component accessor, without needing to store any additional information in the object.
c) Use an array of 5 CatalogueItem items to store data. (You may assume that no imported goods will be recorded.)
d) Write a driver program that prompts for three sets of user input (catalogue number, description and price), to be stored in the atalogueItem instance.
e) The data are to be read for each item in a single line. The data lines will be in the format:
CatNo:Description:Price
Use a StringTokenizer object to separate these data lines into their components.
f) Review the class definition of CatalogueItem, and use modifiers where appropriate to:
� Ensure that data is properly protected;
� Ensure that the accessors and mutators are most visible;
� The accessors and mutators for the catalogue number and description cannot be overridden.
� The constant for the tax rate is publicly accessible, and does not need an instance of the class
present in order to be accessible.
As well as a summary, the program should also calculate and display:
� All of the cheapest and most expensive item(s) in the catalogue. In the case of more than one
item being the cheapest (or most expensive), they should all be listed.
� A total of the pre-tax worth of the goods in the catalogue.
� The average amount of tax on the items in the catalogue.
A sample execution of the program may be as follows (output should be tabulated):
Enter five items of data:
AA123: Telephone: 52.00
ZJ282: Pine Table: 98.00
BA023: Headphones: 23.00
ZZ338: Wristwatch: 295.00
JW289: Tape Recorder: 23.00
LISTING OF ALL GOODS
Cat Description ExTax Tax IncTax ~
ZJ282 pine Table 98.00 14.70 112.70
AA123 Telephone 52.00 7.80 59.80
BA023 Headphones 23.00 3.45 26.45
ZZ338 Wristwatch 295.00 44.25 339.25
JW289 Tape Recorder 23.00 3.45 26.45
CHEAPEST GOODS IN CATALOGUE
Cat Description ExTax Tax IncTax
BA023 Headphones 23.00 3.45 26.45
JW289 Tape Recorder 23.00 3.45 26.45
MOST EXPENSIVE GOODS IN CATALOGUE
Cat Description ExTax Tax IncTax
ZZ338 Wristwatch 295.00 44.25 339.25
TOTAL PRE-TAX WORTH OF CATALOGUE ITEMS: 491.00
AVERAGE AMOUNT OF TAX PAYABLE PER ITEM: 14.73
The next code is what I could make of it�until I got terribly stuck...
//CatalogueItem.java
import java.io.*;
import java.text.DecimalFormat;
import java.util.StringTokenizer;
public class CatalogueItem {
private static final double TAXABLE_PERCENTAGE = 0.15;
private String catalogNumber;
private String description;
private double price;
/** Creates a new instance of CatalogueItem */
public CatalogueItem() {
catalogNumber = null;
description = null;
price = 0;
public CatalogueItem(String pCatalogNumber, String pDescription, double pPrice) {
catalogNumber = pCatalogNumber;
description = pDescription;
price = pPrice;
void setCatalogNumber(String pCatalogNumber) {
catalogNumber = pCatalogNumber;
String getCatalogNumber() {
String str = catalogNumber;
return str;
void setDescription(String pDescription) {
description = pDescription;
String getDescription() {
String str = description;
return str;
void setPrice(String pPrice) {
price = Double.parseDouble(pPrice);
double getPrice() {
double rprice = price;
return formatDouble(rprice);
double getTaxAmount(){
double rTaxAmount = price * TAXABLE_PERCENTAGE;
return formatDouble(rTaxAmount);
double getIncTaxAmount() {
double rTaxAmount = price * (1 + TAXABLE_PERCENTAGE);
return formatDouble(rTaxAmount);
double formatDouble(double value) {
DecimalFormat myFormatter = new DecimalFormat("###.##");
String str1 = myFormatter.format(value);
// System.out.println("String is " + str1);
// System.out.println("The format value : " + value);
return Double.parseDouble(str1);
public static void main(String[] args) throws IOException {
final int MAX_INPUT_SET = 5;
final String strQ = "Enter five items of data:";
CatalogueItem[] catalogList = new CatalogueItem[MAX_INPUT_SET];
String strInput;
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
String header = "Cat\tDescription\tExTax\tTax\tInc Tax";
String lines = "---\t-----------\t------\t---\t-------";
// Input of five items with three data each, delimiter ":"
for (int i = 0; i < MAX_INPUT_SET; i++) {
catalogList[i] = new CatalogueItem();
System.out.print(strQ);
strInput = stdin.readLine();
StringTokenizer tokenizer = new StringTokenizer(strInput, ":" );
String inCatNo = tokenizer.nextToken();
String inDescr = tokenizer.nextToken();
String inPrice = tokenizer.nextToken();
catalogList.setCatalogNumnber(inCatNo);
catalogList[i].setDescription(inDescr);
catalogList[i].setPrice(inPrice);
// Listing of all goods
System.out.println("LISTING OF ALL GOODS");
System.out.println(header);
System.out.println(lines);
for (int i = 0; i < MAX_INPUT_SET; i++) {
System.out.println(
catalogList[i].getCatalogNumber() + "\t" +
catalogList[i].getDescription() + "\t" +
catalogList[i].getPrice() + "\t" +
catalogList[i].getTaxAmount() + "\t" +
catalogList[i].getIncTaxAmount());
// This should pick the cheapest and most expensive goods in catalogue, but
// this code is not good:
// In the case of more than one item being the cheapest (or most expensive),
// they should all be listed.
double cheapest = cataloguelist[1].getPrice();
double mostExpensive = cataloguelist[1].getPrice();
for(int i=2; i< MAX_INPUT_SET; i++){
if (cataloguelist[i].getPrice < cheapest)
cheapest = i;}
for(int i=2; i< MAX_INPUT_SET; i++){
if (cataloguelist[i].getPrice > mostExpensivet)
mostExpensive = i;}
// Lists cheapest goods (not complete enough)
i = cheapest;
System.out.println("CHEAPEST GOODS IN CATALOGUE");
System.out.println(header);
System.out.println(lines);
System.out.println(
catalogList[i].getCatalogNumber() + "\t" +
catalogList[i].getDescription() + "\t" +
catalogList[i].getPrice() + "\t" +
catalogList[i].getTaxAmount() + "\t" +
catalogList[i].getIncTaxAmount());
// Lists most expensive goods (not complete enough)
i = mostExpensive;
System.out.println("MOST EXPENSIVE GOODS IN CATALOGUE");
System.out.println(header);
System.out.println(lines);
System.out.println(
catalogList[i].getCatalogNumber() + "\t" +
catalogList[i].getDescription() + "\t" +
catalogList[i].getPrice() + "\t" +
catalogList[i].getTaxAmount() + "\t" +
catalogList[i].getIncTaxAmount());}}
// Generates and shows total pre-tax worth of catalogue items (how??)
// generates and shows amount of tax payable per item (how??)
How is this:
import java.io.*;
import java.text.*;
import java.util.*;
public class Cat
Vector items = new Vector();
public Cat()
public void read(String fname)
FileReader fr;
BufferedReader br;
String str ="";
try
fr = new FileReader(fname);
br = new BufferedReader(fr);
while ((str = br.readLine()) != null && items.size() < 30)
if (!str.trim().equals(""))
StringTokenizer tokenizer = new StringTokenizer(str, ":");
String n = tokenizer.nextToken().trim();
String d = tokenizer.nextToken().trim();
String s = tokenizer.nextToken().trim();
double p = Double.parseDouble(s);
items.add(new Item(n,d,p));
fr.close();
catch (FileNotFoundException e)
System.out.println("Input file cannot be located, please make sure the file exists!");
System.exit(0);
catch (IOException e)
System.out.println(e.getMessage());
System.out.println("Application cannot read the data from the file!");
System.exit(0);
public void displayAll()
for (int j=0; j < items.size(); j++)
Item item = (Item)items.get(j);
System.out.println(item.toString());
public void sort()
Collections.sort(items);
public class Item implements Comparable
String number, description;
double price,pricep;
final double TAXRATE = 0.15;
public Item(String number, String description, double price)
this.number = number;
this.description = description;
this.price = price;
this.pricep = price * TAXRATE;
public int compareTo(Object o1)
String o = ((Item)o1).number;
return(number.compareTo(o));
public String toString()
DecimalFormat df = new DecimalFormat("#.00");
String p1 = df.format(TAXRATE*price);
String p2 = df.format(TAXRATE*price+price);
String s = number+"\t "+description+"\t"+price+"\t"+p1+"\t"+p2+"\t" ;
return(s);
public static void main (String[] args)
Cat catalog = new Cat();
catalog.read("C31.dat");
String reply = "";
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
while (!reply.equals("e"))
System.out.println("");
System.out.println("CATALOGUE MANAGER: MAIN MENU");
System.out.println("============================");
System.out.println("a) display all goods b) display cheapest/dearest goods");
System.out.println("c) sort the goods list d) search the good list");
System.out.println("e) quit");
System.out.print("Option:");
try
reply = stdin.readLine();
catch (IOException e)
System.out.println("ERROR:" + e.getMessage());
System.out.println("Application exits now");
System.exit(0);
if (reply.equals("a")) catalog.displayAll();
if (reply.equals("c")) catalog.sort();
Noah
Similar Messages
-
Could anyone check this code for errors for me??
Hi! Could someone please tell me if you see any problems with this code?? a friend wants me to check it for errors, but can't find any. I just wanted to make sure, because there are probably a lot of better scripters than me reading this. Please answer soon!!
heres the code:
stop();
addEventListener(Event.ENTER_FRAME, preLoad);
function preLoad(e:Event):void{
var bytestoLoad):Number = loaderInfo.bytesTotal;
var numberLoaded:Number = loaderInfo.bytesLoaded;
if (bytestoLoad == numberLoaded) {
removeEventListener)Event.ENTER_FRAME, preLoad)
gotoAndStop(2);
}else {
preLoader.preLoaderFill.scaleX = numberLoaded/bytestoLoad;
preLoader.bytePercent.text = Math.floor (numberLoaded/bytestoLoad*100) + "%";
Thanks!!
-SammyI ran it on debug mode and changed it to this? see any problems now? or are they fixed? It looks to me like it took some actions out, I hope that doesn't
effect it....
stop();
addEventListener(Event.ENTER_FRAME, preLoad);
function preLoad(e:Event):void{
var bytestoLoad):Number = loaderInfo.bytesTotal;
var numberLoaded:Number = loaderInfo.bytesLoaded;
if (bytestoLoad == numberLoaded) {
removeEventListener)Event.ENTER_FRAME, preLoad)
gotoAndStop(2);
i'm kinda new to flash ((I started as a lua scripter (on Roblox)) so I'm a little confused about this. Thanks for the help!! -
URGENT check the code for vendor ageing (Give Solution)
hi this is the code which i am using to calculate the
ageing but not able to get the result.
every time the result is 0.plz suggest me the solution.
its very urgent.
*& Report Z_VENDOR AGEING *
*& in this repoet I am calculating the vendor ageing
which is depending on formula
AGEING = Current Date(or any date entered by user) Bline Date(BSIK-zfbdt)
REPORT z_vendor NO STANDARD PAGE HEADING
LINE-SIZE 200
LINE-COUNT 65(3).
TABLES : bsik.
DATA : BEGIN OF t_out OCCURS 0,
bukrs LIKE bsik-bukrs,
saknr LIKE bsik-saknr,
bldat LIKE bsik-bldat,
wrbtr LIKE bsik-wrbtr,
lifnr LIKE bsik-lifnr,
zfbdt like bsik-zfbdt,
ageing type i,
END OF t_out.
parameters : p_date1 type d.
SELECT-OPTIONS : s_bukrs FOR bsik-bukrs,
s_saknr FOR bsik-saknr,
s_lifnr FOR bsik-lifnr.
SELECT bukrs saknr bldat wrbtr lifnr zfbdt
FROM bsik
INTO TABLE t_out
WHERE saknr IN s_saknr
AND bukrs IN s_bukrs
AND lifnr IN s_lifnr.
CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
i_datum_bis = p_date1
i_datum_von = t_out-zfbdt
I_KZ_EXCL_VON = '0'
I_KZ_INCL_BIS = '0'
I_KZ_ULT_BIS = ' '
I_KZ_ULT_VON = ' '
I_STGMETH = '0'
I_SZBMETH = '1'
IMPORTING
E_TAGE = t_out-ageing
EXCEPTIONS
DAYS_METHOD_NOT_DEFINED = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT t_out.
WRITE : / t_out-saknr,
t_out-lifnr,
t_out-wrbtr,
t_out-zfbdt,
t_out-ageing.
ENDLOOP.hi sanjeev,
still problem there.
dont worry. just copy this code.
try this code.
TABLES : bsik.
DATA : BEGIN OF t_out OCCURS 0,
bukrs LIKE bsik-bukrs,
saknr LIKE bsik-saknr,
bldat LIKE bsik-bldat,
wrbtr LIKE bsik-wrbtr,
lifnr LIKE bsik-lifnr,
zfbdt like bsik-zfbdt,
ageing type i,
END OF t_out.
parameters : p_date1 type d.
SELECT-OPTIONS : s_bukrs FOR bsik-bukrs,
s_saknr FOR bsik-saknr,
s_lifnr FOR bsik-lifnr.
SELECT bukrs saknr bldat wrbtr lifnr zfbdt
FROM bsik
INTO <b>corresponding fields of</b> TABLE t_out
WHERE saknr IN s_saknr
AND bukrs IN s_bukrs
AND lifnr IN s_lifnr.
<b>loop at t_out.</b>
CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
i_datum_bis = p_date1
i_datum_von = t_out-zfbdt
I_KZ_EXCL_VON = '0'
I_KZ_INCL_BIS = '0'
I_KZ_ULT_BIS = ' '
I_KZ_ULT_VON = ' '
I_STGMETH = '0'
I_SZBMETH = '1'
IMPORTING
E_TAGE = t_out-ageing
EXCEPTIONS
DAYS_METHOD_NOT_DEFINED = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
<b>modify t_out.</b>
clear t_out.
<b>endloop.</b>
LOOP AT t_out.
WRITE : / t_out-saknr,
t_out-lifnr,
t_out-wrbtr,
t_out-zfbdt,
t_out-ageing.
endloop
rgds
anver
Message was edited by: Anversha s -
Could you please check this code
Hi There,
The scenario here is :
I have written this piece of code but its not showing desired result .I think the problem is in the AVGRANGE.
Please look into this and let me know if I am doing anything wrong.
I need to accomplish this task ,if employee E1 & E2 are in Entity1 in Grade S in forecast1 and now in forecast 2 a new employee namely E3 has come in this new forecast and whether he belongs to same entity can be identified by a new account say "F",If "F" is present for that Employee in that particular entity means he belongs to that Entity .Then I need to calculate.
"P" value for E3 for a month=Avg of "P" value for E1 & E2 in Entity1 in Grade S for that month.
I think this code is calculating for invalid combination also.
FIX (&CurrFctScenario,&CurrFctVersion,&CurrYear)
FIX (&SeedCurrency)
FIX(@descendatns("Entity"),@descendatns(GRADE),@Descendants(Employee)
FIX (&CurrMonth:"MAY"
, &SeedHSP
"P"(
IF ( "F"!=#Missing AND "P"==#Missing)
@AVGRANGE(SKIPNONE,"P",@children(Employee)->@currmbr(Grade)->@currmbr(entity));
ENDIF;
ENDFIX
ENDFIX
One more thing as I am testing this code for say two three employees then its working fine but as I am uisng @children(Employee) then I am getting error message
Error: 1012704 Dynamic Calc processor cannot lock more than [200] ESM blocks during the calculation, please increase CalcLockBlock setting and then retry(a small data cache setting could also cause this problem, please check the data cache size setting).
Is there any other way of doing this calculation?
Edited by: user10760185 on Jun 1, 2011 5:35 AMThanks a lot Alp...
Please find the logic of the calculation below:
In forecast1,here E1=employee,S1=Grade,P1=Account member
E1->S1->Entity1->P1= 100
E2->S1->Entity1->P1=200
In forecast2,E3,a new employee has come and if he/she belongs to S1 and Entity1 ,then the value should be
If (E3->F!->@currmbr(grade)->@currmbr(entity)=#Missing AND P1==#Missing)
E3->S1->Entity1->P1= (100+200)/2
I will read the document and will check my cache settings.
Edited by: user10760185 on Jun 1, 2011 11:36 PM -
Urgent where i put this code for delete
hi master
sir this code is right for my requirment but when i put on_delete event system not respons or not delete record
where i put this code for conditional deletion
this is my code
declare
recno number;
begin
if :system.cursor_block='accbal' then
delete accbal where accid=:chartofacc.accid;
go_block('chartofacc');
next_record;
elsif :system.cursor_block='chartofacc' then
select count(*) into recno from accbal where accid=:chartofacc.accid;
if recno=0 then
delete_record;
go_block('chartofacc');
previous_record;
else
message ('system found matching record then no delete master record');
message ('system found matching record then no delete master record');
end if;
end if;
end;
please gide me which event i use
thanking you
aamirHello,
The ON-DELETE triger fires only after a COMMIT statment and only for those records that have been deleted in the block.
Francois -
In my country, Samsung had opened a Game Development Challenge. There's a game that i think they coppied from the other source code. So , i post this topic to need the support from you. Please check this game for me . If it was coppied from any source, please sent to me URL. Thanks. You can download it from http://www.samsungmobilegames.com.vn/view/vn/gamedetail.asp?game_id=46 . Thanks alot...
For one, I don't speak the language that site was in.
And be more specific! Copied the source from what? -
URGENTLY REQUIRE A CODE FOR FOLLOWING--WOULD BE GREAT HELP
HOW TO VALIDATE XML FILE USING SAX PARSER WITH SCHEMAS like .XSD FILES
Mankjas wrote:
URGENTLY REQUIRE A CODE FOR FOLLOWING--WOULD BE GREAT HELPNo, it wouldn't be a great help, as the next time you needed to do something like this you'd still be lost.
And no one here is just simply going to give you code anyway. We'll help you correct yours, and give you advice and tips, but we are not going to do your work for you. And urgent it is not, not to us. And your insisting that it is, is rude. We definately are not going to drop everything we might be doing to "help" you, especially when your essentially demanding that we do your work for you, with no effort on your part, besides. -
I am getting pop ups on safari and firefox lately and am worried I may have malware or something now on my computer doing this. What is the best way to check this out for sure and remove it?
Please review the options below to determine which method is best to remove the Adware installed on your computer.
The Easy, safe, effective method:
http://www.adwaremedic.com/index.php
If you are comfortable doing manual file removals use the somewhat more difficult method:
http://support.apple.com/en-us/HT203987
Also read the articles below to be more prepared for the next time there is an issue on your computer.
https://discussions.apple.com/docs/DOC-7471
https://discussions.apple.com/docs/DOC-8071
http://www.thesafemac.com/tech-support-scam-pop-ups/ -
i create an id. on review option when i enter visa card and security code, it always gives an error msg "Invalid Secruity code". but i use this code for money withdraw from ATM and for shopping also. plz tell the solution ????
The code they are asking for is the last three digits of the number on the back of the card (you don't use this when using an ATM or presenting the card in shops).
-
Urgent need of code for abap hr program
Hi,
Can any one provide with coding to calculate the leave balance for employee
for a given period. Its very urgent.
Thanks in advance,
SubhaHi
See this sample code for calculation of absence quota
using 2001 and 2006 infotypes
make changes as per your requirement
REPORT zh_absence_quota
NO STANDARD PAGE HEADING
MESSAGE-ID zh_msg
LINE-SIZE 169
LINE-COUNT 60(1).
T A B L E S D E C L A R A T I O N S
TABLES: pernr, " Logical PNP
t001p, " Personnel Subarea
t529u, " Employment Status
t500p, " Personnel Area
t501, " Employee Group
t503k, " Employee Subgroup
t549a, " Payroll Area
t554s, " Absence Type
t554t, " Absence Type Texts
t556a, " Quota Type
t527x, " Orgn. Unit
t556b, " Quota Type Text
pa0003. " Payroll Status
INFOTYPES:
0000, " Actions
0001, " Organizational Assignment
2006, " Absence Quota
2001. " Absences
T Y P E S D E C L A R A T I O N S
Employee Absence Structure
TYPES: BEGIN OF s_2001,
pernr TYPE persno, " Personal Number
awart TYPE awart, " Absence Type
subty TYPE subty, " Sub Type
endda TYPE endda, " End date
begda TYPE begda, " Begin date
abrtg TYPE abrtg, " Absence days
ename TYPE emnam, " employee Name
atext TYPE abwtxt, " Absence Type Text
END OF s_2001.
Employee Absence Quota Structure
TYPES: BEGIN OF s_2006,
pernr TYPE persno, " Personal Number
ktart TYPE abwko, " Absence Quota Type
year(4) TYPE n, " Year
subty TYPE subty, " Sub Type
endda TYPE endda, " End date
begda TYPE begda, " Begin date
anzhl TYPE ptm_quonum, " Absence Entitlement days
ename TYPE emnam, " employee Name
ktext TYPE kotxt, " Absence Type Text
kverb TYPE kverb, " Deduction Quota days
anzhb TYPE ptm_quonum, " Balance days
END OF s_2006.
Combined Employee Absence and Quota Structure
TYPES: BEGIN OF s_rep,
pernr TYPE persno, " Personal Number
ktart TYPE abwko, " Absence Quota Type
year(4) TYPE n, " Year
anzhl TYPE ptm_quonum, " Absence Entitlement days
kverb TYPE kverb, " Deduction Quota days
anzhb TYPE ptm_quonum, " Balance days
ktext TYPE kotxt, " Quota Type Text
awart TYPE awart, " Absence Type
abrtg TYPE abrtg, " Absence days
ename TYPE emnam, " employee Name
atext TYPE abwtxt, " Absence Type Text
endda TYPE endda, " End date
begda TYPE begda, " Begin date
END OF s_rep.
Declaration of Variables
DATA : gv_atext TYPE abwtxt, " Absence Type Text
gv_ktext TYPE kotxt, " Absence Type Text
gv_title1 TYPE sylisel, " Report title
gv_year(4) TYPE c, " Year
gv_mon(2) TYPE c, " Month
gv_hrs TYPE abwtg, " Hours
gv_date TYPE sydatum, " Date
gv_date1 TYPE sydatum, " Date
gv_dial. " Color flag
Declaration of Constants
CONSTANTS :
c_x TYPE c VALUE 'X', " Sign
c_1 TYPE persg VALUE '1', " Emp Group
c_pernr(8) TYPE n VALUE '00000000', " Pernr
c_moabw TYPE moabw VALUE '01', " Per SA Grouping
c_mozko TYPE mozko VALUE '01', " Per SA Grouping
c_mopgk TYPE mopgk VALUE '1', " Emp SGrp Grouping
c_endda TYPE sydatum VALUE '99991231', " End Date
c_val1(2) TYPE c VALUE '31', " Date Type
c_val2(2) TYPE c VALUE '12', " Date Type
c_val LIKE p0041-dar01 VALUE '01', " Date Type
c_date1 LIKE sy-datum VALUE '18000101'. " Date
I N T E R N A L T A B L E S D E C L A R A T I O N S
DATA: i_2001 TYPE STANDARD TABLE OF s_2001 WITH HEADER LINE,
i_2006 TYPE STANDARD TABLE OF s_2006 WITH HEADER LINE,
i_rep1 TYPE STANDARD TABLE OF s_2006 WITH HEADER LINE,
i_rep TYPE STANDARD TABLE OF s_rep WITH HEADER LINE.
S E L E C T I O N S C R E E N
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_ktart FOR t556a-ktart, " Absence Quota Type
s_awart FOR t554s-subty. " Absence Type
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(33) text-003. " Quota & Absence
PARAMETERS: p_qa RADIOBUTTON GROUP rb1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(33) text-004. " Quota
PARAMETERS: p_q RADIOBUTTON GROUP rb1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(33) text-005. " Absence
PARAMETERS: p_a RADIOBUTTON GROUP rb1.
SELECTION-SCREEN END OF LINE.SELECTION-SCREEN END OF BLOCK b2.
I N I T I A L I Z A T I O N *
INITIALIZATION.
A T S E L E C T I O N - S C R E E N *
AT SELECTION-SCREEN.
Validate the screen fields
PERFORM validate_screen.
S T A R T - O F - S E L E C T I O N *
START-OF-SELECTION.
Selection of Period
PERFORM get_period.
Get PERNR from LDB
GET pernr.
IF p0000-stat2 <> '0'.
Get the data from PA0001,PA2001, PA2006
PERFORM get_pers_data.
ENDIF.
T O P - O F - P A G E *
TOP-OF-PAGE.
Header of the List
PERFORM header.
E N D - O F - P A G E *
Footer
END-OF-PAGE.
IF p_qa = c_x.
Display both Absence and Quota Data
WRITE /1(188) sy-uline.
ELSEIF p_q = c_x.
Display only Quota Data
WRITE /1(114) sy-uline.
ELSEIF p_a = c_x.
Display only Absence Data
WRITE /1(125) sy-uline.
ENDIF.
E N D - O F - S E L E C T I O N *
END-OF-SELECTION.
Combine the Absence and Quota Data
PERFORM append_data.
IF p_qa = c_x.
Display both Absence and Quota Data
PERFORM display_qa_data.
ELSEIF p_q = c_x.
Display only Quota Data
PERFORM display_q_data.
ELSEIF p_a = c_x.
Display only Absence Data
PERFORM display_a_data.
ENDIF.
*& Form validate_screen
Validation of Selection Screen fields
FORM validate_screen .
Validation of Personnel Number
CLEAR pa0003.
IF NOT pnppernr[] IS INITIAL.
SELECT pernr
FROM pa0003 UP TO 1 ROWS
INTO pa0003-pernr
WHERE pernr IN pnppernr.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e999 WITH 'Incorrect Personnel Number'(006).
ENDIF.
ENDIF.
Validation of Employee Status
CLEAR t529u.
IF NOT pnpstat2[] IS INITIAL.
SELECT SINGLE statv
INTO t529u-statv
FROM t529u
WHERE statv IN pnpstat2 AND
statn = '2' AND
sprsl = sy-langu.
IF sy-subrc <> 0.
MESSAGE e999 WITH 'Invalid Employee Status'(007).
ENDIF.
ENDIF.
Validation of Personnel Area
CLEAR t500p.
IF NOT pnpwerks[] IS INITIAL.
SELECT persa
FROM t500p UP TO 1 ROWS
INTO t500p-persa
WHERE persa IN pnpwerks.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e999 WITH 'Incorrect Personnel Area'(008).
ENDIF.
ENDIF.
Validation of Personnel Sub Area
CLEAR t001p.
IF NOT pnpbtrtl[] IS INITIAL.
SELECT btrtl
FROM t001p UP TO 1 ROWS
INTO t001p-btrtl
WHERE btrtl IN pnpbtrtl.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e999 WITH 'Incorrect Personnel Sub Area'(009).
ENDIF.
ENDIF.
Validation of Employee Group
CLEAR t501.
IF NOT pnppersg[] IS INITIAL.
SELECT persg
FROM t501 UP TO 1 ROWS
INTO t501-persg
WHERE persg IN pnppersg.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e999 WITH 'Incorrect Employee Group'(010).
ENDIF.
ENDIF.
Validation of Employee Sub Group
CLEAR t503k.
IF NOT pnppersk[] IS INITIAL.
SELECT persk
FROM t503k UP TO 1 ROWS
INTO t503k-persk
WHERE persk IN pnppersk.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e999 WITH 'Incorrect Employee Sub Group'(011).
ENDIF.
ENDIF.
Validation of Payroll Area
CLEAR t549a.
IF NOT pnpabkrs[] IS INITIAL.
SELECT abkrs
FROM t549a UP TO 1 ROWS
INTO t549a-abkrs
WHERE abkrs IN pnpabkrs.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e999 WITH 'Incorrect Employee Payroll Area'(026).
ENDIF.
ENDIF.
Validation of Absence Type
CLEAR t554s.
IF NOT s_awart[] IS INITIAL.
SELECT subty
FROM t554s UP TO 1 ROWS
INTO t554s-subty
WHERE subty IN s_awart AND
moabw EQ c_moabw AND
endda EQ c_endda.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e999 WITH 'Incorrect Employee Absence Type'(012).
ENDIF.
ENDIF.
Validation of Absence Quota Type
CLEAR t556a.
IF NOT s_ktart[] IS INITIAL.
SELECT ktart
FROM t556a UP TO 1 ROWS
INTO t556a-ktart
WHERE ktart IN s_ktart AND
mopgk EQ c_mopgk AND
mozko EQ c_mozko AND
endda EQ c_endda.
ENDSELECT.
IF sy-subrc <> 0.
MESSAGE e999 WITH 'Incorrect Employee Quota Type'(013).
ENDIF.
ENDIF.
ENDFORM. "validate_screen
*& Form get_period
Get the Correct Period based on Selection screen selection
FORM get_period.
CLEAR: gv_year,gv_mon, gv_date, gv_date1.
gv_year = sy-datum+0(4).
gv_mon = sy-datum+4(2).
IF pnptimr1 = c_x. " Current Date
pnpbegda = sy-datum.
pnpendda = sy-datum.
ELSEIF pnptimr2 = c_x. " Current Month
CONCATENATE gv_year gv_mon c_val INTO gv_date.
CONCATENATE gv_year gv_mon c_val1 INTO gv_date1.
pnpbegda = gv_date.
pnpendda = gv_date1.
ELSEIF pnptimr3 = c_x. " Current Year
CONCATENATE gv_year c_val c_val INTO gv_date.
CONCATENATE gv_year c_val2 c_val1 INTO gv_date1.
pnpbegda = gv_date.
pnpendda = gv_date1.
ELSEIF pnptimr4 = c_x. " Upto Today
pnpbegda = c_date1.
pnpendda = sy-datum.
ELSEIF pnptimr5 = c_x. " From Today
pnpbegda = sy-datum.
pnpendda = c_endda.
ELSE.
IF ( pnpbegda IS INITIAL AND pnpendda IS INITIAL ).
pnpbegda = c_date1.
pnpendda = c_endda.
ELSEIF pnpbegda IS INITIAL AND NOT pnpendda IS INITIAL.
pnpbegda = c_date1.
pnpendda = pnpendda.
ELSEIF NOT ( pnpbegda IS INITIAL AND pnpendda IS INITIAL ).
pnpbegda = pnpbegda.
pnpendda = pnpendda.
ENDIF.
ENDIF.
ENDFORM. "get_period
*& Form get_pers_data
Get the Absence and Quota Data from PA0001,PA2001,PA2006
FORM get_pers_data.
DATA: lv_year1(4) TYPE n,
lv_year2(4) TYPE n,
lv_date1 TYPE sydatum,
lv_date2 TYPE sydatum,
lv_anzhb TYPE ptm_quonum. " Last Year Balance days
Get data from Respective Infotypes
rp_provide_from_last p0001 space pnpbegda pnpendda.
Absence Data
LOOP AT p2001 WHERE pernr = pernr-pernr AND
begda GE pnpbegda AND
endda LE pnpendda.
IF p2001-awart IN s_awart.
i_2001-pernr = pernr-pernr.
i_2001-subty = p2001-subty.
i_2001-awart = p2001-awart.
i_2001-abrtg = p2001-abrtg.
i_2001-begda = p2001-begda.
i_2001-endda = p2001-endda.
READ TABLE p0001 WITH KEY pernr = p2001-pernr.
i_2001-ename = p0001-ename.
Get the Absence Type Text
CLEAR gv_atext.
SELECT SINGLE atext INTO gv_atext FROM t554t
WHERE sprsl = sy-langu AND
moabw = c_moabw AND
awart = p2001-awart.
IF sy-subrc = 0.
i_2001-atext = gv_atext.
ENDIF.
APPEND i_2001.
CLEAR i_2001.
ENDIF.
ENDLOOP.
Quota Data
LOOP AT p2006 WHERE pernr = pernr-pernr AND
begda GE pnpbegda AND
endda LE pnpendda.
IF p2006-ktart IN s_ktart.
i_2006-pernr = pernr-pernr.
i_2006-subty = p2006-subty.
i_2006-begda = p2006-begda.
i_2006-endda = p2006-endda.
i_2006-year = p2006-endda+0(4).
i_2006-ktart = p2006-ktart.
i_2006-anzhl = p2006-anzhl.
i_2006-kverb = p2006-kverb.
i_2006-anzhb = p2006-anzhl - p2006-kverb.
READ TABLE p0001 WITH KEY pernr = p2001-pernr.
i_2006-ename = p0001-ename.
Get the Quota Type Text
CLEAR gv_ktext.
SELECT SINGLE ktext INTO gv_ktext FROM t556b
WHERE sprsl = sy-langu AND
mopgk = c_mopgk AND
mozko = c_mozko AND
ktart = p2006-ktart.
IF sy-subrc = 0.
i_2006-ktext = gv_ktext.
ENDIF.
APPEND i_2006.
CLEAR i_2006.
ENDIF.
ENDLOOP.
For Vacation Quota (80) get the Balance of the Last Year and
add to the Current Year Quota
LOOP AT i_2006.
IF i_2006-ktart = '80'.
lv_year1 = i_2006-endda+0(4).
lv_year2 = lv_year1 - 1.
CONCATENATE lv_year2 '01' '01' INTO lv_date1.
CONCATENATE lv_year2 '12' '31' INTO lv_date2.
LOOP AT p2006 WHERE pernr = i_2006-pernr AND
begda GE lv_date1 AND
endda LE lv_date2 AND
ktart = '80'.
lv_anzhb = p2006-anzhl - p2006-kverb.
i_rep1-pernr = i_2006-pernr.
i_rep1-ktext = i_2006-ktext.
i_rep1-anzhl = p2006-anzhl.
i_rep1-kverb = p2006-kverb.
i_rep1-ename = i_2006-ename.
i_rep1-begda = p2006-begda.
i_rep1-endda = p2006-endda.
i_rep1-anzhb = lv_anzhb.
i_rep1-ktart = '80'.
i_rep1-year = lv_year2.
APPEND i_rep1.
CLEAR: i_rep1.
ENDLOOP.
ENDIF.
CLEAR: lv_year1, lv_year2,
lv_date1, lv_date2,lv_anzhb.
ENDLOOP.
SORT i_rep1 BY pernr ktart.
ENDFORM. "get_pers_data
*& Form append_data
Put the Absence and Quota Data into one Report Int Table
FORM append_data.
CLEAR: i_rep.
REFRESH: i_rep.
SORT i_2001 BY pernr awart.
SORT i_2006 BY pernr ktart year.
Move I_REP1 data into i_2006
LOOP AT i_rep1.
MOVE-CORRESPONDING i_rep1 TO i_2006.
APPEND i_2006.
CLEAR i_2006.
ENDLOOP.
Move the Absence and Quota Data into a final Int Table
LOOP AT i_2006.
i_rep-pernr = i_2006-pernr.
i_rep-ename = i_2006-ename.
i_rep-ktart = i_2006-ktart.
i_rep-anzhl = i_2006-anzhl.
i_rep-kverb = i_2006-kverb.
i_rep-ktext = i_2006-ktext.
i_rep-anzhb = i_2006-anzhb.
i_rep-year = i_2006-year.
CLEAR i_2001.
CASE i_2006-ktart.
WHEN '81'.
PERFORM get_2001 USING i_2006-pernr '1000' i_2006-year.
WHEN '50'.
PERFORM get_2001 USING i_2006-pernr '1002' i_2006-year.
WHEN '80'.
PERFORM get_2001 USING i_2006-pernr '1001' i_2006-year.
WHEN '56'.
PERFORM get_2001 USING i_2006-pernr '1003' i_2006-year.
WHEN '51'.
PERFORM get_2001 USING i_2006-pernr '1004' i_2006-year.
WHEN '52'.
PERFORM get_2001 USING i_2006-pernr '1005' i_2006-year.
WHEN '54'.
PERFORM get_2001 USING i_2006-pernr '1006' i_2006-year.
WHEN '53'.
PERFORM get_2001 USING i_2006-pernr '1007' i_2006-year.
WHEN '55'.
PERFORM get_2001 USING i_2006-pernr '1008' i_2006-year.
WHEN '57'.
PERFORM get_2001 USING i_2006-pernr '1009' i_2006-year.
WHEN '90'.
PERFORM get_2001 USING i_2006-pernr '2000' i_2006-year.
WHEN '58'.
PERFORM get_2001 USING i_2006-pernr '2001' i_2006-year.
WHEN '59'.
PERFORM get_2001 USING i_2006-pernr '2002' i_2006-year.
WHEN '91'.
PERFORM get_2001 USING i_2006-pernr '2003' i_2006-year.
ENDCASE.
IF sy-subrc <> 0.
APPEND i_rep.
ENDIF.
CLEAR i_rep.
ENDLOOP.
SORT i_rep BY pernr ktart year.
DELETE i_rep WHERE pernr = ' '.
ENDFORM. " append_data
*& Form display_qa_data
Display the Absence and Quota Data
FORM display_qa_data.
DATA: lv_flag, " New Flag
lv_tot2 TYPE ptm_quonum. " Absence Balance days
IF i_rep[] IS INITIAL.
MESSAGE i000 WITH 'No Data found'(014).
ELSE.
LOOP AT i_rep.
toggle color
PERFORM toggle_color.
IF lv_flag <> space.
NEW-LINE.
ENDIF.
AT NEW pernr.
READ TABLE i_rep INDEX sy-tabix.
WRITE:/1 sy-vline,2(8) i_rep-pernr,
10 sy-vline,11(40) i_rep-ename.
ENDAT.
AT NEW ktart.
READ TABLE i_rep INDEX sy-tabix.
WRITE: 1 sy-vline, 10 sy-vline,
51 sy-vline,52(25) i_rep-ktext.
ENDAT.
AT NEW year.
READ TABLE i_rep INDEX sy-tabix.
WRITE: 1 sy-vline, 10 sy-vline,
51 sy-vline,
77 sy-vline, 78(4) i_rep-year,
82 sy-vline, 83(11) i_rep-anzhl,
94 sy-vline, 95(25) i_rep-atext,
120 sy-vline,133 sy-vline,
144 sy-vline,
155 sy-vline,156(13) i_rep-anzhb,
169 sy-vline.
lv_tot2 = lv_tot2 + i_rep-anzhb.
ENDAT.
WRITE: 1 sy-vline, 10 sy-vline,
51 sy-vline, 77 sy-vline,
82 sy-vline, 94 sy-vline,
120 sy-vline,121(12) i_rep-abrtg NO-ZERO,
133 sy-vline,134(10) i_rep-begda NO-ZERO,
144 sy-vline,145(10) i_rep-endda NO-ZERO,
155 sy-vline,169 sy-vline.
NEW-LINE.
AT END OF pernr.
WRITE : /1(169) sy-uline.
SUM.
FORMAT COLOR 3.
WRITE:/1 sy-vline, 10 sy-vline,
51 sy-vline, 77 sy-vline,
82 sy-vline, 94 sy-vline,
120 sy-vline,121(12) i_rep-abrtg,
133 sy-vline,144 sy-vline,
155 sy-vline, 156(13) lv_tot2,
169 sy-vline.
FORMAT COLOR OFF.
WRITE : /1(169) sy-uline.
CLEAR lv_tot2.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM. " display_qa_data
*& Form display_q_data
Display only the Quota Data
FORM display_q_data.
DATA: lv_flag. " New Flag
SORT i_2006 BY pernr ktart year.
IF i_2006[] IS INITIAL.
MESSAGE i000 WITH 'No Data found'(014).
ELSE.
LOOP AT i_2006.
Toggle Color
PERFORM toggle_color.
IF lv_flag <> space.
NEW-LINE.
ENDIF.
AT NEW pernr.
READ TABLE i_2006 INDEX sy-tabix.
WRITE: /1 sy-vline, 2(8) i_2006-pernr,
10 sy-vline,11(40) i_2006-ename.
ENDAT.
AT NEW ktart.
READ TABLE i_2006 INDEX sy-tabix.
WRITE: 1 sy-vline,10 sy-vline,
51 sy-vline,52(25) i_2006-ktext.
ENDAT.
AT NEW year.
READ TABLE i_2006 INDEX sy-tabix.
WRITE: 1 sy-vline, 10 sy-vline,
51 sy-vline,
77 sy-vline,78(4) i_2006-year,
82 sy-vline,83(11) i_2006-anzhl,
94 sy-vline,95(13) i_2006-anzhb,
108 sy-vline.
NEW-LINE.
ENDAT.
AT END OF pernr.
WRITE : /1(108) sy-uline.
SUM.
FORMAT COLOR 3.
WRITE: /1 sy-vline, 10 sy-vline,
51 sy-vline,
77 sy-vline, 82 sy-vline,
94 sy-vline, 95(13) i_2006-anzhb,
108 sy-vline.
FORMAT COLOR OFF.
WRITE : /1(108) sy-uline.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM. " display_q_data
*& Form display_a_data
Display Only the Absence Quota
FORM display_a_data.
DATA: lv_flag. " New Flag
SORT i_2001 BY pernr awart.
IF i_2001[] IS INITIAL.
MESSAGE i000 WITH 'No Data found'(014).
ELSE.
LOOP AT i_2001.
Toggle Color
PERFORM toggle_color.
IF lv_flag <> space.
NEW-LINE.
ENDIF.
AT NEW pernr.
READ TABLE i_2001 INDEX sy-tabix.
WRITE: /1 sy-vline, 2(10) i_2001-pernr,
10 sy-vline,11(40) i_2001-ename.
ENDAT.
WRITE: 1 sy-vline, 10 sy-vline,
51 sy-vline,52(25) i_2001-atext,
77 sy-vline,78(12) i_2001-abrtg,
90 sy-vline,91(10) i_2001-begda,
101 sy-vline,102(10) i_2001-endda,
112 sy-vline.
NEW-LINE.
AT END OF pernr.
WRITE : /1(112) sy-uline.
SUM.
FORMAT COLOR 3.
WRITE: /1 sy-vline, 10 sy-vline,
51 sy-vline,
77 sy-vline,78(12) i_2001-abrtg,
90 sy-vline,101 sy-vline,
112 sy-vline.
FORMAT COLOR OFF.
WRITE : /1(112) sy-uline.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM. " display_a_data
*& Form header
Write the Report Header
FORM header .
data : lv_pers type pbtxt,
lv_orgn type orgtx.
gv_title1 = sy-title. " Set List Header
IF p_qa = c_x.
NEW-PAGE LINE-SIZE 193.
ELSEIF p_a = c_x.
NEW-PAGE LINE-SIZE 125.
ELSEIF p_q = c_x.
NEW-PAGE LINE-SIZE 119.
ENDIF.
Standard header
FORMAT RESET.
CALL FUNCTION 'Z_STANDARD_HEADER'
EXPORTING
title1 = gv_title1.
Get the Personal Area and Org.Unit Texts
clear : lv_pers,lv_orgn.
select single name1 into lv_pers
from t500p where persa = pnpwerks-low.
select single orgtx into lv_orgn
from t527x where sprsl = sy-langu and
orgeh = pnporgeh-low and
endda = c_endda.
if not lv_pers is initial.
write : /2 'Personal Area:'(017), 17(25) lv_pers color 7.
endif.
if not lv_orgn is initial.
write : /2 'Organization Unit:'(021), 20(25) lv_orgn color 3.
endif.
IF p_qa = c_x.
FORMAT COLOR COL_HEADING.
WRITE : /1(169) sy-uline.
WRITE:/1 sy-vline,2(8) 'Emp.No'(015) CENTERED,
10 sy-vline,11(40) 'Employee Name'(016) CENTERED,
51 sy-vline,52(25) 'Quota Description'(018) CENTERED,
77 sy-vline,78(4) 'Year'(027),
82 sy-vline,83(11) 'Entitlement'(019),
94 sy-vline,95(25) 'Absence Description'(022) CENTERED,
120 sy-vline,121(12) 'Absence days'(023),
133 sy-vline,134(10) 'From Date'(024),
144 sy-vline,145(10) 'To Date'(025),
155 sy-vline,156(13) 'Quota Balance'(020),
169 sy-vline.
WRITE : /1(169) sy-uline.
ELSEIF p_q = c_x.
FORMAT COLOR COL_HEADING.
WRITE : /1(108) sy-uline.
WRITE:/1 sy-vline,2(8) 'Emp.No'(015) CENTERED,
10 sy-vline,11(40) 'Employee Name'(016) CENTERED,
51 sy-vline,52(25) 'Quota Description'(018) CENTERED,
77 sy-vline,78(4) 'Year'(027),
82 sy-vline,83(11) 'Entitlement'(019),
94 sy-vline,95(13) 'Quota Balance'(020),
108 sy-vline.
WRITE : /1(108) sy-uline.
ELSEIF p_a = c_x.
FORMAT COLOR COL_HEADING.
WRITE : /1(112) sy-uline.
WRITE:/1 sy-vline,2(8) 'Emp.No'(015) CENTERED,
10 sy-vline,11(40) 'Employee Name'(016) CENTERED,
51 sy-vline,52(25) 'Absence Description'(022) CENTERED,
77 sy-vline,78(12) 'Absence days'(023),
90 sy-vline,91(10) 'From Date'(024),
101 sy-vline,102(10) 'To Date'(025),
112 sy-vline.
WRITE : /1(112) sy-uline.
ENDIF.
ENDFORM. " header
*& Form toggle_color
This routine alters the color of the records in the list
FORM toggle_color.
IF gv_dial = space.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
gv_dial = c_x.
ELSE.
FORMAT COLOR 1 INTENSIFIED OFF.
CLEAR gv_dial.
ENDIF.
ENDFORM. " toggle_color
*& Form get_2001
Get the ABsence type for each Quota type
FORM get_2001 USING p_pernr TYPE persno
p_value TYPE awart
p_year.
LOOP AT i_2001 WHERE pernr = p_pernr AND
awart = p_value AND
endda+0(4) = p_year.
i_rep-awart = i_2001-awart.
i_rep-abrtg = i_2001-abrtg.
i_rep-atext = i_2001-atext.
i_rep-begda = i_2001-begda.
i_rep-endda = i_2001-endda.
APPEND i_rep.
ENDLOOP.
ENDFORM. " get_2001
<b>
Reward points for useful Answers</b>
Regards
Anji -
Problem with this code...please help
The following code is what I've written for a routing system.
- I get machines passed to my class from the 'Machine' class.
How I integrate them into my array is on of the problems that I'm encountering.
This class accepts food from the Machine class, asks the machine to check the size of the first queue, then adds the food to the shortest queue (via the Machine class).
In the simulation food is being given to the packing machine which contains the shortest queue.
package routingSystem;
public class Router {
//attributes.
private int numberOfMachines = 2; //length of array.
private Machine machineArray[]; //this array is of type Machine.
private Food processedFood; //Food item received from the
processing machines
private Machine packingMachine; //The machines that get passed into
//this class - need to use
//these in the code ?????
//Constructor.
public Router() {
Machine machineArray[] = new Machine[numberOfMachines];
addMachine();
public void run() {
int temp = machineArray[0].numberItemsWaiting();
//assign the first size to a temp value with which the other machines queue size can be compared with.
for (int i = 0; i<numberOfMachines; i++){
machineArray[i] = new Machine(/** find out parameters from */); //check this line....
if (machineArray[1].numberItemsWaiting() > temp) {
machineArray[0].addItem(processedFood);
} else {
machineArray[1].addItem(processedFood);
if (machineArray[0].size() == machineArray[1].size()) {
machineArray[0].addItem(processedFood);
//takes the machines as a parameter from the Machine class...
public void addMachine(Machine machine) {
packingMachine = machine;
run();
I'd appreciate any imrovements that you can spot, it just isn't right, the packing machine attribute that I've created isn't being used with the array correctly??
cheers....public Router() {
/*Machine*/ machineArray[] = new Machine[numberOfMachines];
addMachine();
}There may be more wrong... -
PLEASE compile this code on your pc and add some new items then try to update it using update button and we will see my problem clearly which
is:
I have a main window ,by clicking on (add new item) , another window
open to fill the form
on clicking on (save to file),my form will be saved in text file.
if I open this text file using notepad for example,then I found my data
stored but concatenated ,although I add to the saved string "\n"
[hint:you will find two ## to direct u to this line in my code text]
if I change it to "\n\n" then my data is stored in separate lines which
I need.
the Problem that when I read the saved file by clicking on "update data
item" ,the returned
data in the form is not as saved
my code::
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class dataDictionary extends JFrame implements ActionListener
JButton addItem,updateItem,searchItem,exit;
JFileChooser filechooser;
JTextField text1 ;
JTextField text2 ;
JTextField text3 ;
JTextArea area4 ;
JButton saveFile;
public dataDictionary()
super("Main Window");
setSize(400,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addItem = new JButton("add new item");
updateItem = new JButton("update data item");
searchItem = new JButton("search for item");
exit = new JButton ("Exit Program");
addItem.addActionListener(this);
updateItem.addActionListener(this);
searchItem.addActionListener(this);
exit.addActionListener(this);
JLabel label = new JLabel("Data Dictionary Program");
JPanel pane = new JPanel();
pane.setLayout(new GridLayout(5,1,10,10));
pane.add(label);
pane.add(addItem);
pane.add(updateItem);
pane.add(searchItem);
pane.add(exit);
setContentPane(pane);
setVisible(true);
public dataDictionary (String name)
super(name);
setSize(350,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
text1 = new JTextField (30);
text2 = new JTextField (30);
text3 = new JTextField (30);
area4 = new JTextArea (10,30);
saveFile = new JButton("save to file");
JLabel label1 = new JLabel ("Name");
JLabel label2 = new JLabel ("Type");
JLabel label3 = new JLabel ("Date");
JLabel label4 = new JLabel ("Description");
saveFile.addActionListener(this);
JPanel pane =new JPanel();
pane.add(label1);
pane.add(text1);
pane.add(label2);
pane.add(text2);
pane.add(label3);
pane.add(text3);
pane.add(label4);
pane.add(area4);
pane.add(saveFile);
setContentPane(pane);
area4.setLineWrap(true);
area4.setWrapStyleWord(true);
setVisible(true);
public static void main (String[] args)
dataDictionary main = new dataDictionary();
public void actionPerformed (ActionEvent ave )
Object ob = ave.getSource();
if(ob == addItem )
dataDictionary f= new dataDictionary( "form");
if(ob==saveFile )
String a = text1.getText()+"\n"+text2.getText()+"\n"+text3.getText() +"\n"+area4.getText();
String f =text1.getText();
saveInFile(a,f);
JOptionPane.showMessageDialog(null,"The New Data Item save correctly");
if(ob == updateItem)
dataDictionary form= new dataDictionary ("form");
File file = getAFileToOpen();
writeFileToEditor(file);
if(ob == searchItem)
if(ob == exit)
System.exit(0);
public File getAFileToOpen()
File file = null;
File currentdirectory = new File(".");
JFileChooser filechooser = new JFileChooser(currentdirectory);
int replycode = filechooser.showOpenDialog(null);
if (replycode == JFileChooser.APPROVE_OPTION){
file = filechooser.getSelectedFile();
return file;
public void writeFileToEditor(File file)
try{
FileReader filereader = new FileReader(file);
BufferedReader bufferedreader = new BufferedReader(filereader);
String lineread = "";
text1.setText(bufferedreader.readLine());
text2.setText(bufferedreader.readLine());
text3.setText(bufferedreader.readLine());
while ((lineread = bufferedreader.readLine()) != null){
area4.setText(lineread + "\n");
filereader.close();
}catch (IOException ioe){
System.err.println("IOException: " + ioe.getMessage());
public void saveInFile(String s,String fileName)
try{
File f=new File(fileName+".txt");;
FileWriter fw = new FileWriter(f);
StringReader sr = new StringReader(s);
BufferedReader br = new BufferedReader(sr);
String lineread = "";
while((lineread=br.readLine()) != null )
fw.write(lineread+"\n\r");
fw.flush();
fw.close();
catch(IOException io){
System.err.println();
}This can't be called a good design but works fine and sound.
Study this code and compare it against your original code.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class BlackHorse extends JFrame implements ActionListener{
JButton addItem,updateItem,searchItem,exit;
JFileChooser filechooser;
JTextField text1 ;
JTextField text2 ;
JTextField text3 ;
JTextArea area4 ;
JButton saveFile;
BlackHorse form;
public BlackHorse(){
super("Main Window");
setSize(400,200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addItem = new JButton("add new item");
updateItem = new JButton("update data item");
searchItem = new JButton("search for item");
exit = new JButton ("Exit Program");
addItem.addActionListener(this);
updateItem.addActionListener(this);
searchItem.addActionListener(this);
exit.addActionListener(this);
JLabel label = new JLabel("Data Dictionary Program");
JPanel pane = new JPanel();
pane.setLayout(new GridLayout(5,1,10,10));
pane.add(label);
pane.add(addItem);
pane.add(updateItem);
pane.add(searchItem);
pane.add(exit);
setContentPane(pane);
setVisible(true);
form = new BlackHorse("form");
public BlackHorse (String name){
super(name);
setSize(350,500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
text1 = new JTextField (30);
text2 = new JTextField (30);
text3 = new JTextField (30);
area4 = new JTextArea (10,30);
saveFile = new JButton("save to file");
JLabel label1 = new JLabel ("Name");
JLabel label2 = new JLabel ("Type");
JLabel label3 = new JLabel ("Date");
JLabel label4 = new JLabel ("Description");
saveFile.addActionListener(this);
JPanel pane = new JPanel();
pane.add(label1);
pane.add(text1);
pane.add(label2);
pane.add(text2);
pane.add(label3);
pane.add(text3);
pane.add(label4);
pane.add(area4);
pane.add(saveFile);
setContentPane(pane);
area4.setLineWrap(true);
area4.setWrapStyleWord(true);
setVisible(false);
public static void main (String[] args){
BlackHorse main = new BlackHorse();
public void actionPerformed (ActionEvent ave ){
Object ob = ave.getSource();
if (ob == addItem ){
form.setVisible(true);
form.text1.setText("");
form.text2.setText("");
form.text3.setText("");
form.area4.setText("");
else if (ob == saveFile){
String a = text1.getText() + "\n"
+ text2.getText() +"\n"
+ text3.getText() +"\n"
+ area4.getText() + "\n"; // just in case ....
String f = text1.getText();
saveInFile(a,f);
JOptionPane.showMessageDialog(null,"The New Data Item save correctly");
else if(ob == updateItem){
form.setVisible(true);
File file = getAFileToOpen();
writeFileToEditor(file);
else if(ob == searchItem){
else if(ob == exit){
System.exit(0);
public File getAFileToOpen(){
File file = null;
JFileChooser filechooser = new JFileChooser(".");
int replycode = filechooser.showOpenDialog(null);
if (replycode == JFileChooser.APPROVE_OPTION){
file = filechooser.getSelectedFile();
return file;
public void writeFileToEditor(File file){
try{
BufferedReader br = new BufferedReader(new FileReader(file));
String lineread = "";
form.text1.setText(br.readLine());
form.text2.setText(br.readLine());
form.text3.setText(br.readLine());
form.area4.setText("");
while ((lineread = br.readLine()) != null){
form.area4.append(lineread + "\n");
br.close();
catch (IOException ioe){
System.err.println("IOException: " + ioe.getMessage());
public void saveInFile(String s, String fileName){
try{
File f = new File(fileName+".txt");
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(f)));
StringReader sr = new StringReader(s);
BufferedReader br = new BufferedReader(sr);
String lineread = "";
while ((lineread = br.readLine()) != null){
pw.println(lineread);
pw.close();
catch(IOException io){
System.err.println();
} -
Understunding this code for having two instanciation of applets
this an exemple i would like to understund how this code work and how it make difference between register() and register(buffer, (short)(offset + 1), (byte)buffer[offset]);
protected MyApplet1(byte[] buffer, short offset, byte length) {
// data offset is used for application specific parameter.
// initialization with default offset (AID offset).
short dataOffset = offset;
boolean isOP2 = false;
if (length >= 9) {
// Install parameter detail. Compliant with OP 2.0.1.
// | size | content
// |------|---------------------------
// | 1 | [AID_Length]
// | 5-16 | [AID_Bytes]
// | 1 | [Privilege_Length]
// | 1-n | [Privilege_Bytes] (normally 1Byte)
// | 1 | [Application_Proprietary_Length]
// | 0-m | [Application_Proprietary_Bytes]
// shift to privilege offset
dataOffset += (short)( 1 + buffer[offset]);
// finally shift to Application specific offset
dataOffset += (short)( 1 + buffer[dataOffset]);
/**@todo: IF NECESSARY, USE COMMENTS TO CHECK LENGTH*/
// // checks wrong data length
// if(buffer[dataOffset] != <PUT YOUR PARAMETERS LENGTH> )
// // return received proprietary data length in the reason
// ISOException.throwIt((short)(ISO7816.SW_WRONG_LENGTH + offset + length - dataOffset));
// go to proprietary data
dataOffset++;
// update flag
isOP2 = true;
else {
// Install parameter compliant with OP 2.0.
/**@todo: IF NECESSARY, USE COMMENTS TO CHECK LENGTH*/
// if(length != <PUT YOUR PARAMETERS LENGTH> )
// ISOException.throwIt((short)(ISO7816.SW_WRONG_LENGTH + length));
/**@todo: PUT YOUR CREATION ACTION HERE*/
// register this instance
if (isOP2) {
register(buffer, (short)(offset + 1), (byte)buffer[offset]);
else {
register();
}On a GlobalPlatform compliant card, the constructor of an applet is called during the last step of the applet's installation process.
The "buffer" parameter given as argument to the constructor usually contains: the instance AID, the applet's privileges and applet's specific bytes.
When installing an applet on a card you can specify 3 different kind of AIDs:
- the package AID
- the applet AID
- the applet instance AID
register(buffer, (short)(offset + 1), (byte)buffer[offset]); will register the applet with the JCRE using the applet instance AID specified in the buffer parameter
register(); will register the applet with the JCRE using the applet AID -
Would someone be willing to check as3 code for a guestbook
Would someone be willing to check out some as3 code for a guestbook? I'm an old person, and can't seem to get it working.
Thanks!Ned suggested that I post the code, so everyone could see it. The SWF works, but the code doesn't. Any help appreciated!
package com.mgraph\
//IMPORTS
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events::EventDispatcher/dispatchEventFunction();
import flash.events::EventDispatcher/dispatchEvent();
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.events.KeyboardEvent;
import flash.geom.Rectangle;
import flash.net::URLLoader/onComplete();
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import com.utils.StringUtils;
import com.caurina.transitions.Tweener;
import com.pageflip.Page;
import com.pageflip.PageEvent;
public class Guestbook extends MovieClip {
//PRIVATE VARS
private var myXML:XML;
private var frm:TextFormat;
private var popup_mc:MovieClip;
private var greySprite:Sprite;
private var initPosition:Number;
private var dy:Number;
private var initContentPos:Number;
private var moveVal:Number;
private var rectScroll:Rectangle;
private var stageWidth:Number;
private var stageHeight:Number;
public function Guestbook(){
addEventListener(Event.ADDED_TO_STAGE,init);
private function init(e:Event):void {
stage.showDefaultContextMenu = false;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stageWidth = stage.stageWidth;
stageHeight = stage.stageHeight;
// LOAD THE XML
var xmlPath:String;
var xmlLoader:URLLoader = new URLLoader;
if (root.loaderInfo.parameters.myconfig) {
// XML PATH FROM HTML flashvars (myconfig)
xmlPath = root.loaderInfo.parameters.myconfig;
else {
// DEFAUL PATH OF XML
xmlPath = "config.xml";
xmlLoader.load(new URLRequest(xmlPath));
xmlLoader.addEventListener(Event.COMPLETE,xmlLoaded);
private function xmlLoaded(e:Event):void {
// XML LOADED COMPLETE
myXML = new XML(e.target.data);
// ADD EVENT LISENER TO FIELDS AND TO (send_btn)
form_mc.name_txt.addEventListener(TextEvent.TEXT_INPUT,clearAlert);
form_mc.email_txt.addEventListener(TextEvent.TEXT_INPUT,clearAlert);
form_mc.message_txt.addEventListener(TextEvent.TEXT_INPUT,clearAlert);
form_mc.email_txt.addEventListener(Event.CHANGE,checkMail);
addMouseEvent(form_mc.send_btn,sendEvent);
// CREATE TEXT FORMAT (frm)
frm = new TextFormat ;
frm.leading = 4;
form_mc.message_txt.defaultTextFormat = frm;
// LOAD BACKGROUND IMAGE
var backLoader:Loader = new Loader();
backLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,backLoaded);
backLoader.load(new URLRequest(myXML.img_back));
// ADD KEYBOARD EVENT WHEN PRESSING ENTER KEY
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyboardDown);
// CREATE THE GREY SPRITE
greySprite = new Sprite ;
greySprite.graphics.beginFill(0x000000,0.2);
greySprite.graphics.drawRect(0,0,stageWidth,stageHeight);
greySprite.graphics.endFill();
greySprite.useHandCursor = false;
// CREATE THE POPUP and ADD EVENTLISTENER TO (close_btn)
popup_mc = new popup_obj;
popup_mc.x = (stageWidth - popup_mc.width)/2;
popup_mc.y = (stageHeight - popup_mc.height)/2;
addMouseEvent(popup_mc.close_btn,closeEvent);
private function keyboardDown(e:KeyboardEvent):void{
if(e.keyCode == 13){
// STOP USING BREAK LINE IN message_txt
stage.focus = null;
private function backLoaded(e:Event):void{
// BACKGROUND LOADED COMPLETE
var back_mc:MovieClip = new MovieClip;
back_mc.addChild(e.target.content);
addChildAt(back_mc,0);
form_mc.wait_mc.visible = false;
startPageFlip();
// START LOADING GUEST MESSAGE FROM DATABASE
load_guestbook();
private function startPageFlip():void{
var flipedPage:Page = new Page(this, stageWidth, stageHeight, 0, 0);
flipedPage.turnPageForward();
private function load_guestbook():void {
// GET MESSAGES FROM DATABASE USING PHP
var guestLoad:URLLoader = new URLLoader ;
var guestReq:URLRequest = new URLRequest(myXML.phpURL);
guestReq.method = URLRequestMethod.POST;
guestReq.data = new URLVariables ;
guestReq.data["getMessage"] = 1;
guestLoad.addEventListener(Event.COMPLETE,bookLoaded);
guestLoad.load(guestReq);
private function bookLoaded(e:Event):void {
// MESSAGES LOADED SUCCESSFULLY FROM DATABASE
var bookXML:XML = new XML(e.target.data);
showMessages(bookXML);
private function showMessages(_xml:XML):void{
var guest_mc:MovieClip;
// CREATE (guest_mc) to SHOW EACH GUEST NAME & MESSSAGE
for (var u=0; u<_xml.guest.length(); u++) {
guest_mc = new messageObj ;
guest_mc.y = 95 * u;
//CAPITALIZE THE FIRST CHAR IN NAME
guest_mc._Name = StringUtils.capitalize(_xml.guest[u].name);
guest_mc._Msg = _xml.guest[u].msg;
guest_mc._Date = _xml.guest[u].sdate;
guest_mc.guestName_txt.htmlText = setHtmlFormat(14,myXML.name_color,guest_mc._Name);
//IF guestMessage_txt TEXT LENGTH > 110 substr guestMessage_txt AND ADD (...)
guest_mc.guestMessage_txt.htmlText = setHtmlFormat(12,myXML.message_color,StringUtils.capitalize(StringUtils.truncate(_xml.gue st[u].msg,110,"...")));
guest_mc.guestMessage_txt.setTextFormat(frm);
guest_mc.tabChildren = false;
guest_mc.tabEnabled = false;
// ADD EVENT LISTISTENER TO (readMore_btn) FOR EACH (guest_mc)
addMouseEvent(guest_mc.readMore_btn,readEvent);
msgContainer.addChild(guest_mc);
// SHOW/HIDE SCROLL
if (msgContainer.height < mask_mc.height) {
scroller.scroll_btn.visible = false;
else {
this.mouseChildren = false;
scroller.scroll_btn.y = 0;
if(msgContainer.y != 10){
Tweener.addTween(msgContainer,{y:10,time:1.5,onComplete:initScrollPos});
else{
initScrollPos();
scroller.scroll_btn.visible = true;
// ADD EVENT TO SCROLL
addMouseEvent(scroller.scroll_btn,scroll_Event);
scroller.scroll_btn.addEventListener(MouseEvent.MOUSE_UP,scroll_Event);
private function initScrollPos():void{
this.mouseChildren = true;
dy = 0;
initPosition = scroller.scroll_btn.y = scroller.bar_mc.y;
initContentPos = msgContainer.y;
moveVal = (msgContainer.height-mask_mc.height)/(scroller.bar_mc.height-scroller.scroll_btn.height);
rectScroll = new Rectangle(scroller.bar_mc.x + 4,scroller.bar_mc.y,0,scroller.bar_mc.height - scroller.scroll_btn.height);
private function readEvent(me:MouseEvent):void {
var _this = me.currentTarget;
switch (me.type) {
case "mouseOver" :
_this.alpha = 0.8;
break;
case "mouseOut" :
_this.alpha = 1;
break;
case "mouseDown" :
// SHOW POPUP WITH MORE INFORMATIONS ABOUT THE CURRENT MESSAGE
popup_mc.pop_nom.htmlText = setHtmlFormat(15,myXML.name_color,_this.parent._Name) + setHtmlFormat(13,myXML.datePosted_color," - Posted "+_this.parent._Date);
popup_mc.pop_message.htmlText = setHtmlFormat(13,myXML.message_color,StringUtils.capitalize(_this.parent._Msg));
popup_mc.pop_message.autoSize = TextFieldAutoSize.LEFT;
popup_mc.pop_message.setTextFormat(frm);
popup_mc.back_mc.height = popup_mc.pop_message.height + 50;
popup_mc.x = (stageWidth - popup_mc.width)/2;
popup_mc.y = (stageHeight - popup_mc.height)/2;
addChild(greySprite);
addChild(popup_mc);
popup_mc.alpha = 0;
greySprite.alpha = 0;
Tweener.addTween(popup_mc,{alpha:1,time:0.6});
Tweener.addTween(greySprite,{alpha:1,time:0.6});
break;
private function setHtmlFormat(_size:Number,_color,_txt:String):String{
var htmlFrm:String = "<font size='"+_size+"'color='"+_color+"'>"+_txt+"</font>";
return htmlFrm;
private function closeEvent(me:MouseEvent):void {
switch (me.type) {
case "mouseOver" :
popup_mc.close_btn.alpha = 0.8;
break;
case "mouseOut" :
popup_mc.close_btn.alpha = 1;
break;
case "mouseDown" :
if (stage.contains(popup_mc)) {
Tweener.addTween(greySprite,{alpha:0,time:0.6,onComplete:function(){removeChild(greySprit e)}});
Tweener.addTween(popup_mc,{alpha:0,time:0.6,onComplete:function(){removeChild(popup_mc)}} );
break;
private function scroll_Event(me:MouseEvent):void {
switch (me.type) {
case "mouseOver" :
scroller.scroll_btn.alpha = 0.7;
break;
case "mouseOut" :
scroller.scroll_btn.alpha = 1;
break;
case "mouseUP" :
scroller.scroll_btn.stopDrag();
scroller.scroll_btn.removeEventListener(Event.ENTER_FRAME, scrollMove);
break;
case "mouseDown" :
scroller.scroll_btn.startDrag(false, rectScroll);
scroller.scroll_btn.addEventListener(Event.ENTER_FRAME, scrollMove);
stage.addEventListener(MouseEvent.MOUSE_UP, releaseOut);
break;
private function scrollMove(event:Event):void {
dy = Math.abs(initPosition - scroller.scroll_btn.y);
msgContainer.y = Math.round(dy * -1 * moveVal + initContentPos);
private function releaseOut(me:MouseEvent):void {
scroller.scroll_btn.stopDrag();
scroller.scroll_btn.removeEventListener(Event.ENTER_FRAME, scrollMove);
stage.removeEventListener(MouseEvent.MOUSE_UP, releaseOut);
private function sendEvent(e:MouseEvent):void {
switch (e.type) {
case "mouseOver" :
form_mc.send_btn.alpha = 0.7;
break;
case "mouseOut" :
form_mc.send_btn.alpha = 1;
break;
case "mouseDown" :
// CHECK FIELDS AND EMAIL THEN SEND DATA TO PHP
if (form_mc.name_txt.text == "") {
stage.focus = form_mc.name_txt;
show_alert("You must enter the : « Name »");
else if (form_mc.email_txt.text == "") {
stage.focus = form_mc.email_txt;
show_alert("You must enter the : « E-mail »");
else if (form_mc.validating.currentFrame == 1) {
stage.focus = form_mc.email_txt;
form_mc.validating.alpha = 1;
form_mc.validating.gotoAndStop(1);
show_alert("« E-mail » address is incorrect");
else if (form_mc.message_txt.text == "") {
stage.focus = form_mc.message_txt;
show_alert("You must enter the : « Message »");
else {
sendData();
break;
private function checkMail(e:Event):void {
form_mc.validating.alpha = 1;
var mail_validation:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
mail_validation.test(form_mc.email_txt.text);
if (mail_validation.test(form_mc.email_txt.text) == true) {
form_mc.validating.gotoAndStop(2);
form_mc.alert_txt.text = "";
else {
form_mc.validating.gotoAndStop(1);
private function clearAlert(te:TextEvent):void {
if (form_mc.alert_txt.text != "") {
form_mc.alert_txt.text = "";
private function show_alert(txt:String):void {
form_mc.alert_txt.htmlText = "<font color='" + myXML.alert_color + "'>" + txt + "</font>";
private function sendData():void {
// SEND NAME-EMAIL-MESSAGE TO PHP
this.mouseChildren = false;
form_mc.wait_mc.visible = true;
var phpLoad:URLLoader = new URLLoader ;
var phpReq:URLRequest = new URLRequest(myXML.phpURL);
phpReq.method = URLRequestMethod.POST;
phpReq.data = new URLVariables ;
phpReq.data["name"] = StringUtils.stripTags(form_mc.name_txt.text);
phpReq.data["email"] = form_mc.email_txt.text;
phpReq.data["message"] = StringUtils.stripTags(form_mc.message_txt.text);
phpLoad.addEventListener(Event.COMPLETE,insertPHP);
phpLoad.load(phpReq);
private function insertPHP(e:Event):void {
this.mouseChildren = true;
var phpXML:XML = new XML(e.target.data);
form_mc.send_btn.mouseEnabled = true;
form_mc.wait_mc.visible = false;
if (phpXML.inserted == 1) {
startPageFlip();
form_mc.alert_txt.htmlText = myXML.insert_ok;
form_mc.validating.alpha = 0;
form_mc.validating.gotoAndStop(1);
while (msgContainer.numChildren) {
msgContainer.removeChildAt(msgContainer.numChildren-1);
// SHOW THE CURRENT POSTED MESSAGE AND CLEAR FIELDS
showMessages(phpXML);
clearFields();
else {
form_mc.alert_txt.htmlText = myXML.insert_error;
private function clearFields():void {
form_mc.name_txt.text = "";
form_mc.email_txt.text = "";
form_mc.message_txt.text = "";
form_mc.validating.gotoAndStop(1);
form_mc.validating.alpha = 0;
private function addMouseEvent(_targ,_func):void {
_targ.buttonMode = true;
_targ.mouseChildren = false;
_targ.addEventListener(MouseEvent.MOUSE_OVER,_func);
_targ.addEventListener(MouseEvent.MOUSE_OUT,_func);
_targ.addEventListener(MouseEvent.MOUSE_DOWN,_func); -
System.in code for Quiz(please help)
I have a Question for all you gifted people:
I am designing a sort of quiz which takes questions and three possible answers from a database(which also holds the real answer).It prints these on the dos screen and I then have a System.in statement which allows the user to enter his or her answer (eg A,B,C or 1,2,3). I need a way of adding up the score at the end!!I was thinking of storing there answers in an array and compairing there answer to my correct answer in the database and if it is the same add 1 and if it not the same add 0???
How would i write the System.in answers into an array and add them up???
These are my thoughts on how to do this i would love to hear yours!! And also a help with writing the code for the above system of scoreing would be GREATLY appriciated!!
thanks everyone,
james.Here's an example of how to get input from a user (like when they answer a question):
import java.io.*;
public class Example {
public static void main(String[] args) {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
// now anytime you call input.readLine(), it will let the person input something
System.out.println("Type something in:");
// you always hafta make sure you catch IOException in case it happens
String s = "";
try {
s = input.readLine(); // get input
catch (IOException e) { // something went wrong
e.printStackTrace(); // show error
System.exit(0); // abort
System.out.println("You typed: "+s); // show what was typed
}Good luck.
Maybe you are looking for
-
New ipod touch 4th generation trouble
Do i need to sync with iTunes before using it ? I try turning it on and I get the itunes + usb symbol, then the ipod shuts off. I'm used to my iphone, never had an ipod touch before. Just got it yesterday and charged it up.
-
Updation of indicators in planning file MD21
Dear Guru's, When the indicators inside the planning file entry (MD21) gets updated e.g. NTECH, NETPL & reset props. I observed that even for newly created materials these indicators are updated & for old materials which had gone through MRP run are
-
Having trouble moving files to external hard drive
I have a freeagent pc&mac ext. hd that i usually use on my pc. I have used it on my mac in the past but i tried trasnfering all of the music from my macbook to my ext. hd and i got the following error message: "The item could not be moved because Fre
-
Notes sync ios 8.1.3
Hi, My Notes won't' sync between my Mac bookpro running on Maverick since I updated my iphone to ios 8.1.3 with icloud account. Checked over and over can't find the solution. Thanks for helpful solutions!
-
Hi All, I'm think of buying the new Apple TV but I have a few questions about it? What does the apple tv connect to for its content (not including itunes store content)? Do I need to have a computer running itunes on whenever I want to use my apple t