Calculate Tax Payable Based On Income And Income After Tax Deduction
Nov 3, 2014
I'm writing some code which calculates the tax payable based on income, and I need to have a separate method which then calculates the income AFTER the tax has been deducted. I've done this quite easily by re-writing the code in the next method, however is there a more efficient way around this where I can pass the values from the first method to do the calculation...
public class TaxCalculator {
// Main method calling taxpayablereturn and taxafterdeduction
public static void main(String[] args) {
System.out.print("Tax Payable = £"
+ TaxCalculator.taxpayablereturn(570));
With fields that holds a tax payer social security number, last name, first name, street address, city zip code, annual income, marital status and tax liability, include a constructor that requires argument that provide values for all other fields other than the tax liability. the constructor calculates the tax liability based on annual income and percentage in the ff table
Income 0-20,000 20,000-50,000 50,000 and over
marital status single married 15% 14% 22% 20% 30% 28%
I have written the following code to calculate tax payments based on income and filing status :
import java.util.Scanner; public class computeTax { public static void main(String[] args) { Scanner input = new Scanner(System.in); // prompt for filing status System.out.println("enter '0' for single filer,");
[Code] ....
The while loop initiated on line 21 is there so that in case the wrong input is given at the prompt given in line 24, the program outputs "please type the right answer" with the command on line 254 before looping back to line 24 and prompting the user to enter his status number. The program works as long as the input at line 28 is an integer. Not surprisingly if the erroneous input here is not an integer, the program outputs the following error message :
Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:909) at java.util.Scanner.next(Scanner.java:1530) at java.util.Scanner.nextInt(Scanner.java:2160) at java.util.Scanner.nextInt(Scanner.java:2119) at computeTax.main(computeTax.java:28
To try to solve this I used the Try / Catch technique with the following version of the code :
import java.util.Scanner; public class computeTax { public static void main(String[] args) { Scanner input = new Scanner(System.in); // prompt for filing status System.out.println("enter '0' for single filer,");
I am trying to build an app for managing expenses to practice with java programming. I am stuck on the ActionEvent block. The program i am trying to make needs to minus the expenses from the monthly income and display the net income in JLabel.
This program is for a swimming pool filling service company. They charge 2 cents per gallon and $50 per hour to fill a pool. The truck can fill at a rate of 730 gallons per hour.
Create the Pool class that calculates the cost to fill a pool based on it's Shape, length, width and depth. (Input order is S L W D)
The pool class will need data fields for String shape, double length, double width, double depth, static double GallonsPerSqFoot = 7.4805, static double price per gallon = .02, static double FillingFeePerHour = 50.0, and static double FillingRate = 730gal/hr.
Create a No-Arg constructor and a constructor that accepts the non-static values, and has the methods: getShape, getLength, getWidth, getDepth, getGallons, getHours, getFillingFeePerHour, getHourlyCost and getTotalCost.
At the end of the class, create a main() method that asks for the input and returns the output based on the Pool class gets.. methods.
The shape options are oblong or rectangle. (A round pool would be oblong with the same width and height, a square pool would have the same width and height)
Example Output An oblong pool 18.00 feet long by 12.00 feet wide and 5.00 feet deep will use 6923.10 gallons of water and take 9.48 hours to fill. The total cost will be 612.65.
OK very similar to switches & cases & ifs, but I'm wondering if I can do something like that:
public Method[] method; method[0] = walk(); method[1] = run(); method[2] = stop(); for (int i = 0; i < x; i++){ if (i == myNumber) { run m[i]; return; } }
I am implementing a console based interface for an assigment. I've got a DAO interaces and implementations ready and I am stuck on a loop that checks whether to display logged in menu or logged out menu.
public static void main(String[] args) throws SQLException { Main consoleInterface = new Main(); boolean runningLoop = consoleInterface.isRunning(); boolean loggedOutLoop, loggedInLoop; while(runningLoop) {
[Code] ....
So when this runs it should show loggedIn() method only and only if the condition is not met. At the start when program runs I set loggedOutLoop = true and loggedInLoop = false. When I handle login I set loggedOut = false and loggedIn = true
What seems to happen is that the else statement doesnt work and the output I've got is only loggedOut() method displayed where I only want loggedIn() to be displayed without loggedOut().
I'm trying to create a tile based map JPanel but all I get is a white screen. I'm fairly new to the Java Swing and AWT package so I've been watching tutorials on YouTube so learn as much as I can.
I've got three classes: Window.java which includes the Main method, Panel.java which is the JPanel and Tile.java to draw all the images into an array.
Window.java:
import javax.swing.JFrame; public class Window extends JFrame { public Window() { setTitle("Project"); setSize(500, 400);
[Code] .....
I've checked through everything and still cannot find what I'm doing wrong. I did try different codes but I just got errors instead.
I'm relatively new to Java, I'm trying to create a text based game, like those old ones where you type "north" or "east" to move as such, and "look" to inspect the area. My only problem thus far has been trying to figure out just how I should... "structure?" the movement. As in, what's the best overall way to approach this? I've tried making a new method for every area and just passing a variable called "location," but along with passing the inventory and stat arrays, it's just become messy. Or is this a good way to do it? I have a separate method for when the player enters something, but then how will it know which description to give when the player types "look?"
I have to write Scanner and Parser for the C-Code based on Java and obtain Abstract syntax tree(AST) . I am allowed to use tools like ANTLR, CUP. But i should be able to expand all macros in my code to its basic low level data type like int, boolean and whats the best approach?How to start initially?
I started a text based game, but I am dissatisfied with the console that PrintF prints to. How can I set up a window and have text output to that window, and have my player type responses in the window?
I am new to JSP !! and I'm developing a web-based chatting system using JSP and socket.
The problem I am facing is that the sender can send message but on the receiver side we have to manually refresh the page. The sender stays into blocking mode until the receiver refresh its page !
After that I've implemented auto-refresh on the receiver side and "Connection Refused" exception is generated.
This is what the gui looks like at run time. The question is how do I compact it so there is not so much space between the labels and the textArea. I've tried using different numbers on my GridLayout, but not a lot of success.
For some time i've been trying to rewrite my XML configurated webapp into one that has Java Based cofiguration. Unfortunately ,even after going through many tutorials i've been unable to do so.
So, I've been working on creating a text-based game engine that would create games similar to Achaea. It's been working pretty well so far. I just finished creating a great mapping system, but now I've run into a problem. I have a mapping system, but actually creating a map would prove to be quite a lot of work. Each location that the player can be inside of has a name, description, map symbol, and an array of the things inside of it. How can I make some sort of map creation program or something so that I can create my maps more easily?
I thought perhaps making a constructor that accepts a list of files, the first containing a table of strings for the names, the second containing a table of strings for the descriptions, etc.; but it seems that would be quite tedious and may be more complex than actually just hard-programming maps.
i'm totally new to Java.I'm making a small text based RPG and this is what i've come up for now.
Java Code:
import java.util.Scanner; class Main { public static void main(String args[]){ Scanner input = new Scanner(System.in); Player playerObject = new Player();
[code]....
My thing is that i want the user to enter 'Caucasian' or another race in the console below and i want it to be saved in a variable or something else in the Player Class that i can later use it in texts or something else. My question is how can i do it?
I tried like 'int Mongoloid = 1; int Caucasian = 2;'
And the same with the others, and after that i tried to use them with the Switch Statement but it did not work.
I'm currently trying to build a DAO based application where you use a text file as a data source. It have worked out well until I tried to delete lines from the file.
I've managed to fill out the temp file with everything except the line I wanted to remove, but when I try to replace the original file with the temp file it won't work. It casts the error: "temp.txt -> databilar.txt".
I've also tried to use the renameTo method without any success...
I've been working on a small text-based RPG for fun. This particular part is supposed to allow the user to change their name. Now, the problem is that when they reach the option to change their name, the above code seems to skip the line:
name = scan.nextLine();
It will erase whatever the player previously entered for their name, as well. So it will print out:
Okay, let's change your name. What did you say it was? Alright, so you'll go by . Is that correct? [now allows input for verifyNameChange]
The above code works fine on it's own, but somehow messes up when put into the full program. I don't want to post the whole program, because it's fairly large. But the String name is set and functions fine before this bit of code.
I'm trying to create a tile based map JPanel but all I get is a white screen. I'm fairly new to the Java Swing and AWT package so I've been watching tutorials on YouTube so learn as much as I can. I don't know where I'm going wrong.
I've got three classes: Window.java which includes the Main method, Panel.java which is the JPanel and Tile.java to draw all the images into an array.
Window.java:
import javax.swing.JFrame; public class Window extends JFrame { public Window() { setTitle("Project"); setSize(500, 400); setLocationRelativeTo(null);
Check out the following basic code (assume that dog has a method called bark):
Dog d = new Dog(); Object o = d;
o.bark(); // error
But why? Isn't o just a pointer to a memory address which has the dog object? If so, why can't the compiler see that the object has a method called bark? Or, to ask the question another way, why is Java designed to check the object reference to see if the method exists instead of the object itself?
a new java executable file which does heavy processing (batch). Development hasn't really started yet and the design phase is just beginning. Now the client is asking us to give them the minimum server specs to be able to run our application..I'm thinking this can't be done without performance testing, which will be after development. Is there a better and faster way to be able to assess this?
I'm trying to create java based fairly simple forum.
The task is as following:-
• each user may post exactly one research topic;
• each each may see all research topics posted by other users;
• each each may read all messages contributed by all users on a particular research topic;
• each user may post a new message to contribute to the discussion on any of the topics posted.
Something like below:-
User topic: Intrusion Detection Systems Posted by: John [22/10/11 14:00] John wrote I am building a new IDS based on neural networks. …………….Comments ………….? [22/10/11 14:12] Kate wrote there could be too many false positives!