Can you help me do this question?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Mar 2008
Posts: 8
Reputation: 9107you is an unknown quantity at this point 
Solved Threads: 0
9107you 9107you is offline Offline
Newbie Poster

Can you help me do this question?

 
0
  #1
Mar 1st, 2008
i just started the course but teacher gave me this amazingly hard question for to start with he said it's some sort of challenge question im not just asking you for the answer but i think i need LOTS of
// The "Taxesforresidents" class.
public class Taxesforresidents

// The "Taxesforresidents" class.
public class Taxesforresidents
{
public static void main (String[] args)
{
System.out.println ("Enter the icome");
double income = ReadLib.readDouble ();

System.out.println ("Enter the housing cost");
double housingCost = ReadLib.readInt ();

System.out.println ("Enter the number of children");
int childTotal = ReadLib.readInt ();

System.out.println ("Enter the total number of children in school");
int schoolChildren = ReadLib.readInt ();

if (housingCost <= 600000) income -= 1500000;

if (income < 0) income = 0;

double tax = taxableIncome * 19 / 100;
tax -= 35000 * childTotal;
tax -= (67000-35000) * schoolChildren;

if (tax < 0 && (housingCost > 580000 || childTotal < 3 || schoolChildren == 0)) tax = 0;

if (tax > 180000) tax += income * 15 / 100;
return tax;
}



} // end of main method
} // end of Taxesforresidents class


i hope someone help me with this question so here is the question

The government of Mississauga has asked you to write a program that would calculate taxes for Mississauga residents. Your program should ask for the income (income) housing cost (housingCost), number of children (childTotal), and the total number of children in school (schoolChildren). It should then compute and print the tax payable or the refund due. The following are the tax regulations: the municipal tax rate is 19% but residents are not taxed on the first $15000 unless they pay more than $6000 for housing. For every child, residents get a $350 reduction, or $670 if the child is in school. This reduction never results in residents getting refunds unless their housing costs are less than $5800 and they have more than 2 children, at least one of them in school. If the tax payable is more than $1800, then it is increased by an additional 15% surtax.

an output window with the following inputs:


3 children with 1 child in school
35000 income
5999 house cost


and here is the ReadLib

// The "ReadLib " class by R.Parteno February 2001
// ReadLib is a library class of read routines all based upon pressing the enter key
// ReadLib provides methods for reading int, double, boolean, char and String types

import java.io.*;
import java.util.*;

public class ReadLib
{
// the Tokenizer is used to get the first item typed on a line, used with
// readInt(), readDouble(), and readBoolean()
static private StringTokenizer stok;

// the BufferedReader opens the connection to the keyboard
static private BufferedReader br
= new BufferedReader (new InputStreamReader (System.in));

public static int readInt () // uses a Tokenizer and Integer wrapper class
{ // to get a true int value
int i;
try
{
String str = br.readLine ();
StringTokenizer stok = new StringTokenizer (str);
i = new Integer (stok.nextToken ()).intValue ();
}
catch (IOException ex) // connection failure
{
System.out.println (ex);
i = 0;
}
catch (NumberFormatException nfe) // invalid keyboard entry
{
System.out.println ("Warning: A non-numeric value was entered");
System.out.println ("Your variable has been given value of 0");
i = 0;
}
return i;
}


public static double readDouble ()// uses a Tokenizer and Double wrapper class
{ // to get a true double value
double d = 0;
try
{
String str = br.readLine ();
stok = new StringTokenizer (str);
d = new Double (stok.nextToken ()).doubleValue ();
}
catch (IOException io)
{
System.out.println (io);
}
catch (NumberFormatException nfe)
{
System.out.println ("Warning: A non-numeric value was entered");
System.out.println ("Your variable has been given value of 0");
d = 0;
}
return d;
}


public static boolean readBoolean () // reads a boolean, looks for trus or false
{ // assumes false otherwise
boolean result = false;

try
{
String str = br.readLine ();
stok = new StringTokenizer (str);
String answer = stok.nextToken ();
if (answer.equals ("true")) // valid true entry
{
result = true;
}
else
{
if (!answer.equals ("false")) // invalid entry
System.out.println ("An invalid value was entered, false ia assumed");
result = false;
}
}
catch (IOException io)
{
System.out.println (io);
}

return result;

}

public static char readChar ()
{
char oneChar = ' ';

try
{

String str = br.readLine ();
oneChar = str.charAt (0); // oneChar is first character of keyboard entry
}
catch (IOException io) // connection error
{
System.out.println (io);
}
catch (StringIndexOutOfBoundsException se) // enter key only, no character
{
System.out.println ("There was no character entered, blank assumed");
}
return oneChar;
}

public static String readString ()
{
String str="";
try
{

str = br.readLine (); // returns null if no characters typed

}
catch (IOException io)
{
System.out.println (io);
}

return str;
}
} // ReadLib class
Last edited by 9107you; Mar 1st, 2008 at 9:47 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,708
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 229
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: Can you help me do this question?

 
0
  #2
Mar 2nd, 2008
First of all you don't say what is your problem and what is your question. You just post code you have written.
Second of all, the main method is void, nad like any other method that is declared void cannot return anything so this is wrong:
if (tax > 180000) tax += income * 15 / 100;
return tax;
}
It should be System.out.println(tax);

And you have one extra bracket '}':
return tax; //this is the one that closes the main
}



} // end of main method
} // end of Taxesforresidents class
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 3
Reputation: jeby is an unknown quantity at this point 
Solved Threads: 0
jeby jeby is offline Offline
Newbie Poster
 
-2
  #3
22 Days Ago
i delete 2,55 and 21 but the out put is coming out only in in order...i need other two pls help...
here my code..
package com.eyc.roughworks.binarysearchtree;

import java.lang.*;
import java.io.*;

public class pBSTRemoveNode {

public pBSTRemoveNode left, right;
public Comparable data;

public static pBSTRemoveNode tree_AddNumber(pBSTRemoveNode r, Comparable n) {
if (r == null) {
r = new pBSTRemoveNode();
r.left = r.right = null;
r.data = n;
} else if (r.data.compareTo(n) < 0)
r.right = tree_AddNumber(r.right, n);
else if (r.data.compareTo(n) > 0)
r.left = tree_AddNumber(r.left, n);
return r;
}

public static pBSTRemoveNode tree_removeNumber(pBSTRemoveNode r, Comparable n) {
if (r != null) {
if (r.data.compareTo(n) < 0) {
r.right = tree_removeNumber(r.right, n);
} else if (r.data.compareTo(n) > 0) {
r.left = tree_removeNumber(r.left, n);
} else {
if (r.left == null && r.right == null) {
r = null;
} else if (r.left != null && r.right == null) {
r = r.left;
} else if (r.right != null && r.left == null) {
r = r.right;
} else {
if (r.right.left == null) {
r.right.left = r.left;
r = r.right;
} else {
pBSTRemoveNode q, p = r.right;
while (p.left.left != null)
p = p.left;
q = p.left;
p.left = q.right;
q.left = r.left;
q.right = r.right;
r = q;
}
}
}
}
return r;
}

public static void tree_InOrderPrint(pBSTRemoveNode r) {
if (r != null) {
tree_InOrderPrint(r.left);
System.out.print(" " + r.data);
tree_InOrderPrint(r.right);
}
}

public static void main(String[] args) {
pBSTRemoveNode tree = null;
int[] numbers = { 21, 3, 4, 55, 6, 3, 44, 7, 9, 4, 2, 3, 11, 56, 7, 54, 67, 87, 54, 67, 87, 45, 66, 77, 42, 21 };
System.out.print("inserting: ");
for (int i = 0; i < numbers.length; i++) {
Integer n = new Integer(numbers[i]);
System.out.print(" " + n);
tree = tree_AddNumber(tree, n);
}
System.out.print("\ntree: ");
tree_InOrderPrint(tree);
// int j = 6;
int j = 0;
int num = 2;
deleteNode(tree, numbers, j, num);

num = 56;
deleteNode(tree, numbers, j, num);

num = 21;

deleteNode(tree, numbers, j, num);


}

private static void deleteNode(pBSTRemoveNode tree, int[] numbers, int j, int num) {
for(int i = 0;i<numbers.length;i++){
if(numbers[i]==num){
j = i;
}
}

{
Integer n = new Integer(numbers[j]);
System.out.print("\nremove: " + n + " tree: ");
tree = tree_removeNumber(tree, n);
tree_InOrderPrint(tree);
}
System.out.println("\ndone ;-)");
}
}
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,708
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 229
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #4
22 Days Ago
Start a new thread. Use code tags
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC