Getting wrong answers for conversion
Hi all,
I've been working on a program for base conversion.
After making some adjustments I am yet to get the "correct" answer for my conversion. For example when i key in 100 i get 10 as my answer.
I am using a label to set the text of my answer but all it does is take the number entered in the textfield i guess. Appreciate all replies.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.io.*;
This is an applet that enables the user to enter the number and the base
system of number entered. Upon clicking the Convert button, the program should
display the number, the positional weightage of each digit of the number, and
the decimal equivalent of the number
public class Testing1 extends Applet implements ActionListener {
//declare all components
Label numbersystemLabel; //Top Label
Label numberLabel; //Middle Label next to the number TextField
Label baseLabel; //Middle Label next to the base TextField
Label answerLabel; //Bottom Label for the answer
static String numberkeyin; //number that is entered in the textfield
static String bintype="binary"; //convert binary base to decimal
static String octtype="octal"; //convert octal base to decimal
static String yrtype="";
static String real= "";
TextField numberField;
TextField baseField;
Button convert;
int Answer;
Panel p1;
Panel p2;
Panel p3;
public void init() {
p1 = new Panel ();
p2 = new Panel ();
p3 = new Panel ();
p1.setLayout(new BorderLayout(25,25));
p2.setLayout(new GridLayout(2,2,2,2));
p3.setLayout(new BorderLayout(25,25));
numbersystemLabel=new Label ("Number System");
p1.add("North",numbersystemLabel);
numberLabel=new Label ("Enter the number : ");
p2.add(numberLabel);
numberField=new TextField(9);
p2.add(numberField);
baseLabel=new Label ("Enter the base system ");
p2.add(baseLabel);
baseField=new TextField(9);
p2.add(baseField);
convert=new Button ("Convert");
convert.addActionListener(this);
answerLabel=new Label ("Decimal Equivalent : ");
p1.add("South",answerLabel);
p3.add("North",p2);
p3.add("South",convert);
p1.add("Center",p3);
add(p3);
add(p1);
public void actionPerformed(ActionEvent event) {
Answer=Integer.parseInt(numberField.getText());
yrtype=baseField.getText();
answerLabel.setText(real);
if (yrtype.equals(bintype)){
real="Decimal Equivalent: " +Answer ;
else {
real="Decimal Equivalent: Daddy's girl ";
repaint();
private void Compute() {
int i;
int countlength;
char bit;
Answer = 0; // initialize the answer to zero.
countlength = numberkeyin.length();
// find the length of the binary number string.
for( i=1; i<=countlength; i++) {
bit = numberkeyin.charAt(countlength-i);
// extract each binary digit, starting from the right.
if( bit == '1' ) {
Answer += Math.pow(2.0,i-1.0);
// The digit was a "1", so add it's decimal equivalent to the answer.
public void paint(Graphics g) {
//power
String a= "2" ; String v= "4";
String b= "2" ; String w= "3";
String c= "2" ; String x= "2";
String d= "2" ; String y= "1";
String e= "2" ; String z= "0";
g.setFont(new Font ("Helvetica",Font.ITALIC+Font.BOLD,20));
g.drawString("" +e +" " +d +" " +c +" " +b +" " +a, 350, 250 );
g.setFont(new Font ("Helvetica",Font.ITALIC+Font.BOLD,12));
g.drawString(" " +v +" " +w +" " +x +" " +y +" " +z, 355, 235 );
I think you need to completely re-think your
actionPerformed method. I don't think there's
anything correct in there.
I'm not going to do you homework for you.
Jeez, what's wrong with the people in here. I am not
asking anyone to do my homework for God's sake. Yeah
sure its a school assignment (what's the big deal
about that?)I just want to know the errors pertaining
to my code and ways on improving/correcting it.
Oh yeah,,, just knowing won't help. I have checked my
action Performed and i don't see anything wrong in
there though.
I am a newbie in java and would like to learn. So my
question is how can i call the compute method?
God save me from paranoids.Hi miss_mushroom...
If you look through these forums, you will find many "do my homework requests"...
so the replies here are understandable...
anyway here is an example code snippet...
public void sayHello(){
System.out.println("Hello);//outputs "Hello"
public int doSomeMath(int num1,int num2){
/* returns an int and takes two ints as arguements\parameters */
return num1 + num2; this is where the int get returned...
public void callMethods(){ // yet another method
sayHello();// calls sayHello which displays "Hello"
int answer = doSomeMath(10,5);//calls do someMath which adds 10 and 5
// and the returned value is assigned to answer...
}many of your question can be answered by reading Sun's Java Tutorial...
http://java.sun.com/docs/books/tutorial/index.html
including your bits.length question...
- MaxxDmg...
- ' He who never sleeps... '
Similar Messages
-
Java Calculator, Minus & multiplication button gets wrong answer?
import java.awt.event.*;
import java.applet.Applet;
import javax.swing.*;
import java.awt.*;
public class calc extends JApplet implements ActionListener
JTextField input = new JTextField("");
JButton numbers[] = new JButton[10];
JButton add = new JButton("+");
JButton equals = new JButton("=");
JButton minus = new JButton("-");
JButton multiply = new JButton("*");
JButton divide = new JButton("/");
JButton clear = new JButton("AC");
int num1 = 0;
int num2 = 0;
String oper = " ";
public void init()
setLayout(null);
setBackground(new Color(227,131,125));
Design();
public void Design()
int x = 1;
int y= 1;
int wi = 10;
int he = 50;
input.setSize(250,30);
input.setLocation(10,10);
add(input);
add.setSize(80,30);
add.setLocation(280,50);
add.addActionListener(this);
add(add);
minus.setSize(80,30);
minus.setLocation(280,90);
minus.addActionListener(this);
add(minus);
multiply.setSize(80,30);
multiply.setLocation(280,130);
multiply.addActionListener(this);
add(multiply);
divide.setSize(80,30);
divide.setLocation(280,175);
divide.addActionListener(this);
add(divide);
equals.setSize(80,30);
equals.setLocation(190,175);
equals.addActionListener(this);
add(equals);
clear.setSize(80,30);
clear.setLocation(100,175);
clear.addActionListener(this);
add(clear);
while(x<=10)
if (x==10)
numbers[x-1] = new JButton("0");
numbers[x-1].setSize(80,30);
numbers[x-1].setLocation(wi,he);
//numbers[x-1].setBackground();
else
numbers[x-1] = new JButton(Integer.toString(x));
numbers[x-1].setSize(80,30);
numbers[x-1].setLocation(wi,he);
wi = wi + 90;
if(x%3==0)
he = he + 40;
wi = 10;
numbers[x-1].addActionListener(this);
add(numbers[x-1]);
x++;
public void actionPerformed(ActionEvent act)
int x = 0;
while(x<10)
if(act.getSource().equals(numbers[x]))
if(x==9)
input.setText("0");
else
input.setText(Integer.toString(x+1));
x++;
if (act.getSource().equals(add))
num1 = Integer.parseInt(input.getText());
else if(act.getSource().equals(equals))
num2 = Integer.parseInt(input.getText());
input.setText(Integer.toString(num1 + num2));
if (act.getSource().equals(minus))
num1 = Integer.parseInt(input.getText());
oper = "minus";
else if(act.getSource().equals(equals))
num2 = Integer.parseInt(input.getText());
if(oper.equals("minus"))
input.setText(Integer.toString(num1 - num2));
if (act.getSource().equals(multiply))
num1 = Integer.parseInt(input.getText());
oper = "multiply";
else if(act.getSource().equals(equals))
num2 = Integer.parseInt(input.getText());
if(oper.equals("multiply"))
input.setText(Integer.toString(num1 * num2));
The addition button is working, but i cant seem to make minus and multiply button work, they get wrong answer when i use them.. what could bee the problem with my codeSorry, but I don't see a simple fix in this code here (Hopefully I'm wrong and someone else will see this, but I don't) Because of this, I recommend that you fully scrap this code and start over from square one. I don't think that you really "see" your logic here. To help you see what you are trying to do, you need to separate your logic from your GUI. Try to build a non-gui calculator that works via simple console menu. Once you get this working, then use this code to create a GUI calculator.
-
How to get an answer for Support Request Number 12...
How to get an answer for Support Request Number 1277702580 ?
Has your speed problem been resolved, or do you need assistance?
There are some useful help pages here, for BT Broadband customers only, on my personal website.
BT Broadband customers - help with broadband, WiFi, networking, e-mail and phones. -
Problem in Getting Count answer for the report in OBIEE 11g..
Hi friends,
I created a report in OBIEE 11g, but i'm not getting the correct answer as i expected...I'm getting answer in presentation services but the answer is wrong..
I'll explain to you with an example report: Suppose in the report "NATIONALITY COUNT IN DEPARTMENT WISE" manner
i dragged the Nationality column from per_all_people_f which is dim table and i dragged the column that i applied aggregation rule "count" for the column "nation count" from per_all_assignments_f which is fact table......If i viewed answers means i'm getting correct answer
(i.e.) nation count per Nationality..........
NATIONALITY<---------------------->NATION COUNT
AUSTRALIA 40
INDIA 20
AFRICA 10
USA 5
The above is the answer I'm getting with out including the department column from hr_all_organization_units...........
But since according to the report i need count in department wise manner, so for that along with nationality and nation count column i dragged department column from hr_all_organization_units which is dim table and also i hide that column as i dont want to view the department column in answers..........
If i clicked answers, means then I'm not getting the nation count for the nationality......... I'm getting the answer 0 for each and every nationality, if i included the hided department column
NATIONALITY<----------------->NATION COUNT
AFRICA 0
AUSTRALIA 0
INDIA 0
USA 0
I'm getting answers like the above if i include the department dimension column which is in hided manner.........................
What is wrong with it........Whether i made any logical mistake for the report.....If so guide me friends..........
Cheers,
Harry...........Hi,
you said about writing query in DB.......whether U meant of trying checking the query in toad..or something else..........
Since im giving only one join from dim to fact in the physical diagram........
But more than one join exist between those dim and fact, but im giving only one join mainly the primary key column of the dimension table to the fact table....Whether i need to give all the joins that exist(even if it has 2 or 3 joins between those fact and dim) tables....
If i give count distinct means it is giving count for every nation as 1....like i mentioned below
NATIONALITY<----------------------------------------------------->NATION COUNT
INDIA---------------------------------------------------------------------1
AUS------------------------------------------------------------------------1
CAN------------------------------------------------------------------------1
Since you said to check about depts of the particular column....i couldn't able to understand about "depts" that you meant????
Whether i made any logical mistake...........
thanks,
Harry...
Edited by: HariPrasad on Oct 10, 2010 9:55 PM -
HT5312 I can't get my answers for the security questions
Hello
Please, how can I get answers for the security questionsGo back to the article you asked this question from and use the link to contact the iTunes Store staff in the 'Additional Information' section. If you don't already have a valid rescue email address, you can't reset the questions yourself, and nobody on these boards can reset them for you.
Setting up a rescue email address requires correctly answering two of the questions.
(92728) -
HT5312 Wrong answer for id security quesion and can not make areset
I were took capture the answer for id securrity question by take a photo The probelm when i filled up my answer into id question the result is one or both incorrect Pls. Help
The reset link, as described on the page that you posted from, only shows if you have a rescue email address on your account. If you don't have one (you won't be able to add one until you can answer 2 of your questions) then you won't get the reset option - you will need to contact iTunes Support / Apple to get the questions reset.
Contacting Apple about account security : http://support.apple.com/kb/HT5699
When they've been reset you can then use the steps half-way down the page that you posted from to add a rescue email address for potential future use -
Hi Somw help to get the answers for these Questions
Q1 Which one of the following is NOT polymorphic behavior?
a. Method overloading -- having methods with the same name but different signatures
b. Implicit type conversion -- for instance, a java.util.List class converts its members to Objects
c. Explicit type conversion -- when a class is converted to another class by a class cast statement
d. Method inheritance -- when a subclass inherits the behavior of the class from which it inherits
e. Using interfaces -- where any class can implement an interface for a given behavior, e.g. Runnable
Q2 The following code defines the Example class.
package com.brainbench.javaexamples;
public class Example {
public static final int VALUE = 10;
// Additional code not shown.
Referring to the sample code above, what classes modify the value of Example.VALUE
a Inner classes of Example only
b Classes in the same package only
c Classes in the same source code unit only
d. Classes in Java standard packages only
e. None of the classes
Q3 What is a classpath?
a. A search path for loading class files from disk
b. It exports Java code remotely
c. It protects the multiple JVMs from interfering with each other
d. It specifies which Java files must be compiled.
e. The security behavior of java.security
Q4 Which one of the following is NOT a configurable JVM option?
a. Collect profiling and debugging statistics.
b. Set the maximum memory allocation pool size.
c. Set the initial memory allocation pool size.
d. Modify the garbage collector's behavior
e. Modify the number of bits a double variable uses.
Q5 a. public void foo() {..}
b. void foo() {..}
c. protected void foo() {..}
d. private void foo() {..}
e public final void foo() {..}
Which of the methods above are overridden via inheritance?
a. a and c
b. a and e
c. a, b and c
d. a, b and d
e. c, d and eQ1 Which one of the following is NOT polymorphic
behavior?
a. Method overloading -- having methods with the same
name but different signatures
b. Implicit type conversion -- for instance, a
java.util.List class converts its members to Objects
c. Explicit type conversion -- when a class is
converted to another class by a class cast statement
d. Method inheritance -- when a subclass inherits the
behavior of the class from which it inherits
e. Using interfaces -- where any class can implement
an interface for a given behavior, e.g. Runnable
_________I would say c) beacause you need to state it clearly to the compiler, so it is not this great automatic polymorphic java behaviour.
>
>
Q2 The following code defines the Example class.
package
com.brainbench.javaexamples;
public class Example {
public static final int VALUE = 10;
// Additional code not shown.
Referring to the sample code above, what
classes modify the value of Example.VALUE
a Inner classes of Example only
b Classes in the same package only
c Classes in the same source code unit only
d. Classes in Java standard packages only
e. None of the classes
___I would say e) beacause this variable is final which means you can't change it once initialized.
>
Q3 What is a classpath?
a. A search path for loading class files from disk
b. It exports Java code remotely
c. It protects the multiple JVMs from interfering
with each other
d. It specifies which Java files must be compiled.
e. The security behavior of java.security
________a). Using classpath class loader load the classes.
>
Q4 Which one of the following is NOT a configurable
JVM option?
a. Collect profiling and debugging statistics.
b. Set the maximum memory allocation pool size.
c. Set the initial memory allocation pool size.
d. Modify the garbage collector's behavior
e. Modify the number of bits a double variable uses.
_______I would say e) because in Java every primitive value (including double) has the same size on every platform. Thats one thing why Java is portable.
>
>
Q5 a. public void foo() {..}
b. void foo() {..}
c. protected void foo() {..}
d. private void foo() {..}
e public final void foo() {..}
Which of the methods above are overridden via
inheritance?
a. a and c
b. a and e
c. a, b and c
d. a, b and d
e. c, d and eI would say b) but I think the order is also important which is not stated in this question ( c) would be also good if methods in reverse order - c -> b -> a ) a) not because you can't reduce the visibility of a method. And two others includes private method, which doesn't take part in inhertiance at all (it is invisible when inheritted so can't be overriden, or you can't reduce visibility to private). -
Getting wrong values for decimal value in Bex report
Hi,
I am getting some problem in Bexreport decimal values.
In ODS i am able to look the values for this key figure
(Total PO Release Val)= 140.692,00,the same value in Bex report looks like this $ 140,692.00.
Here one calculation is going with these above values
% Used = 'Total PO Release Val' / 'Target Value' * 100
as per ODS value calculation it is correct = 140.692/1000 * 100 =14.692
as per Bex it is coming like this = 140,692.00/1000 *100 = 142.692.
in Bex report Percentage valus is not considering value is taking as 140,692.00 rather than 140.692.I mean to say decemal values are ignoring while calculation in Bexreport.can you any please advice me how to comeout of this problem.Appreciate your help.
Regards
Ramesh<i> "(Total PO Release Val)= 140.692,00,the same value in Bex report looks like this $ 140,692.00."
</i>
How do you check the ODS value? The amount will only have two decimal places after it, so you can't have a value like 140.692,00. It seems to be an issue of user's decimal notation (where decimal is represented by comma, and thousand seperator by '.'). Go to user profile, change this setting (in default tab) to correct one (ie decimal being represented by '.') and login again and check it. The value that you see in ODS is 'one hundred forty thousand six hundred ninety two, the same that you get in Bex, only the representation is different). -
My appl ID got blocked , because i tried to answer the security questions and i fail to get the wright answer .
If you have a Mac or can have a friend do this for you, plug in the USB flash drive and burn the video files on it to a DVD (data) disk, which can then be placed in your HP computer. If this isn't an option for you, I'd recommend the "MacDrive 9" software. I have a much older version (5.0.8) of it on my HP P-4 tower running Windows XP. It works perfectly when reading Mac-formatted USB flash drives, as well as Mac-formatted CDs.
-
Wrong Answer for substring question?
This is the question from one of Sun's e-Practice exams. I am only posting it because I believe the answer is wrong.
QUESTION:
A text field in a GUI allows a user to type in a string, pNum, that represents a telephone number in the following format: AAA-PPP-NNNN; where A, P, and N are digits. Assume that this string format has been validated by another part of the system.
Which line of code generates a string in the format AAAPPPNNNN that will be stored to a database?
SUN's ANSWER:
pNum.substring(0,3) + pNum.substring(4,7) + pNum.substring(8,12)
This answer is INCORRECT as it would produce: AAA-PPP-NNNN[EXTRA] and NOT the desired: AAAPPPNNNN
SHOULDN'T THE RIGHT ANSWER BE:
pNum.substring(0,2) + pNum.substring(4,6) + pNum.substring(8,11)
THIS WOULD PRODUCE: AAAPPPNNNN
Note: If it is representing the string without the '-' characters (as if a 'replace' is implied), SUN's answer would still be wrong.. it should then be:
pNum.substring(0,2) + pNum.substring(3,5) + pNum.substring(6,9)
THIS WOULD PRODUCE: AAAPPPNNNN
Does anyone agree with me?Read the API, where it says:
"The substring begins at the specified beginIndex and extends to the character at index endIndex - 1."Note that it ends not at endIndex, but at endIndex - 1. -
Content Search Web Part displaying wrong Results for anonymous Users.
HI Forum Group,
I am getting Wrong results for my content search web part. The requirement is to show the News Description for the selected news item.
I have a catalog site which stores News like
News1
News2
News3
as Items. and i have connected this catalog in publishing site which is anonymous. In the publishing site created one page "News.aspx"added search results webpart which shows all the news item. Added one page "Description.aspx" to show
description to show the selected news item.
When ever user selects any news from news.aspx page it will redirected to description.aspx with the selected item ID
The "Description.aspx" the search results page gets the data based on the URL by QueryString parameter as shown below
The problem is, if i multiple items to open in tabs all the items are showing the data same as the first selected item, though the article ID is different.
Thanks
SithenderHi,
Thank you for your feedback on how you were successful in resolving this issue.
Your solution will benefit many other users, and we really value having you as a Microsoft customer.
Have a nice day!
Best Regards,
Lisa Chen
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
Getting wrong subtotals in the Report
Hi,
I have generated a report. But in that report i am getting wrong subtotals for some of the rows.
Please tell me what can be the reason and the corrective action for this.
Thanks and Regards,
VikrantIs that the Key fig are not properly adding up??? Then go the properties and set Calculate result as Summation
If this is not your problem then could you please show with an example how ur report looks like and what is the error that u are getting???? -
Hi, i forgot answer for security question
Hi
I forgot answer for security question.
However, i put the e-mail address which was wrong one, because e-mail system of "yahoo.co.kr" can not use anymore.
So how do i get the answer for the other e-mail address???
And how do i change the original alternate e-mail address??
Thanks!Hello there, Sungyong Ha.
The following Knowledge Base article offers some great information on how to resolve issues with forgotten security questions:
Apple ID: All about Apple ID security questions
http://support.apple.com/kb/HT5665
What should I do if I don't remember the answers to my Apple ID security questions?
If you forgot the answers to your security questions, try answering them at least once to see if you can get them right, even if you're not sure you remember the answers. If you're confident that you can't remember them, try one of the following:
If you have three security questions and a rescue email address, sign in to My Apple ID and select the “Password and Security” tab to send an email to your rescue email address to reset your security questions and answers.
If you have one security question and you know your Apple ID password, sign in to My Apple ID and select the “Password and Security” tab to reset your security question.
If you have one security question, but don't remember your Apple ID password, contact Apple Support for assistance. Learn more about creating a temporary support PIN to help Apple confirm your identity when you contact Apple Support.
Note: If you forgot your password and answer your security questions incorrectly too many times in a row, you will be unable to try to answer your security questions for a period of time. During that time, you will not be able to reset your password and will not have access to your account.
Thanks for reaching out to Apple Support Communities.
Cheers,
Pedro. -
hi
i didnt get the answer for the security questionI spoke with Apple Support this morning and they believe anything MobileMe related is due to the conversion over to iCloud that's taking place.
As for other email clients, check with your host to see if settings have changed on their end. I use inmotionhosting.com and over the weekend the updated their outgoing requirements so that a password authentication is now needed.
Hope that helps get some on the right path to resolving their issues! -
Trying to get another card for my G5
This is one of the few questions I've asked Apple, and they absolutely have no clue on what to answer. I was on hold for 30 minutes trying to get an answer for this, and it wasn't a straight answer after all. I also asked one of the "Apple Experts" in online-chat, he sent me to AppleCare.
I have a PowerMac G5 (late 2004) Dual 2.5GHz. It has an AGP 256MB ATI Radeon card in it with DVI and VGA outputs.
I want to get a second 23-inch display, but I don't want to use the same card. The G5 I have from my understanding, uses PCI-X slots. I know it's backwards compatible with PCI cards.
What card is best for my computer to run that other display separately? Also, I know some of these cards don't support Quartz Xtreme. Any comments, suggestions on this? Thanks guys.This is my G5 Forrest:
http://support.apple.com/specs/powermac/PowerMac_G5J
une_2004.html
The Dual 2.5Ghz from late 2004.
And Malcolm, thanks for that. The thing is I don't
want to sacrifice my gaming FPS. What would you
recommend? I actually have this card installed in my
computer:
ATI Radeon 9800 XT with 256MB of DDR SDRAM
Thanks!
June is not late 2004, late 2004 is October
Maybe you are looking for
-
FrameMaker 9 - Autonumbering of Tables/Figures not working correctly
I have a multi-chapter book. My autonumber paragraph definitions for "Figure Title" and Table Title" are: F:Figure <$chapnum>-<n+> T:Table <$chapnum>-<n+> My other autonumber tags are: C:Chapter <n+> A:Appendix <A+>: L:<a=1>)
-
Alert Management for RFC Communication Channel
Hi All, I want to send notification to user using Alert Management in case of System Error in RFC Adapter. I tried with defining rule in RWB with * . But still I am not able to find notification in Inbox or Mail Inbox. Thanks.
-
I accidentally right-click and choose 'Export to Shared Services' on a Calc script in EAS. the help file is not much...I am curious...where did this export to in Shared Services? What is the point of this feature? Thanks JTS
-
I get a lot of screen distortion, and my iMac completely freezes or crashes. I get a video ram failure message when I run Techtool. I've tried reinstalling the system, but it's still happening. I had the logic board replaced while it was under warr
-
Safari won't stop reformatting or reflowing page
Anyone else having problems with Safari constantly reformatting/reflowing pages with comments? For example, this page: http://money.cnn.com/2012/07/31/news/economy/drought-oil-us/index.htm?hpt=hp_t3 The page is full width then the slider appears indi