Calculation program
I'm trying to create a program that prints whether a year is a leap year or not. A leap year is divisible by 4 but not 100 or is divisible by 400.
I just can't understand what type of "maths" to enter into the if statements.
I've got this so far:
import java.util.*;
public class TestVar2
{ public static void main (String[] args)
{ Scanner sc = new Scanner(System.in);
System.out.println("Enter year : ");
int year = sc.nextInt();
if (year )
{ System.out.println(year + "is a leap year");
else
{ System.out.println(year + "is a normal year"); }}}
I'm pretty sure I need to use a boolean somehow as well.
still don't get how to put it into the code* take a number input
* modulus operation to 4 and 400, test if remainder is 0
* if 0, output leap, else, output not leap.
Similar Messages
-
ForLoop Square Root Calculator Program
* Programmer: R McBride
* Date: November 29, 2006
* Filename: SquareRootForLoop.java
* Purpose: This program uses for()loops to
* find the square root of a number
* up to four decimal places long.
import APCS.Keyboard;
class SquareRootForLoopTest1
public static void main (String[]args)
//define variables
double SquareRoot = 0; //holds initial value
double num1 = 0;
boolean done = false;
double tempReg1 = 0; //holds initial value of i
double tempReg2 = 0; //holds
double tempReg3 = 0;
//while loop start
// while (!done)
//program input
System.out.println("\t\t\tSQUARE ROOT CALCULATOR PROGRAM");
System.out.println(""); //skip line
System.out.println("Enter the number you would like to be square rooted or [0] to end the program.");
System.out.print("");
SquareRoot = Keyboard.readInt();
System.out.println(""); //skip line
System.out.println("You entered "+SquareRoot+".");
System.out.println(""); //skip line
//for loop function
for(int i = 0; i < 999999; i++)
tempReg1 = i * i;
tempReg2 = i;
// while (!done)
if(tempReg1 == SquareRoot)
System.out.println("The square root is "+tempReg2);
System.out.println("");
else
System.out.print("");
//while loop check to finish
// if(SquareRoot == 0)
// done = true;
// }//end while loop
}Here is my code for and of you who ever wants to use it. Our assignment was to make a square root calculator using ForLoop (a.k.a. no square root functions).
My question is, how would I make it increase by .0001 instead of 1 every loop? I need it to do that so I can find square roots of numbers of numbers that have decimals for squares.* Programmer: R McBride
* Date: November 29, 2006
* Filename: SquareRootForLoop.java
* Purpose: This program uses for()loops to
* find the square root of a number
* up to four decimal places long.
import APCS.Keyboard;
class SquareRootForLoopTest1
public static void main (String[]args)
//define variables
double SquareRoot = 0; //holds initial value
double num1 = 0;
boolean done = false;
double tempReg1 = 0; //holds initial value of i
double tempReg2 = 0; //holds
double tempReg3 = 0;
//while loop start
// while (!done)
//program input
System.out.println("\t\t\tSQUARE ROOT CALCULATOR PROGRAM");
System.out.println(""); //skip line
System.out.println("Enter the number you would like to be square rooted or [0] to end the program.");
System.out.print("");
SquareRoot = Keyboard.readInt();
System.out.println(""); //skip line
System.out.println("You entered "+SquareRoot+".");
System.out.println(""); //skip line
//for loop function
for(double i = 0; i < 999999; i+=.0001)
tempReg1 = i * i;
tempReg2 = i;
// while (!done)
if(tempReg1 == SquareRoot)
System.out.println("The square root is "+tempReg2);
System.out.println("");
else
System.out.print("");
//while loop check to finish
// if(SquareRoot == 0)
// done = true;
// }//end while loop
}Still doesn't work. =[ -
Enhancement option for excise duty calculation program - /BEV2/EDMSESES
Hi,
My requirement is to enhance the excise duty calculation program /BEV2/EDMSESES. I searched the user exit using the package /BEV2/ED, but was not able find any user exit. So can you please help me how to enhance this standard program.
Thanks in advance,
SudhanvaHi,
My requirement is to enhance the excise duty calculation program /BEV2/EDMSESES. I searched the user exit using the package /BEV2/ED, but was not able find any user exit. So can you please help me how to enhance this standard program.
Thanks in advance,
Sudhanva -
I need help in a calculator program
hi
I'm writing a calculator program and i keep having this error in the actionPerformed method:
this is the error :
symbol : method parseInt (int)
location: class java.lang.Integer
tf.setText( Integer.parseInt(result));
^
1 error
here's the actionPerformed method :
public void actionPerformed(ActionEvent e) {
int num1, num2, result;
char c = e.getActionCommand().charAt(0);
switch(c)
case '0': //theses are keys 0 to 9 on the calculator
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':
tf.setText(tf.getText( ) + c); //concatenation of the numbers
break;
case 'C': //this is the clear button
tf.setText("");
break;
switch (c)
case '+': //if the key + is presses
num1= Integer.parseInt(tf.getText()); //stores the 1st number in the num1 variable
tf.setText("");//clears the display
num2=Integer.parseInt(tf.getText()); //stores the 2nd number in num2 variable
result= (num1 + num2) ;//adds num1+num2
break;
case 'x': //theses are the other operations that i haven't done yet
case '-':
case '/':
tf.setText("");
case '=':
tf.setText( Integer.parseInt(result));//this is where the error isOr rather "tf.setText( String.valueOf(result));".
You should not be parsing an integer value from its string representation but the opposite: trying to get a string from an integer value. -
I've designed Calculator Program, used by String function
Hello Everyone,
I've designed Calculator Program, used by String function. U've any Feedback in this program, cantact me.
Thanks & Regards,
SABARI SARAVANAN M
Certified LabVIEW Associate Developer
Attachments:
calculator.vi 71 KBHi Jitendra,
Does the dump log shows that the cause is memory shortage?
Thanks and Best Regards,
Vikas Bittera.
**Points for useful answers** -
My wife's Centro had a basic Calculater program on the applications screen. We had to purchase a reconditioned replacement and all is fine except the Calculator program is missing. Does anyone know how to get a copy of it so I can reinstall it?
Post relates to: Treo 680 (Cingular)
Yes, "All" is used for Applications. For some reason I do not think the refurbished Centro had the program installed. I do not recall noticing it (it could have been there at one time) when we got the phone last month.
Message Edited by temco on 09-29-2008 08:09 AM
This question was solved.
View Solution.Did you check to make sure that all the programs are showing on your device?
Click on the home button. Then check the top right and make sure that "all" is highlighted so that all the programs on the device are showing up.
Post relates to: Tungsten E2 -
Could u guys help me with a calculator program
hi
i'm writing a calculator program for my java class and the code ur about to read actually works but when i click on the keypad i don't get any numbers in the display screen, the textfield
Could u guys have a look at it please:
here we go
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;
public class Calculator extends JFrame implements ActionListener {
public boolean firstDigit;
public int temp1 = 0;
public int temp = 0;
public int result = 0;
public String opr = "";
JTextField tf= new JTextField ("",20) ; //sets the display initially at 0
//tf.setEditable (false) ; this doesn't work
JPanel pan = new JPanel() ;
JButton bclear= new JButton("C") ;
JButton b0= new JButton("0") ;
JButton badd = new JButton("+") ;
JButton bsub = new JButton("-") ;
JButton bmult = new JButton("x");
JButton bdiv = new JButton("/") ;
JButton bpoint= new JButton(".");
JButton bequal = new JButton("=");
public Calculator (String title) // constructor
super(title) ;
pan.add(tf);
for ( int i=1; i<=3; i++)
JButton butt=new JButton(""+i);
butt.addActionListener(this);
pan.add(butt); }
badd.addActionListener(this);
pan.add(badd);
for ( int i=4; i<=6; i++)
JButton butt=new JButton(""+i);
butt.addActionListener(this);
pan.add(butt);
bsub.addActionListener(this);
pan.add(bsub);
for ( int i=7; i<=9; i++)
JButton butt=new JButton(""+i);
butt.addActionListener(this);
pan.add(butt);
bmult.addActionListener(this);
pan.add(bmult);
bclear.addActionListener(this);
pan.add(bclear);
b0.addActionListener(this);
pan.add(b0);
bpoint.addActionListener(this);
pan.add(bpoint);
bequal.addActionListener(this);
pan.add(bequal);
bdiv.addActionListener(this);
pan.add(bdiv);
//pan.add(new Button(""));
setContentPane(pan) ;
public boolean action(Event e, Object o)
//checks for operator keys
if (e.target == badd)
temp1 = temp; //to "save" for calculation
opr = "+";
else if (e.target == bsub)
temp1 = temp;
opr = "-";
else if (e.target == bmult)
temp1 = temp;
opr = "*";
else if (e.target == bdiv)
temp1 = temp;
opr = "/";
else if (e.target == bequal)
result = calculate(temp1,opr,temp);
tf.setText(Integer.toString(result)); //does the calculation
temp= result; //to be able to do an operation on the result
else if (e.target == bclear)
tf.setText("");
temp1 = 0; //resets the temps and display to 0
temp = 0;
else
//numeric buttons
if (firstDigit)
tf.setText( o.toString() );
firstDigit = false;
temp = Integer.parseInt(tf.getText()); //saves the number in a temp
else
tf.setText(tf.getText() + o.toString()); //for numbers longer than 1 digit
temp = Integer.parseInt(tf.getText());
return true;
firstDigit = true; // GET READY FOR NEXT NUMBER
return true;
public int calculate(int num1,String op, int num2 )
// calculate the numbers
int answers = 0;
if (op == "+")
answers = num1 + num2; //does the calculation for +
else if(op == "-")
answers = num1 - num2; //does the calculation for -
else if(op == "/")
if(num2 == 0)
tf.setText("ERROR");//gives error message if dividing by 0
else
answers = num1 / num2;
else if(op == "*")
answers = num1 * num2; //does the calculation for *
return answers;
public void actionPerformed(ActionEvent e) {
Object source = e.getSource() ;
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName() );
catch (Exception e) {
System.err.println("impossible to use system setting : " + e ); }
Calculator fen = new Calculator("CALCULATOR");
fen.setSize(235, 300);
fen.setVisible(true);
fen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);I Hope this would help you.
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=2&txtCodeId=2275
Thanks,
Vikas Karwal
[email protected] -
Error in Proportional Factor Calculation Program
Hi ,
I have developed an ABAP Program to calculate Proportional Factor(PF) as below.
Generally,to calculate the PF for a period , we need to use transaction /sapapo/sdp94 to create a profile .After doing that , to calculate PF we need to go transaction /sapapo/mv8v .
Now,the given program has three options :-
1)Create : To create the selection-ID by taking areabasepackRS as name of the selection-ID . Here we need to give the excel sheet that is used to load data into /sapapo/mc8v to calculate PF.
2)Calculate PF : This option is used to calculate proportional factor.
Now if we try to calculate PF ,I get an error message saying there are no
plannable characteristic combinations .
3) Delete : This option is used to delete the selection profile.
I am getting an error in this program which I have explained with the document attached in this mail .
Please could anyone help me out with this .
The program is as below:-
<b>report ZRSNORMS_PPF
no standard page heading line-size 255.</b>
*include bdcrecx1.
INCLUDE ZAPO_DATA_DECLARATION_PPF.
INCLUDE Z_APO_FORMS_PPF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
program_name = syst-repid
DYNPRO_NUMBER = SYST-DYNNR
field_name = p_file1
STATIC = ' '
MASK = ' '
CHANGING
file_name = p_file1
EXCEPTIONS
MASK_TOO_LONG = 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.
start-of-selection.
PERFORM READ_DATA TABLES I_PROFILE
I_EXEL
IT_PROFILE_NAME
USING P_FILE1
CHANGING W_SUBRC.
PERFORM SAVE_SELECTION TABLES I_EXEL
IT_SAVE_SEL
IT_PROFILE_NAME.
IT_GRP-OBJNAM = 'ZRSBASPCK'.
APPEND IT_GRP.
LOOP AT IT_GRP INTO W_GROUP.
APPEND W_GROUP TO IT_GROUP.
ENDLOOP.
G_PAREAID = 'ZRSPAHPC'.
G_MVIEW = 'ZRSPAHPC'.
G_COUNT = 0.
IF CREATE = 'X'.
LOOP AT IT_SAVE_SEL INTO W_SEL_SAVE.
IF W_SEL_SAVE-IOBJNM = '9AVERSION' AND SY-TABIX > 1.
G_COUNT = G_COUNT + 1.
READ TABLE IT_PROFILE_NAME INDEX G_COUNT.
G_NAME = IT_PROFILE_NAME-F_NAME.
CALL FUNCTION '/SAPAPO/MCPSH_SELECTION_SAVE'
EXPORTING
IV_SELID =
IV_FLG_USED_FOR =
IV_PAREAID = G_PAREAID
IV_MVIEW = G_MVIEW
IV_SEL_DESCRIPTION = G_NAME
IT_SELECTION = IT_SEL_SAVE
IT_OBJECTS =
IT_SEL_GROUP = IT_GROUP
IV_POPUP_SEL_DESCRIPTION =
IMPORTING
EV_SELID =
EV_SEL_DESCRIPTION =
EXCEPTIONS
DUPLICATE_SELECTION = 1
MULTIPLE_SELECTION = 2
INCONSISTENT_DATABASE = 3
DUPLICATE_DESCRIPTION = 4
INVALID_DESCRIPTION = 5
NO_PERMISSION = 6
SELID_INVALID = 7
OTHERS = 8
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CLEAR IT_SEL_SAVE[].
APPEND W_SEL_SAVE TO IT_SEL_SAVE.
ELSEIF W_SEL_SAVE-IOBJNM = '9AVERSION' AND SY-TABIX = 1.
APPEND W_SEL_SAVE TO IT_SEL_SAVE.
ELSE.
APPEND W_SEL_SAVE TO IT_SEL_SAVE.
ENDIF.
ENDLOOP.
G_COUNT = G_COUNT + 1.
READ TABLE IT_PROFILE_NAME INDEX G_COUNT.
G_NAME = IT_PROFILE_NAME-F_NAME.
CALL FUNCTION '/SAPAPO/MCPSH_SELECTION_SAVE'
EXPORTING
IV_SELID =
IV_FLG_USED_FOR =
IV_PAREAID = G_PAREAID
IV_MVIEW = G_MVIEW
IV_SEL_DESCRIPTION = G_NAME
IT_SELECTION = IT_SEL_SAVE
IT_OBJECTS =
IT_SEL_GROUP = IT_GROUP
IV_POPUP_SEL_DESCRIPTION =
IMPORTING
EV_SELID =
EV_SEL_DESCRIPTION =
EXCEPTIONS
DUPLICATE_SELECTION = 1
MULTIPLE_SELECTION = 2
INCONSISTENT_DATABASE = 3
DUPLICATE_DESCRIPTION = 4
INVALID_DESCRIPTION = 5
NO_PERMISSION = 6
SELID_INVALID = 7
OTHERS = 8
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IV_GROUP = 'ZRSBASPCK'.
LOOP AT IT_SEL_SAVE INTO w_confirm_sel.
APPEND w_confirm_sel TO it_confirm_sel.
ENDLOOP.
CALL FUNCTION '/SAPAPO/MSDP_SH_OBJ_LIST_BUILD'
EXPORTING
IV_PAREAID = G_PAREAID
IV_MVIEW = G_MVIEW
IV_DVIEW =
IV_FROMDATE =
IV_ENDDATE =
IV_NO_POPUPS =
IMPORTING
ET_SH_OBJECTS =
EXCEPTIONS
INVALID_INPUT = 1
INTERNAL_ERROR = 2
OTHERS = 3
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CLEAR IT_SEL_SAVE[].
ENDIF.
if calc_ppf = 'X'.
PERFORM CALC_PPF TABLES I_EXEL
BDCTAB
IT_PROFILE_NAME.
ENDIF.
if del_prof = 'X'.
LOOP AT I_EXEL.
concatenate i_exel-area I_EXEL-BASE INTO DEL_NAME.
SELECT SINGLE * FROM /SAPAPO/TS_SELKO INTO IT_TS_SELKO
WHERE SEL_DESRCIPTION = DEL_NAME.
DEL_PROFILE = IT_TS_SELKO-SELECTIONID.
CALL FUNCTION '/SAPAPO/MCPSH_SELECTION_DELETE'
EXPORTING
IV_SELID = DEL_PROFILE
IV_FLG_CONFIRM_TRANS = 'X'
EXCEPTIONS
NO_ENTRY = 1
NO_AUTHORITY = 2
DELETION_NOT_POSSIBLE = 3
OTHERS = 4
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDLOOP.
ENDIF.
<b>INCLUDE ZAPO_DATA_DECLARATION_PPF .</b>
types: t_ts_selpo type /sapapo/ts_selpo.
TYPES: BEGIN OF T_EXEL,
PROF_DATFRM TYPE DATS,
PROF_DATTO TYPE DATS,
FORCAST_FROM TYPE DATS,
FORCAST_TO TYPE DATS,
AREA(60),
BASE(60),
POPID(60),
RATING(60),
RS(60),
END OF T_EXEL.
types: begin of t_profile,
obj(30),
val(60),
end of t_profile.
TYPES: begin of t_profile_name,
f_name(60),
end of t_profile_name.
DATA: G_COUNT TYPE I VALUE 0.
*TYPES: T_SAVE_SEL LIKE IT_SELECTION.
data: w_subrc TYPE sy-subrc,
I_TS_SELPO TYPE Table of t_ts_selpo with header line,
I_EXEL TYPE Table of t_EXEL with header line.
DATA: IV_GROUP TYPE /SAPAPO/IOBJNM.
DATA: IT_PROFILE_NAME TYPE TABLE OF T_PROFILE_NAME WITH HEADER LINE.
data: i_profile type table of t_profile with header line.
*/sapapo/ts_iobj_selection_tab.
data: IT_SEL_SAVE TYPE /sapapo/ts_iobj_selection_tab,
w_SEL_SAVE type /SAPAPO/TS_IOBJ_SELECTION.
DATA: IT_CONFIRM_SEL TYPE /SAPAPO/SH_SEL_RANGE_TAB,
W_CONFIRM_SEL TYPE /SAPAPO/SH_SEL_RANGE_STR.
TYPES: BEGIN OF T_SAVE_SEL,
IOBJNM(30),
SIGN,
OPTION(2),
LOW(60),
HIGH(60),
END OF T_SAVE_SEL.
DATA: IT_SAVE_SEL TYPE TABLE OF T_SAVE_SEL WITH HEADER LINE.
TYPES: BEGIN OF T_GRP,
OBJNAM(30),
END OF T_GRP.
DATA: IT_GRP TYPE TABLE OF T_GRP WITH HEADER LINE.
DATA DECLARATION FOR FUNC MODULE **************
DATA: IT_GROUP TYPE /SAPAPO/TS_GROUP_BY_TAB,
W_GROUP TYPE /SAPAPO/TS_GROUP_BY_STR.
DATA: G_PAREAID TYPE /SAPAPO/TS_PAREAID,
G_MVIEW TYPE /SAPAPO/PB_MVIEW,
G_NAME TYPE /SAPAPO/TS_SEL_DESCR.
BDC TABLES ***************************
DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA: it_messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
DATA : BDCTAB like BDCDATA occurs 0 with header line.
DATA : w_file type string.
****************BDC ERROR TAB ***************************
DATA : xcount1 TYPE i,
xstat TYPE i,
xmsgv1 LIKE balm-msgv1,
xmsgv2 LIKE balm-msgv2,
xmsgv3 LIKE balm-msgv3,
xmsgv4 LIKE balm-msgv4,
xmessage(80) TYPE c.
DATA : BEGIN OF t_errlog OCCURS 0,
sno TYPE i,
message(80) TYPE c,
END OF t_errlog.
DATA: DEL_PROFILE TYPE /SAPAPO/SELECTIONID2,
DEL_NAME(60).
************DUPLICATE NAME TAB **************************
DATA: IT_NOT_PROCESSED TYPE TABLE OF /SAPAPO/TS_SELPO WITH HEADER LINE.
DELETE TAB *****************************
DATA: IT_TS_SELKO TYPE TABLE OF /SAPAPO/TS_SELKO WITH HEADER LINE.
SELECTION-SCREEN : BEGIN OF BLOCK b1.
parameters: p_file1 TYPE rlgrap-filename.
parameters: create type c radiobutton group g1,
calc_ppf type c radiobutton group g1,
del_prof type c radiobutton group g1.
SELECTION-SCREEN END OF BLOCK b1.
Include Z_APO_FORMS_PPF
*& Include Z_APO_FORMS_PPF
*& Form READ_DATA
text
-->P_I_PROFILE text
-->P_I_EXEL text
-->P_IT_PROFILE_NAME text
-->P_P_FILE1 text
<--P_W_SUBRC text
FORM READ_DATA TABLES P_I_PROFILE STRUCTURE I_PROFILE
P_I_EXEL STRUCTURE I_EXEL
P_IT_PROFILE_NAME STRUCTURE IT_PROFILE_NAME
USING P_P_FILE1
CHANGING P_W_SUBRC.
DATA : iexcel LIKE zexcel_read OCCURS 0 WITH HEADER LINE,
G_DATE TYPE DATS.
data: l_name(60).
CLEAR p_w_subrc.
CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_p_file1
i_begin_col = 1
i_begin_row = 1
i_end_col = 62
i_end_row = 50000
TABLES
intern = iexcel.
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
p_w_subrc = 0 .
endif.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT iexcel WHERE row > 1.
IF iexcel-col = '0001'.
PERFORM CONVERT_DATE CHANGING G_DATE iexcel-value.
p_i_EXEL-PROF_DATFRM = G_DATE.
ENDIF.
IF iexcel-col = '0002'.
PERFORM CONVERT_DATE CHANGING G_DATE iexcel-value.
p_i_EXEL-PROF_DATTO = G_DATE.
ENDIF.
IF iexcel-col = '0003'.
PERFORM CONVERT_DATE CHANGING G_DATE iexcel-value.
p_i_EXEL-FORCAST_FROM = G_DATE.
ENDIF.
IF iexcel-col = '0004'.
PERFORM CONVERT_DATE CHANGING G_DATE iexcel-value.
p_i_EXEL-FORCAST_TO = G_DATE.
ENDIF.
IF iexcel-col = '0005'.
p_i_EXEL-AREA = iexcel-value.
p_i_profile-obj = 'ZRSAREA'.
p_i_profile-VAL = iexcel-value.
append p_i_PROFILE.
clear p_i_PROFILE.
ENDIF.
IF iexcel-col = '0006'.
p_i_EXEL-BASE = iexcel-value.
p_i_profile-obj = 'ZRSBASPCK'.
p_i_profile-VAL = iexcel-value.
append p_i_PROFILE.
clear p_i_PROFILE.
ENDIF.
IF iexcel-col = '0007'.
p_i_EXEL-POPID = iexcel-value.
p_i_profile-obj = 'ZRSPOPULN'.
p_i_profile-VAL = iexcel-value.
append p_i_PROFILE.
clear p_i_PROFILE.
ENDIF.
IF iexcel-col = '0008'.
p_i_EXEL-RATING = iexcel-value.
ENDIF.
IF iexcel-col = '0009'.
p_i_EXEL-RS = iexcel-value.
p_i_profile-obj = 'ZRSCUSTMR'.
p_i_profile-VAL = iexcel-value.
append p_i_PROFILE.
clear p_i_PROFILE.
ENDIF.
at end of row.
append p_i_EXEL.
clear p_i_EXEL.
endat.
endloop.
loop at P_I_EXEL.
concatenate P_I_EXEL-AREA P_I_EXEL-BASE INTO L_NAME.
P_it_profile_name-f_name = l_name.
append P_it_profile_name.
ENDLOOP.
ENDFORM. " READ_DATA
*& Form CONVERT_DATE
text
<--P_G_DATE text
<--P_IEXCEL_VALUE text
FORM CONVERT_DATE CHANGING P_G_DATE
P_IEXCEL_VALUE.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
DATE_EXTERNAL = p_iexcel_value
ACCEPT_INITIAL_DATE =
IMPORTING
DATE_INTERNAL = p_g_date
EXCEPTIONS
DATE_EXTERNAL_IS_INVALID = 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.
ENDFORM. " CONVERT_DATE
*& Form SAVE_SELECTION
text
-->P_I_EXEL text
-->P_IT_SAVE_SEL text
-->P_IT_PROFILE_NAME text
FORM SAVE_SELECTION TABLES P_I_EXEL STRUCTURE I_EXEL
P_IT_SAVE_SEL STRUCTURE IT_SAVE_SEL
P_IT_PROFILE_NAME STRUCTURE IT_PROFILE_NAME.
DATA: L_PAREAID(40).
loop at p_i_exel.
p_it_save_sel-iobjnm = '9AVERSION'.
p_it_save_sel-SIGN = 'I'.
p_it_save_sel-OPTION = 'EQ'.
p_it_save_sel-LOW = '000'.
APPEND P_IT_SAVE_SEL.
CLEAR P_IT_SAVE_SEL.
p_it_save_sel-iobjnm = 'ZRSAREA'.
p_it_save_sel-SIGN = 'I'.
p_it_save_sel-OPTION = 'EQ'.
p_it_save_sel-LOW = P_I_EXEL-AREA.
APPEND P_IT_SAVE_SEL.
CLEAR P_IT_SAVE_SEL.
IF NOT P_I_EXEL-BASE IS INITIAL.
p_it_save_sel-iobjnm = 'ZRSBASPCK'.
p_it_save_sel-SIGN = 'I'.
p_it_save_sel-OPTION = 'EQ'.
p_it_save_sel-LOW = P_I_EXEL-BASE.
ENDIF.
APPEND P_IT_SAVE_SEL.
CLEAR P_IT_SAVE_SEL.
IF NOT P_I_EXEL-POPID IS INITIAL.
p_it_save_sel-iobjnm = 'ZRSPOPULN'.
p_it_save_sel-SIGN = 'I'.
p_it_save_sel-OPTION = 'EQ'.
p_it_save_sel-LOW = P_I_EXEL-POPID.
APPEND P_IT_SAVE_SEL.
CLEAR P_IT_SAVE_SEL.
ENDIF.
IF NOT P_I_EXEL-RS IS INITIAL.
p_it_save_sel-iobjnm = 'ZRSCUSTMR'.
p_it_save_sel-SIGN = 'I'.
p_it_save_sel-OPTION = 'EQ'.
p_it_save_sel-LOW = P_I_EXEL-RS.
APPEND P_IT_SAVE_SEL.
CLEAR P_IT_SAVE_SEL.
ENDIF.
write 'hi'.
*CLEAR P_IT_SAVE_SEL[].
ENDLOOP.
*submit
ENDFORM. " SAVE_SELECTION
*& Form CALC_PPF
text
-->P_I_EXEL text
-->P_BDCTAB text
-->P_IT_PROFILE_NAME text
FORM CALC_PPF TABLES P_I_EXEL STRUCTURE I_EXEL
P_BDCTAB STRUCTURE BDCTAB
P_IT_PROFILE_NAME STRUCTURE IT_PROFILE_NAME.
DATA: PERIOD_FROM TYPE /SAPAPO/BASIS_VON_BIS,
PERIOD_TO TYPE /SAPAPO/BASIS_VON_BIS,
TRANSFER_FORM TYPE /SAPAPO/TARGET_VON_BIS,
TRANSFER_TO TYPE /SAPAPO/TARGET_VON_BIS,
SEL_PROFILE TYPE /SAPAPO/SEL_TXT.
DATA: SEL_NAME(60).
DATA : L_TEMP TYPE SY-DATUM,
L_TEMP1 TYPE SY-DATUM,
L_TEMP2 TYPE SY-DATUM,
L_TEMP3 TYPE SY-DATUM.
LOOP AT P_I_EXEL.
L_TEMP0(2) = P_I_EXEL-FORCAST_FROM6(2). "passed date
L_TEMP2(2) = P_I_EXEL-FORCAST_FROM4(2). "passed Month
L_TEMP4(4) = P_I_EXEL-FORCAST_FROM0(4). "passed year
L_TEMP10(2) = P_I_EXEL-FORCAST_TO6(2). "passed date
L_TEMP12(2) = P_I_EXEL-FORCAST_TO4(2). "passed Month
L_TEMP14(4) = P_I_EXEL-FORCAST_TO0(4). "passed year
L_TEMP20(2) = P_I_EXEL-PROF_DATFRM6(2). "passed date
L_TEMP22(2) = P_I_EXEL-PROF_DATFRM4(2). "passed Month
L_TEMP24(4) = P_I_EXEL-PROF_DATFRM0(4). "passed year
L_TEMP30(2) = P_I_EXEL-PROF_DATTO6(2). "passed date
L_TEMP32(2) = P_I_EXEL-PROF_DATTO4(2). "passed Month
L_TEMP34(4) = P_I_EXEL-PROF_DATTO0(4). "passed year
PERIOD_FROM = L_TEMP2.
PERIOD_TO = L_TEMP3.
transfer_form = L_TEMP.
TRANSFER_TO = L_TEMP1.
concatenate P_I_EXEL-AREA P_I_EXEL-BASE INTO SEL_NAME.
SEL_PROFILE = SEL_NAME.
perform bdc_dynpro using '/SAPAPO/RMDP_SHARE_VERSION_M' '1000'.
perform bdc_field using 'BDC_CURSOR'
'BPAREAID'.
perform bdc_field using 'BDC_OKCODE'
'=ONLI'.
perform bdc_field using 'PAREAID'
'ZRSPAHPC'.
perform bdc_field using 'FLG_AREA'
'X'.
perform bdc_field using 'BPAREAID'
'ZRSPAHPC'.
perform bdc_dynpro using '/SAPAPO/RMDP_SHARE_MANAGER' '1000'.
perform bdc_field using 'BDC_OKCODE'
'=UCOMM1'.
perform bdc_field using 'BDC_CURSOR'
'Z_DATE-HIGH'.
perform bdc_field using 'B_VER'
'000'.
perform bdc_field using 'B_KENN'
'9AVCORHIST'.
perform bdc_field using 'B_DATE-LOW'
PERIOD_FROM.
perform bdc_field using 'B_DATE-HIGH'
PERIOD_TO.
perform bdc_field using 'VERSION'
'000'.
perform bdc_field using 'Z_DATE-LOW'
transfer_form.
perform bdc_field using 'Z_DATE-HIGH'
TRANSFER_TO.
perform bdc_field using 'FLG_ONE'
'X'.
perform bdc_dynpro using '/SAPAPO/RMDP_SHARE_MANAGER' '1000'.
perform bdc_field using 'BDC_OKCODE'
'=ONLI'.
perform bdc_field using 'BDC_CURSOR'
'SEL_TXT'.
perform bdc_field using 'SEL_TXT'
SEL_PROFILE.
perform bdc_dynpro using '/SAPAPO/RMDP_SHARE_MANAGER' '1000'.
perform bdc_field using 'BDC_OKCODE'
'/EE'.
perform bdc_dynpro using '/SAPAPO/RMDP_SHARE_VERSION_M' '1000'.
perform bdc_field using 'BDC_OKCODE'
'=ONLI'.
perform bdc_field using 'BDC_OKCODE'
'/EE'.
perform bdc_field using 'BDC_CURSOR'
'PAREAID'.
*perform bdc_transaction using '/SAPAPO/MC8V'.
SELECT SINGLE * FROM /SAPAPO/TS_SELKO INTO IT_TS_SELKO
WHERE SEL_DESRCIPTION = sel_NAME.
if sy-subrc = 0.
call transaction '/SAPAPO/MC8V'
using bdctab
mode 'A'
update 'L'
messages into it_messtab.
describe table it_messtab lines xcount1.
read table it_messtab index xcount1.
LOOP AT it_messtab WHERE msgtyp = 'E'
OR msgtyp = 'A'.
MOVE It_messtab-msgv1 TO xmsgv1.
MOVE It_messtab-msgv2 TO xmsgv2.
MOVE It_messtab-msgv3 TO xmsgv3.
MOVE It_messtab-msgv4 TO xmsgv4.
CALL FUNCTION 'MESSAGE_PREPARE'
EXPORTING
LANGUAGE = sy-langu
msg_id = It_messtab-msgid
msg_no = It_messtab-msgnr
MSG_VAR1 = xmsgv1
MSG_VAR2 = xmsgv2
MSG_VAR3 = xmsgv3
MSG_VAR4 = xmsgv4
IMPORTING
MSG_TEXT = xmessage
EXCEPTIONS
FUNCTION_NOT_COMPLETED = 1
MESSAGE_NOT_FOUND = 2
OTHERS = 3
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
MOVE sy-tabix TO t_errlog-sno.
MOVE xmessage TO t_errlog-message.
APPEND t_errlog.
CLEAR t_errlog..
ENDLOOP.
CLEAR BDCTAB[].
CLEAR SEL_NAME.
CLEAR P_I_EXEL.
endif.
ENDLOOP.
ENDFORM. " CALC_PPF
*& Form bdc_dynpro
text
-->P_0424 text
-->P_0425 text
FORM bdc_dynpro USING PROGRAM DYNPRO.
CLEAR bdcTAB.
bdcTAB-program = program.
bdcTAB-dynpro = dynpro.
bdcTAB-dynbegin = 'X'.
APPEND bdcTAB.
ENDFORM. " bdc_dynpro
*& Form bdc_field
text
-->P_0494 text
-->P_TRANSFER_FROM text
FORM bdc_field USING FNAM FVAL.
CLEAR bdcTAB.
bdcTAB-fnam = fnam.
bdcTAB-fval = fval.
APPEND bdcTAB.
ENDFORM. " bdc_fieldHi,
As I have not been able to attach the document, I will explain the problem in full as below:-
Business scenario - Consider a factory having 5 different customers (which is known as Customer_rs). We need to supply stock to each of them based on their past consumption. So to forecast this, we calculate a factor known as proportional factor based on the data we have for previous months.
So to calculate the PF for a period, we need to create a profile in /sapapo/sdp94 .
After creating the profile, the profile can be seen by clicking on SPD94 and going to selection-screen button .
Then to calculate PF , we need to go to transaction /sapapo/mv8v .
Here we will have to give the selection id that was saved in SDP94.
All this process has to be automated and a program has been created to do this.
A description of how the program works is as given below.
When we try to calculate the proportional factor with this program , the following error is obtained :-
There are no plannable characteristic combinations.
We are passing the same parameters that were passed by the SDP94 transaction to the standard function module for saving the selection ids. This is shown in the below screenshots.
In spite of this we are getting the error.
Now to delete the selection ids,click on delete option in the program .
But the problem is even if we click on delete , the PPF data will be stored in the database inspite of deleting the selection profiles .
Please can anyone help me out with this .
Regards,
Sushanth H.S.
Now we will have to give the selection description
Now the profile can be seen by going to SDP94 and clicking on selection profile button.
Now to calculate PF, go to transaction /sapapo/mv8v
Click on execute and give following inputs
This will forecast the PF for the period 01.09.2007 to 21.02.2007 based on data from 21.04.2007 to 20.05.2007
Click on other settings
Here we will have to give the selection id that was saved in SDP94.
Click on execute.
All this process has to be automated and a program was created to do this.
A description of how the program is given below.
Program zrsnorms_ppf
Execute.
Give file path of excel sheet.
Execute.
This will create the selection id by taking areabasepackRS as name of id.
This is the excel sheet that is used to load data into /sapapo/mc8v to calculate the PF.
Upon executing, the ids have been created
The new selection ids can be seen by going to /sapapo/sdp94
And clicking on selection profile.
Parameters passed to standard function module in order to save the selection id.
Now if we try to calculate PF using the program, the following happens
When executed,
BDC is called to input data to transaction /sapapo/mc8v to calculate ppf.
An error screen is generated with the message There are no plannable characteristic combinations.
We are passing the same parameters that were passed by the SDP94 transaction to the standard function module for saving the selection ids. This is shown in the below screenshots.
In spite of this we are getting the error.
When IV_POPUP_SEL_DESCRIPTION is passed, a popup will be displayed where the selection description will have to be entered. I am passing the same selection description here as is picked by the program.( H3HPCDEL00110096, H3HPCDEL00110063)
To avoid this, we need to go to SDP94 and after going to selection window, we need to save the selections as shown in the following screenshots.
Select the selection id one by one.
Click on save selection
Click on save.
Do the same for all ids created by the program.
Now if we try to calculate the PF using the program, it is seen to work
So what needs to be done is that we need to avoid going to SDP94 in order to save the selections after the ids are created by the program.
How the Program works
Se38
Program zrsnorms_ppf
Execute.
Give file path of excel sheet.
Execute.
This will create the selection id by taking areabasepackRS as name of id.
The new selection ids can be seen by going to /sapapo/sdp94
And clicking on selection profile.
Now the selection has to be saved. For that, follow the following procedure.
Click on selection window.
Click on load selection.
Select the ids.
Select and then press save.
Do the same for every id.
Only then can proportional factor be calculated.
Now go to program and select Calc_ppf, with filepath to excel sheet as the sel_ids will be pulled from the excel.
When executed,
BDC is called to input data to transaction /sapapo/mc8v to calculate ppf.
Now go to sdp94 and load the selection
Click on load data.
And make sure, data view is TDP_VIEW_PROP as shown
PPF will be shown for the period chosen in the excel sheet.
Now to delete the selection ids.
Go to the program and give file path of the excel sheet and execute.
The selection profiles will be deleted as shown.
But PPF data will be stored in the database inspite of deleting the selection profiles. And ppf can be shown by selecting the basepack and the sales area.
Click load data.
Business scenario - Consider a factory having 5 different customers (which is known as Customer_rs). We need to supply stock to each of them based on their past consumption. So to forecast this, we calculate a factor known as proportional factor based on the data we have for previous months.
So to calculate the PF for a period, we need to create a profile in /sapapo/sdp94
How it is done in standard transaction /SAPAPO/SDP94
Important pushbuttons and their functions
Click on selection window.
Give the selections
Click on save selection
A break-point has been set in the standard program to show what all parameters are being passed to the standard function module /SAPAPO/MCPSH_SELECTION_SAVE used to save the selection
Now we will have to give the selection description
Now the profile can be seen by going to SDP94 and clicking on selection profile button.
Now to calculate PF, go to transaction /sapapo/mv8v
Click on execute and give following inputs
This will forecast the PF for the period 01.09.2007 to 21.02.2007 based on data from 21.04.2007 to 20.05.2007
Click on other settings
Here we will have to give the selection id that was saved in SDP94.
Click on execute.
All this process has to be automated and a program was created to do this.
A description of how the program is given below.
Program zrsnorms_ppf
Execute.
Give file path of excel sheet.
Execute.
This will create the selection id by taking areabasepackRS as name of id.
This is the excel sheet that is used to load data into /sapapo/mc8v to calculate the PF.
Upon executing, the ids have been created
The new selection ids can be seen by going to /sapapo/sdp94
And clicking on selection profile.
Parameters passed to standard function module in order to save the selection id.
Now if we try to calculate PF using the program, the following happens
When executed,
BDC is called to input data to transaction /sapapo/mc8v to calculate ppf.
An error screen is generated with the message There are no plannable characteristic combinations.
We are passing the same parameters that were passed by the SDP94 transaction to the standard function module for saving the selection ids. This is shown in the below screenshots.
In spite of this we are getting the error.
When IV_POPUP_SEL_DESCRIPTION is passed, a popup will be displayed where the selection description will have to be entered. I am passing the same selection description here as is picked by the program.( H3HPCDEL00110096, H3HPCDEL00110063)
To avoid this, we need to go to SDP94 and after going to selection window, we need to save the selections as shown in the following screenshots.
Select the selection id one by one.
Click on save selection
Click on save.
Do the same for all ids created by the program.
Now if we try to calculate the PF using the program, it is seen to work
So what needs to be done is that we need to avoid going to SDP94 in order to save the selections after the ids are created by the program.
How the Program works
Se38
Program zrsnorms_ppf
Execute.
Give file path of excel sheet.
Execute.
This will create the selection id by taking areabasepackRS as name of id.
The new selection ids can be seen by going to /sapapo/sdp94
And clicking on selection profile.
Now the selection has to be saved. For that, follow the following procedure.
Click on selection window.
Click on load selection.
Select the ids.
Select and then press save.
Do the same for every id.
Only then can proportional factor be calculated.
Now go to program and select Calc_ppf, with filepath to excel sheet as the sel_ids will be pulled from the excel.
When executed,
BDC is called to input data to transaction /sapapo/mc8v to calculate ppf.
Now go to sdp94 and load the selection
Click on load data.
And make sure, data view is TDP_VIEW_PROP as shown
PPF will be shown for the period chosen in the excel sheet.
Now to delete the selection ids.
Go to the program and give file path of the excel sheet and execute.
The selection profiles will be deleted as shown.
But PPF data will be stored in the database inspite of deleting the selection profiles. And ppf can be shown by selecting the basepack and the sales area.
Click load data. -
Some help needed for shopping calculator program
Hi. I would like to thank you in advance for helping me. At the moment I am pretty much stuck. I don't know how to add the input using 'while loop'. This is what I'm suppose to do:
Write a program called ShoppingCalculator.java that allows the user to enter the prices of several items they have bought and then tells them the total amount. The user can enter the prices for as many items as they want, until they click Cancel. The program should then output the total amount they spent, in a message dialog box. Use pounds for all the amounts.
So far I have written:
import javax.swing.JOptionPane;
public class ShoppingCalculator
public static void main(String[] args)
boolean done = false;
double amount;
String input;
while (!done)
input = JOptionPane.showInputDialog("Enter the amount you spent on the next item:");
amount = Double.parseDouble (input);
if (done = true)
JOptionPane.showMessageDialog (null, "You spent a total amound of £" + amount );
}Sorry if the code doesn't make much sense cause I've been changing the code around so many times that.
At one point when I was playing around with the code, I manage to make the input dialog loop nicely but when I pressed cancel, the message dialog only output the last input I put in. What I'm really stuck here is I need to know how to add the input when using 'while loop' and is it correct to use the IF Statement on this program. Please give me some advice on how to and I will try to work on it again.Ok. I have edit the code and this is what it looks like:
import javax.swing.JOptionPane;
public class ShoppingCalculator
public static void main(String[] args)
boolean done = false;
double amount;
String input;
double total = 0;
while (!done)
input = JOptionPane.showInputDialog("Enter the amount you spent on the next item:");
amount = Double.parseDouble (input);
if (input == null)
total = total + amount;
JOptionPane.showMessageDialog (null, "You spent a total amound of " + total );
}I created another variable (total) and it even compiled. The only problem I have now is the message dialog wouldn't show at the end. When I press cancel and nothing happen. This is what I get on my output command window:
Exception in thread "main" java.lang.NullPointerException
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:991)
at java.lang.Double.parseDouble(Double.java:510)
at ShoppingCalculator.main(ShoppingCalculator.java:23)
Java Result: 1
Anything that isn't right here? -
MacOS 7.5.x & a soap calculator program
Does anyone know of a working soap calculator that will run on my beloved Mac Classic II?
I make homemade soap, and would really like to know if my lye/water mix is safe and if the bars will be hard after setting up.
I know there are online versions, but my Classic II is not connected to the internet... yet
ALSO, if anyone knows how to very easily connect the Classic to the internet, let me know how I can do it. If I can't find a stand alone soap calculator that will run on my Mac, then this could be an option. It does not to be a "fast" internet/computer function, just a working one
TIA-
Apple //GSThis is the very first time I have heard of a soap calculator.
Formally speaking you can probably connect to the Internet if you bought a modem and had a dialup account. It would be horribly slow by modern standards, the browsers for OS7 would be old. It might have problems with many pages, especially since many pages have complex design that would take a long time to download the files and might have commands that an old browser couldn't understand. If your calculator page is the only one you want to visit, and it is simple in design and doesn't need newer resources, then you might be able to use it. However, the place where old machines really show their age is in Internet use. Gosh, for that matter was the WWW even around back in OS7 days? I remember using Gopher, and then testing this very confusing and unpromising looking thing called a web browser 16 years ago...
Edit: I see at [this page|http://www.millersoap.com/worksheet.html] there are Excel calculator templates, but again I have no idea if these would even open or run on a Mac of System 7 generation. -
please help!!
I'm writting a program in which i have a JFrame with numberd buttons in it. What i want to do is desplay then numbers in the north RIGHT corner of the screen. For example when you press "1" it will display a one, then if you press two with out preesing cler it will display "12". i dont need the code jsut an explanation of what to do, like should I use a textfield? and how do i link the buttons up to this
If anyone could give me some advice i would really appreacite it
-SeanUse a text field if you want the field to be editable, otherwise it's just as easy to use a label (and more fool proof)
I'd add one actionListener to all the buttons, and assuming they have their number as the text label on the button, do this:
public void actionPerformed(ActionEvent e)
JButton pushed = (JButton)(e.getSource()); // assumes nothing else will throw this ActionEvent, otherwise ClassCastException
answerLabel.setText(answerLabel.getText()+pushed.getText());
}Hope this helps,
Radish21 -
Hey Apple Programmers,
FYI - The factorial only exists for non-negative integers. However the scientific calculator on the iPod touch and iPhone the factorial function gives values for negative values and for non-integers. Sorry guys this is an error!
Now, it is true that if you integrate the gamma function (which exists for all numbers) you will get the factorial. For example gamma(N) = (N-1)! and in statistics it is useful to now that gamma(1/2) = sqrt(pi) so for HP calculators this comes in handy and -0.5! on an HP calculator will give you sqrt(pi) or gamma(1/2). This is useful if you know what is going on. The routine that APPLE uses does not give the gamma function so it IS totally useless and WRONG!
Sorry guys, got you on this one.
LeRoyApple does not read this forum. If you'd like to let them know use this url.
http://www.apple.com/feedback/ipodtouch.html
lenn -
A calculator programe, I want to use NumberPad to calculate
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
class calculatorPanel extends JPanel implements ActionListener{
private boolean first = true;
private int result =0;
private String op = "=";
private JTextField screen;
public calculatorPanel(){
setLayout(new BorderLayout());
screen = new JTextField(10); //
// screen.setEditable(false);
screen.setHorizontalAlignment(JTextField.RIGHT);
/* screen.addKeyListener(new KeyAdapter(){
public void KeyTyped(KeyEvent e){
String s = "";
char c = e.getKeyChar();
if(c >= '0' && c <= '9'){
if(first){
screen.setText(s+c);
else
screen.setText(screen.getText()+c);
first = false;
else{
if(first){
if(c == '-'){
screen.setText(s+c);
first = false;
else{
op = s;
else{
String t = screen.getText();
int x = Integer.parseInt(t.substring(0,t.length()-1));
calculate(x);
op = s+c;
first = true;
if(c == 'c'){
screen.setText("0");
result = 0;
first = true;
op = "=";
add(screen,"North");
JPanel p = new JPanel(); //??????????????????
p.setLayout(new GridLayout(4,4,5,5)); //
String buttons = "789/456*123-0c=+"; //
for(int i=0;i < buttons.length();i++) //
addButton(p,buttons.substring(i,i+1));
add(p,"Center");
private void addButton(Container c,String s){
JButton b = new JButton(s);
c.add(b);
b.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
b.addActionListener(this);
// b.addKeyListener(new KeyAdapter());
public void actionPerformed(ActionEvent e){
String s = e.getActionCommand();
if(s.charAt(0) >= '0' && s.charAt(0) <= '9'){
if(first) screen.setText(s);
else
screen.setText(screen.getText()+s);
first = false;
else{
if(first){
if(s.equals("-")){
screen.setText(s);
first = false;
else op = s;
else{
int x = Integer.parseInt(screen.getText());
calculate(x);
op = s;
first = true;
if(s.equals("c")){
screen.setText("0");
result = 0;
first = true;
op = "=";
public void calculate(int n){
if(op.equals("+")) result += n;
else if (op.equals("-")) result -= n;
else if (op.equals("*")) result *= n;
else if (op.equals("/")) result /= n;
else if (op.equals("=")) result = n;
screen.setText(""+result);
class calculatorFrame extends JFrame{
public calculatorFrame(){
setTitle("Calculator");
setSize(200,200);
Container contentPane = getContentPane();
contentPane.add(new calculatorPanel());
addWindowListener(new WindowAdapter(){//
public void windowClosing(WindowEvent e){
System.exit(0);
public class calculator{
public static void main(String args[]){
JFrame frame = new calculatorFrame();
frame.show();
// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// frame.setVisible(true);
// frame.pack();
}So what is your problem?
One obvious thing is that in your commented out code you have a method
public void KeyTyped(KeyEvent e){
but if you are expecting this to be invoked when a key is pressed then you will be disappointed. The method name should probably be 'keyPressed' or maybe 'keyReleased'. -
How to monitor progress of web-service calculation? And abort it?
Hello. We're thinking of converting an existing Java radar calculation program into a web-service, so that it can be used by various interested parties. However, calculations can take some time (several minutes) and so we would like the client to be able to both show calculation progress and allow the user to abort the calculation if necessary. It is not obvious to us how to do this with a web-service. Are there any standard approaches to this problem? What's the best way of a client asking the web-service how a calculation is progressing? What's the best way for a client to abort a calculation? Any advice most welcomed.
Kind regards
Paul Howland
NATO C3 Agency
The HagueYou can't estimate the duration withour running the gather_database_stats. You can monitor it while it is running. (e.g. count the tables that have got updated statistics based on DBA_TABLES)
And if you run gather_database_stats, the default behaviour might well be to exclude tables which aren't "stale" while in the imported database the expectation is to gather stats on all tables.
(Similarly, the behaviour to gather column histograms (method_opt) may differ in an existing database from a newly imported database)
Hemant K Chitale
Edited by: Hemant K Chitale on May 14, 2013 10:13 AM -
Error when running mortgage calc program from DOS prompt
I have a GUI Mortgage Calculator program. It probably isn't the most efficient use of code, but it gets the job done. I am running java SDK 1.6.0_06. This is a class assignment. We are to compile the code and post the .class file for our team members to run. I am trying to get the .class file to run after I compile it with javac. I used jCreator LE to create it... it compiles and runs there just fine. The program will compile at the DOS prompt, but will not run properly. The following is the error I get (any help would be appreciated):
Exception in thread "mani" java.lang.NoClassDefFoundError: manchorMortgage3
Caused by: java.lang.ClassNotFoundException: manchorMortgage3
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader1.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Below is my code:
* manchorMortgage3.java
* Created on July 10, 2008
* This program calculates and displays the mortgage amount
* from user input of the amount of the mortgage and the user's
* selection from a menu of available mortgage loans.
import java.math.*; //*loan calculator
import java.text.*; //*formats numbers
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class manchorMortgage3 extends javax.swing.JFrame {
/** Creates new form manchorMortgage3 */
public manchorMortgage3() {
initComponents();
setLocation(300,200);
/** This method is called from within the constructor to
* initialize the form.
// Begin Initialize Components
private void initComponents() {
mortgageAmount = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
termAndInterest = new javax.swing.JLabel();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jRadioButton3 = new javax.swing.JRadioButton();
calcButton = new javax.swing.JButton();
enterAmount = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Manchor - Mortgage Calculator - Week 3");
mortgageAmount.setText("Enter the Mortgage Amount:");
termAndInterest.setText("Select Your Term and Interest Rate:");
jRadioButton1.setText("7 years at 5.35%");
jRadioButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
jRadioButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton1ActionPerformed(evt);
jRadioButton2.setText("15 years at 5.5%");
jRadioButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
jRadioButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton2ActionPerformed(evt);
jRadioButton3.setText("30 years at 5.75%");
jRadioButton3.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
jRadioButton3.setMargin(new java.awt.Insets(0, 0, 0, 0));
jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButton3ActionPerformed(evt);
calcButton.setText("Calculate");
calcButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
calcButtonActionPerformed(evt);
jTextArea1.setColumns(20);
jTextArea1.setEditable(false);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jButton2.setText("Quit");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(enterAmount)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 222, Short.MAX_VALUE)
.addComponent(calcButton)
.addGap(75, 75, 75))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton3)
.addComponent(jRadioButton2)
.addComponent(jRadioButton1)
.addComponent(termAndInterest)
.addComponent(mortgageAmount)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(224, Short.MAX_VALUE)))))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(277, Short.MAX_VALUE)
.addComponent(jButton2)
.addGap(70, 70, 70))
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(31, 31, 31)
.addComponent(mortgageAmount)
.addGap(14, 14, 14)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(20, 20, 20)
.addComponent(termAndInterest)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jRadioButton1)
.addGap(15, 15, 15)
.addComponent(jRadioButton2)
.addGap(19, 19, 19)
.addComponent(jRadioButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(calcButton)
.addComponent(enterAmount))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(jButton2)
.addGap(20, 20, 20))
pack();
}// End initialize components
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//event_jButton2ActionPerformed
System.exit(1);
}//event_jButton2ActionPerformed
static NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
static NumberFormat np = NumberFormat.getPercentInstance();
static NumberFormat ni = NumberFormat.getIntegerInstance();
static BufferedReader br;
private void calcButtonActionPerformed(java.awt.event.ActionEvent evt) {//event_calcButtonActionPerformed
enterAmount.setText(null);
jTextArea1.setText(null);
double monthlyPayment;
double interest;
double amount ;
int years ;
double monthlyInterest, monthlyPrinciple, principleBalance;
int paymentsRemaining, lineCount;
np.setMinimumFractionDigits(2);
br = new BufferedReader(new InputStreamReader(System.in));
lineCount = 0;
try
amount=Double.parseDouble(jTextField1.getText());
catch (Exception e)
enterAmount.setText("Please Enter Mortgage Amount");
return;
if(jRadioButton1.isSelected())
interest=0.0535;
years=7;
else if(jRadioButton2.isSelected())
interest=0.055;
years=15;
else if(jRadioButton3.isSelected())
interest=0.0575;
years=30;
else
enterAmount.setText("Please Select Your Term and Interest Rate");
return;
jTextArea1.append(" For a mortgage of " + nf.format(amount)+"\n"+" With a Term of " + ni.format(years) + " years"+"\n"+" And an Interest rate of " + np.format(interest)+"\n"+" The Payment Amount is " + nf.format(getMortgagePmt(amount, years, interest)) + " per month."+"\n"+"\n");
principleBalance = amount - ((getMortgagePmt(amount, years, interest)) - (amount*(interest/12)));
paymentsRemaining = 0;
do
monthlyInterest = principleBalance * (interest/12);//*Current monthly interest
monthlyPrinciple = (getMortgagePmt(amount, years, interest)) - monthlyInterest;//*Principal payment each month minus interest
paymentsRemaining = paymentsRemaining + 1;
principleBalance = principleBalance - monthlyPrinciple;//*New balance of loan
jTextArea1.append(" Principal on payment " + ni.format(paymentsRemaining) + " is " + nf.format(monthlyPrinciple)+"\n");
jTextArea1.append(" Interest on payment " + ni.format(paymentsRemaining) + " is " + nf.format(monthlyInterest)+"\n");
jTextArea1.append(" New loan balance on payment " + ni.format(paymentsRemaining) + " is " + nf.format(principleBalance)+"\n"+"\n"+"\n");
while (principleBalance > 1);
}//Begin event_jRadioBtton1Action Performed
public static double getMortgagePmt(double balance, double term, double rate)
double monthlyRate = rate / 12;
double monthlyPayment = (balance * monthlyRate)/(1-Math.pow(1+monthlyRate, - term * 12));
return monthlyPayment;
private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//Begin event_jRadioButton3ActionPerformed
if(jRadioButton2.isSelected())
jRadioButton2.setSelected(false);
if(jRadioButton1.isSelected())
jRadioButton1.setSelected(false);
}//End event_jRadioButton3ActionPerformed
private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//Begin event_jRadioButton2ActionPerformed
if(jRadioButton1.isSelected())
jRadioButton1.setSelected(false);
if(jRadioButton3.isSelected())
jRadioButton3.setSelected(false);
}//End event_jRadioButton2ActionPerformed
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
if(jRadioButton2.isSelected())
jRadioButton2.setSelected(false);
if(jRadioButton3.isSelected())
jRadioButton3.setSelected(false);
}//End event_jRadioButton1ActionPerformed
* @param args the command line arguments
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new manchorMortgage3().setVisible(true);
// Begin variables declaration
private javax.swing.JButton calcButton;
private javax.swing.JButton jButton2;
private javax.swing.JLabel mortgageAmount;
private javax.swing.JLabel termAndInterest;
private javax.swing.JLabel enterAmount;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JRadioButton jRadioButton3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField jTextField1;
// End variables declaration
}The class is not in your classpath. Likely you blew away your classpath with some silly environment variable.
If you are in the directory where your class file is then execute
java -cp . manchorMortgage3and it will work. (Note the -cp . which tells java to include the current directory in the runtime classpath)
Maybe you are looking for
-
The Pages stop working on my computer when I upgraded OS to Mountain Lion. I reinstalled iWork from CD and updated to 9.3 version from Apple store. I also restarted computer before opening the iWork. It still doesn't work. It keeps giving me the erro
-
Can we get Adobe InDesign CS6 and use CS5?
Hi There, We currently have 4 license of InDesign CS5 that comes with Adobe Creative Suite CS5. Also an Adobe Product Premium CS5.5. We now need to get an extra license for InDesign CS5 for the Adobe Product Premium CS5.5 machine. I noticed Adobe now
-
All of my downloaded apps will not open, how do I correct this? The same thing happened a few days ago, but when I received an alert from the sport app, all the games opened up and I could use them. This morning they are all closed again. Everything
-
Only two categories visible in purchased.
Hi everybody, I have two movies, plenty of apps, and one book purchased. I set up a family sharing with my mother's macbook air and she bought a movie (on my credit card). She already watched it, but I don't see it in my library. Just like she don't
-
Retrieve Image from SQL Server and Store in Oracle
Hi All I want to retrieve the image stored in sql server as a image type and store that image to oracle as a BLOB type. I tried to retrive the image from sqlserver using getBytes and when storing to Oracle i have to type cast the byte array to BLOB t