Tax Return - Constructor Calculate Tax Liability Based On Annual Income And Percentage
May 12, 2014
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'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));
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 wasn't supposed to use the % in front of f.I have to make a program to calculate the average temperature and annual precipitation in Jacksonville. I get this error on line 49:
java.util.IllegalFormatPrecisionException; null (in java.util.Formatter$FormatSpecifier)
I don't get any errors during compilation.Here is my code (I'm not using the system selection yet):
import java.util.Scanner; public class AnnualClimate1 { public static void main(String[] args) { double[] temperaturesInJacksonville = {53.1, 55.8, 61.6, 66.6, 73.4, 79.1, 81.6, 80.8, 77.8, 69.4, 61.7, 55.0};
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.
Class1 class1 = new Class(); class1 = Class2.method1();
and
Class1 class1 = Class2.method1();
I have one more query on the same lines ... I always need to call the method1 of Class2 whenever i create a object of class1. So I wanted to go with the constructor in Class1. But the method1 in Class2 has a return statement. so is there any better way to do this other than constructors.
Sample code:
public int class Class2{ public static method1(){ return 2; } } public class Class1{ public Class1(){ Class2.method1(); } }
I am having an issue with a parallel array that I created that returns array values based on an input. The code only works for the first four array locations just fine. The remaining values are not found. I thought it might be a memory allocation issue with the array size, I tried to dimension the array, however, using the Eclipse editor get errors.
import java.util.*; import javax.swing.JOptionPane; public class StudentIDArray { static String[] studentNum = new String[] {"1234", "2345", "3456", "4567", "5678", "6789", "7890", "8901", "9012", "0123"}; static String[] studentName = new String[]
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.
Write method distance to calculate the distance between two points (x1, y1) and (x2, y2). All numbers and return values should be of type double. Incorporate this method into an application that enables the user to enter the coordinates of the points.
Hints:
- The distance between two points can be calculated by taking the square root of
( x2 - x1 )2 + ( y2 - y1 )2
- Use Math class methods to compute the distance.
- Your output should appear as follows:
Type the end-of-file indicator to terminate
On UNIX/Linux/Mac OS X type <ctrl> d then press Enter
On Windows type <ctrl> z then press Enter
Or Enter X1: 1
Enter Y1: 1
Enter X2: 4
Enter Y2: 5
Distance is 5.000000
Type the end-of-file indicator to terminate
On UNIX/Linux/Mac OS X type <ctrl> d then press Enter
My question is how do I configure this so that when / if I need to change the discount value, it automatically adjusts the % discount off of the Full or Compact?
All I can get to work is simply hardcoding it and assigning the discount value, i'm probably just messing up the syntax.
I want to use a method, which takes for example an int and also returns an integer. For example, if the the given integer is strong return a, if it is notstrong return b. How would you write that in a Code?
I want to use that in a more general way. I want to give a method mlong the value X of the type date and let it return an int. Type date consists of 3 int, one of them is the int month.
mlong should return an int depending on the X.moth. at the moment my code looks like this:
// File1: public class date { public int day; public int month; public int year; }
// File 2: public class monthlength { public int mlong(date X) { int t; t = X.month; if (t == 1 || t == 3 || t == 5 || t == 7 || t == 8 || t == 10 || t == 12) { return 31; } if(t == 4 || t == 6 || t == 9 || t == 11) {return 30;} } }
These are the values I have. Basically I just need an explanation of how to code a statement so I receive the calculated discount of a Full or Compact.
Here is the excerpt from the code, I can copy the whole code in too if needed.
Java Code:
System.out.println("You selected Item1."); System.out.print("Have coupon? [Y or N]"); answer = kb.next(); if (answer.equalsIgnoreCase("n")) System.out.print("Price is 30.50 per day."); if (answer.equalsIgnoreCase("y")) >This is what I'm looking for< mh_sh_highlight_all('java');
So, I am supposed to write a program that calculates the total annual compensation for a salesman using user input for the salary, sales, and commission rate (list of 3 predefined commission rates. have to display in dollar format the amount of commission and total annual salary.
CommCalc class
public class CommCalc { //attributes of class, stored data private double sales; private double salary; private double rate; //and a total field? beware stale data. //store sales argument from sales field public void setSales(double sal)
[Code] ....
I know that i have to fix some of the semantics . I have this code that I made earlier, is there an easy way to make it into a GUI interface? Or will I have to go throughthe code lines to add the JOptionPane? And I am a little confused on how to make a list (array) for the commission rate.
I am trying to create a program that allows me to enter 5 students numeric grade (0-100) to a letter grade (A, B, C, D, F) and I CANNOT use an array. When I try to run my program it says main class not found, and when I change the it from a string to a void in the main method it does not work.
Java Code:
import java.util.Scanner; public class Week3ControlStatements2 { public static String main(String[] args){ int numberGrade = 0; int quotient = numberGrade / 10; int remainder = numberGrade % 10;
I've been writing a fraction class code below that does a number of arithmetic calcs and when I run it these are the results I get. My gcd doesn't work when it comes to negative fractions and I'm not quite sure how to print.out the boolean methods ((greaterthan)), ((equals))and ((negative)). I'm also not sure if I have implemented those 3 methods properly. I'm still learning how to do unit testing.
Enter numerator; then denominator. -5 10 -5/10 Enter numerator; then denominator. 3 9 1/3 Sum: -5/30 -0.16666666666666666 Product: -5/30 -0.16666666666666666 Devide: -15/30 -0.5 subtract: -45/90 -0.5 negative: 1/6 0.16666666666666666 Lessthan: 1/6 0.16666666666666666 greaterthan: 1/6 0.16666666666666666
FRACTION CLASS
import java.util.Scanner; public class Fraction { private int numerator; //numerator private int denominator; //denominator
How do i take input values for TwoDPoint (which are objects) and return it back in numerical values also print them.
When i create an object in main method and pass values to my function of return type TwoDPoint,it gives error:- found int,int need TwoDPoiint,TwoDPoint.
// Here is what i tried to do:
Created class TwoDPoint that contains two fields x, y which are of type int. Defined another class TestTwoDPoint, where a main method is defined.In the main method created two TwoDPoint objects.
Then I modified the class TestTwoDPoint and add another function to it. This function takes two TwoDPoints as input and returns the TwoDPoint that is farthest from the point (0,0).
Then I added another function to TestTwoDPoint. This function takes two TwoDPoints as input and returns a new TwoDPoint whose x value is the sum of x values of the input TwoDPoint's and whose y value is the sum of the y values of the input TwoDPoint's.
class TwoDPoint { int x = 2; int y = 4; } class TestTwoDPoint { public static void main(String args[]) { TwoDPoint obj1 = new TwoDPoint(); System.out.println(obj1.x); System.out.println(obj1.y);
I want to use a method, which takes for example an int and also returns an integer. For example, if the the given integer is even return 1, if it is not even return 0. How would you write that in a Code?
I want to use that in a more general way. I want to give a method mlong the value X of the type date and let it return an int. Type date consists of 3 int, one of them is the int month.
mlong should return an int depending on the X.moth.
At the moment my code looks like this:
// File1:
public class date { public int day; public int month; public int year; }
// File 2:
public class monthlength { public int mlong(date X) { int t; t = X.month; if (t == 1 || t == 3 || t == 5 || t == 7 || t == 8 || t == 10 || t == 12) { return 31; } if(t == 4 || t == 6 || t == 9 || t == 11) {return 30;} } }
I was practicing my java skills and came across an exercise in which a non parameter constructor calls a two parameter constructor. I tried a few searches online but they all came back unsuccessful. This is the part I am working on:
public PairOfDice(int val1, int val2) { // Constructor. Creates a pair of dice that // are initially showing the values val1 and val2. die1 = val1; // Assign specified values die2 = val2; // to the instance variables. } public PairOfDice() { // Constructor that calls two parameter constructor }
I tried calling the two constructor using the line "this(val1, val2)" but I get an error because val1 and val2 are local variables.
Then I tried to use the same signature: "this(int val1, int val2)" but that didn't work either.
I'm wonder about the issue of constructor for arrays. Let say I have a class tablica, and one component int[] tab. If I get it right until now tab is nothing more than empty reference to some unexisting array?
import java.util.Random; class tablica{ int[] tab; tablica (){ // i wish it was constructor
[code]....
Then, I'm trying to build the constructor for class tablica. What can be the parameter of such constructor? Is it fields of array? It is simple forf for basic variable
- I liken values defined in constructor with those global defined in class. But how to do it with array component tab.
If I create array object in main method then how can I use this constructor?
public class TestClass { public TestClass(String k){System.out.println(k);} public static void main(String[] args) { try { hello(); } catch(Exception e){System.out.println(e);}
[Code] ....
Explain how to catch block act as constructor with parameter?
"A constructor cannot be abstract, static, final, native, or synchronized."
I understand on why it can't be all of the above, except "final".
Why can't we have a final constructor, i understand constructors are not inherited, hence no chance/case of overriding etc. But why is it not allowed at all ?