473,411 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Making dialogs

2
I'm trying to write a program that asks the user two numbers - the 1st number is the income, the 2nd is the tax class (either 1 or 2).

If the tax class is 1, the program will divide the income by 10, if the tax class is 2, it will divide by 15. So if a user puts in "8000" as his income and "2" as his tax class, there will be a plain message saying "You're paying 4000 in taxes" (taxes=8000/15).

I have no idea how to even start on this. I'm able to write a simple program that asks a user to type in his name, then shows a "Hello <NAME>!" message... but not this. Can someone please help me, give me a push in the right direction? It would be so much appreciated.

this is what I've got so far - I can't even get the if/else thing to work. I've only done this for a couple of weeks >.<


Expand|Select|Wrap|Line Numbers
  1.  
  2.     public class eks_sett02_oppg4a {
  3.  
  4.     /**
  5.      * @param args
  6.      */
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.  
  10.         int k=1;
  11.         int j=2;
  12.  
  13.  
  14.         String s=javax.swing.JOptionPane.showInputDialog("Tast inn din inntekt");
  15.         System.out.println(s);
  16.         String t=javax.swing.JOptionPane.showInputDialog("Tast inn din skatteklasse");
  17.  
  18.         System.out.println(t);
  19.  
  20.         if (t==k){
  21.  
  22.             System.out.println("bleh");
  23.         }
  24.  
  25.         else if (t==j){
  26.             System.out.println("bah");
  27.         }
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.     }
  35.  
  36. }
  37.  
Oct 5 '07 #1
9 1440
JosAH
11,448 Expert 8TB
You're almost there (the input part that is): that JOptionPane can get a String
from the user; you can convert that String to a number (if it is a representation
of a number); read the API documentation for the Integer or Double classes.
They implement methods that can convert appropriate Strings to ints or doubles.

kind regards,

Jos
Oct 5 '07 #2
Below is the code, but I dont understand how 8000/15 equals 4000. Anyway check the code below

[ spoonfeeding code removed ]
Oct 5 '07 #3
JosAH
11,448 Expert 8TB
@eeriehunk: please don't spoonfeed code; read the forum guidelines (see the
'Help' link near the top right of this page).

kind regards,

Jos
Oct 5 '07 #4
@eeriehunk: please don't spoonfeed code; read the forum guidelines (see the
'Help' link near the top right of this page).

kind regards,

Jos
Hey, Jos ... Didnt realise that.. Just was trying to help and contribute.
Regards,
eeriehunk
Oct 5 '07 #5
JosAH
11,448 Expert 8TB
Hey, Jos ... Didnt realise that.. Just was trying to help and contribute.
Regards,
eeriehunk
No problem and no hard feelings; just don't post boilerplate code; it really doesn't
help the OPs; most of them just copy and paste it and even turn it in as if it were
their own code. There's too much trash in the IT world already (you wouldn't
want a cheater as a colleague?). This is all not implying that the current OP
would be cheating. And it also doesn't imply that your contributions are not
appreciated; keep up the good work.

kind regards,

Jos
Oct 5 '07 #6
Hey hi bro nice code but i wanna u to work a few:
Use J2SE 6(SDK i meant)
Here i just show u how u can use ur Interger or double
I get ur string as u use s but after da convert into int or double wid nextInt or nextDouble,rewrite ur prog after reding mine good luck see ya soon

[ code snipped; see next reply ]
Oct 5 '07 #7
JosAH
11,448 Expert 8TB
Hey hi bro nice code but i wanna u to work a few:
Use J2SE 6(SDK i meant)
Here i just show u how u can use ur Interger or double
I get ur string as u use s but after da convert into int or double wid nextInt or nextDouble,rewrite ur prog after reding mine good luck see ya soon

[ code snipped ]
Please mind your spelling, please don't post spoonfeeding code and most
important: please read the forum posting guidelines (select the 'Help' link
near the top right corner of this page).

kind regards,

Jos
Oct 5 '07 #8
Camya
2
Thanks you so much for the help - it took me a while, but I finally figured it out ^^ Aahh... it feels good :D

or... I think I did. It works at least, but I don't know if I did it "right".

Expand|Select|Wrap|Line Numbers
  1. public class task4 {
  2.  
  3.     /**
  4.      * @param args
  5.      */
  6.     public static void main(String[] args) {
  7.         // TODO Auto-generated method stub
  8.         double tax;
  9.         double income;
  10.         int taxclass;
  11.  
  12.         String s=javax.swing.JOptionPane.showInputDialog("Your income is:");
  13.         String t=javax.swing.JOptionPane.showInputDialog("Your tax class is:");
  14.  
  15.         tax class = Integer.parseInt(t);
  16.         income = Double.parseDouble(s);
  17.  
  18.         if(taxclass ==1){
  19.             tax=income/10;
  20.         }
  21.         else {
  22.             tax=income/15;
  23.         }
  24.  
  25.         String tittel=("Tax");
  26.         String info= "Taxes are "+tax;
  27.         javax.swing.JOptionPane.showMessageDialog(null, info, tittel, javax.swing.JOptionPane.PLAIN_MESSAGE);
  28.  
  29.     }
  30.  
  31. }
I've got another question.

Wasn't sure whether I'm supposed to make a new thread....? Anyhow, my next task is

"Make a program that asks the user for a text, prints out the number of characters in the text, splits the text in half and switch the parts and returns the result to the user".

Meaning abcdefgh should come out as "efghabcd".

Um. I think I can figure it out, sooner or later, except for the part about splitting the text. Not asking anyone to spoonfeed me code, but a little hint on this area would be great :)
Oct 5 '07 #9
r035198x
13,262 8TB
Thanks you so much for the help - it took me a while, but I finally figured it out ^^ Aahh... it feels good :D

or... I think I did. It works at least, but I don't know if I did it "right".

Expand|Select|Wrap|Line Numbers
  1. public class task4 {
  2.  
  3.     /**
  4.      * @param args
  5.      */
  6.     public static void main(String[] args) {
  7.         // TODO Auto-generated method stub
  8.         double tax;
  9.         double income;
  10.         int taxclass;
  11.  
  12.         String s=javax.swing.JOptionPane.showInputDialog("Your income is:");
  13.         String t=javax.swing.JOptionPane.showInputDialog("Your tax class is:");
  14.  
  15.         tax class = Integer.parseInt(t);
  16.         income = Double.parseDouble(s);
  17.  
  18.         if(taxclass ==1){
  19.             tax=income/10;
  20.         }
  21.         else {
  22.             tax=income/15;
  23.         }
  24.  
  25.         String tittel=("Tax");
  26.         String info= "Taxes are "+tax;
  27.         javax.swing.JOptionPane.showMessageDialog(null, info, tittel, javax.swing.JOptionPane.PLAIN_MESSAGE);
  28.  
  29.     }
  30.  
  31. }
I've got another question.

Wasn't sure whether I'm supposed to make a new thread....? Anyhow, my next task is

"Make a program that asks the user for a text, prints out the number of characters in the text, splits the text in half and switch the parts and returns the result to the user".

Meaning abcdefgh should come out as "efghabcd".

Um. I think I can figure it out, sooner or later, except for the part about splitting the text. Not asking anyone to spoonfeed me code, but a little hint on this area would be great :)
You should probably start a new thread for it but I don't think it will be a long thread anyway. You want to have a look at the String.susbstring method. Open the API docs for the String class. You'll find some more usefull methods there.
Oct 6 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mahesh | last post by:
Hi all, I have a doubt with OOAD and Dialogs. I have a Dialog Class. tkSimple.py It contains a class body as below. Now I am calling the tkSimple.py in another python program and using the...
2
by: Daniel Bickett | last post by:
Hello, I am writing an application using two event-driven libraries: wxPython, and twisted. The first problem I encountered in the program is the confliction between the two all-consuming...
1
by: sebastien maraux | last post by:
Hello NG, I would like to display dialogs such as CDialog and CMenu in fullscreen exclusive mode. I noticed that CMenu always display under openGL drivers (my app is a 3D Renderer window) but...
1
by: dwaine | last post by:
I HAVE done this before, but can't figure this out. It's not critical, just an annoyance. Added RTF files to a standard deployment project, then "Read Me" and "License Agreement" dialogs and...
2
by: David | last post by:
Hello, I have an application that has been running for years and had little problem with it. We've been retesting the latest code under Windows 2003 and found a surprise. There is a certain...
0
by: Tony Johansson | last post by:
Hello! Assume I have 10 dialogs and these will be written in winforms C++.NET. Assume also that 30 % of these 10 dialogs are identical. What kind of component would be suitable to avoid to...
1
by: wendy | last post by:
I have got a problem while using the modal dialogs. In my code I need to open a modal dialog from the parent page and I need to enter some values in the dialog and save it. It takes the values...
1
by: hash | last post by:
Hello! I recently ported my project from VC6 to VC8. But while executing them I found that dialogs have not changed to XP style. These dialogs are being shown with same WIN98 style. However in...
0
tbarto
by: tbarto | last post by:
Hello, For some time I have been working on an application where a part of the solutuion is a class that is able to find all the system dialogs ( eg. openFileDialog ) that are currently open....
2
by: vbdummy | last post by:
I am not able to use Dialogs.Item(wdDialogFileOpen) because of the way I'm using word inside of another application. The code below works outside of the application but not in it: Sub FileInsert()...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.