Write Class That Accepts User Hourly Rate Of Pay And Number Of Hours Worked
Feb 22, 2014
Here is what im trying to do
Write a class that accepts a user's hourly rate of pay and the number of hours worked. Display the user's gross pay (gross pay = hours worked * hourly rate), the tax withheld (tax withheld = gross pay * tax rate) and the net pay (net pay = gross pay - tax withheld).Use a named constant for storing the tax rate of 0.15
Here is my Code:
import java.util.Scanner;
class Tutorial
{
public static void main(String[] args);
[Code]....
View Replies
ADVERTISEMENT
Jan 30, 2014
I am not sure how to incorporate the rate per month and the three rate zones.
Problem: Electricity billing charges vary with the season and amount used.
Southwest Power and Light provides electricity at the basic rate of $ 0.10 per kilowatt for the months December through February, 0.12 per kilowatt for the months of March through May, and 0.15 per kilowatt for the remaining months.
Customer billing is divided into three rate zones: 0-350 kilowatts, 351 – 500 kilowatts, and above 500 kilowatts. Usage up to 350 kilowatts is billed at the basic rate. Usage between 350 and 500 kilowatts is billed at 10% above the basic rate. Above 500, billing is 25% above the basic rate. These surcharges apply only to the usage falling within the respective rate zone.
View Replies
View Related
Apr 9, 2014
The instructions:
Write a method named hopscotch that accepts an integer parameter for a number of "hops" and prints a hopscotch board of that many hops. A "hop" is defined as the split into two numbers and then back together again into one.For example, hopscotch(3); should print:
1
2 3
4
5 6
7
8 9
10
how to start this program.
View Replies
View Related
Nov 20, 2014
I am trying to write a code that allows a user to input the number of stones in a basket, then put the stones in my pocket, after the stones are in my pocket, the stones must be taken out, one by one, and thrown in a pond. I get stuck at this part because my for statement has to subtract the number of stones in my pocket (one at a time) and add a stone to the pond (one by one) at the same time.I can get the pond stones to increase until the max amount of stones with the following:
for (int i = 0; i < stones; i++) {
System.out.println("Pocket:" ? " " + "Pond:" + i);
how to reduce one and add to other. Is it possible to do this in one for statement? I tried to put stones-- in place of the question mark, but that is not working.
View Replies
View Related
Jan 26, 2014
I am attempting to make a heart rate calculator program. Here is a little overview of what I am trying to do. It must use a constructor and get and set methods. It must print heart rate ranges and the user's information(age).
// Use scanner to get inputs
import java.util.Scanner;
// Declare class
public class HeartRates {
private int Age;
private int DayOfBirth;
private int MonthOfBirth;
private int YearOfBirth;
private double MaxHeartRate;
private double MinTargetHeartRate;
[Code] ....
View Replies
View Related
May 13, 2014
I have an application which is doing a fine job of placing the total hours on the interface.
Where I am breaking down is that I am unable to split the string into two distinct groups: hours and minutes
private HtmlElement createTravelTimeRow(ShowSet showSet) {
HtmlElement tr = new HtmlElement(ROW_OPEN, ROW_CLOSE);
HtmlElement td = new HtmlElement(CELL_OPEN, CELL_CLOSE);
[Code].....
I came across something which showed how to split the String but I am still very unsure how to do this.
View Replies
View Related
Mar 5, 2014
I was trying to execute the following program and the multiplication worked but the division didn't work.
import java.util.Scanner;
public class BodyMassIndex {
public static void main(String[] args) {
// Prompt the user for weight and height
// Create a scanner
Scanner input = new Scanner (System.in);
System.out.println("Please enter your weight in pounds");
int weight = input.nextInt();
System.out.println("Please enter your height in inches");
int height = input.nextInt ();
double BMI = weight * (0.45359237)/ (height * 0.0254)*(height * 0.0254);
// the weight * (0.45359237) executed but it wasn't divided by (height * 0.0254)*(height * 0.0254)
System.out.println ("Your BMI is "+BMI);
View Replies
View Related
Dec 21, 2014
I am doing a program where i have to implement a payroll system into a company for hourly, fixed monthly and commission paid workers. I also have to put the method which i did. the problem is I cant tell if my calculation is wrong or if i am missing a codes some where. The output is not giving me the answer that I was at least expected,
Here is my method:
{
< double total_deduction;>
< total_deduction = gross_pay - deduction;>
< return total_deduction;>
}
< public static double calGrossH(double hours_worked, double pay_rate)>
[Code] .....
I have done a lot researching and have come up with some search with almost the same calculation and I have also asked employees of a company on how they calculated hourly rate, commissions rate and fixed rate for all workers and gotten the same response but for some reason the output is not what it is supposed to output. here is my output.
<
un:>
<please enter the number of employees to be processed 31>
<please enter employee id number 3669>
<please enter employee first name>
[Code] ....
I dont know if I am missing some calculation somewhere or codes been researching and bussing my brains to figure out where is the missing codes or calculation.
View Replies
View Related
Mar 28, 2015
I have a beginning Java Program I have been working on that creates a number guessing program where the computer guesses a number that the user is thinking of within a certain range. I so far have the program below, but need getting rid of a few kinks/ adding features.
-First, I need to set it up so that the user will be prompted and give a range. It should run and produce something like this:
Welcome to this first-ever mind-guessing program!
Please pick a range (higher than 1 and no larger than 50): 32
You will choose a number between 1 and 32... and I will try to guess it.
With each of my guess, you will tell me whether I am too high (h or H), too low (l or L), match (m or M), or you want to quit (q or Q). My objective is to find the number using as few guesses as possible.
-Second, the game is supposed to give up and restart after failing the five, guesses, but for some reason, after it fails the fifth time, it prompts a fifth guess once again instead, then restarts after- I need to prevent this, so that it should look something like this:
My fourth guess is 17: h
My guess is too high?
My fifth guess is 16: h
*** I am unlucky this round. I give up.
Let's play!
My first guess is 10:
etc..
import java.util.*;
import java.lang.Math;
public class numguessprac1 {
// Declaring variables
public static String input;
public static int quit;
public static int guess;
public static int wins;
[Code] ....
View Replies
View Related
Sep 16, 2014
So I am currently writing my first assignment and have run into problems with my coding. The task was to have someone enter a 5 digit number and in return, I list each number on their respective lines. We also must create an error if a number other than 5 digits was entered. My problem is that when they enter a 1 or 2,3,4,6,7,8 digit number.. the error message occurs along with the rest of the messages (listing the numbers, etc). I want the program to end (or even re-ask to enter the numbers) if they incorrectly enter the data.
View Replies
View Related
Nov 4, 2014
I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.
public class PrimeNumber
{
Scanner scan = new Scanner(System.in);
int userNum;
String neg;
public void getUserNum()
[code]...
View Replies
View Related
May 5, 2014
trying to write a program that takes a user inputted number and converts it to a binary number.
Here's what I have:
package com.java2novice.algos;
import java.util.Scanner;
public class Converter {
static Scanner console = new Scanner(System.in);
public void printBinaryFormat(int number){
int binary = console.nextInt();
[Code]...
Bugs on:
Line 13
Line 17
Line 23
View Replies
View Related
Jan 30, 2014
Write a class named Calculator add four methods to that class:
add(int a, int b)
sub(int a, int b)
mul(int a, int b)
div(int a, int b)
Then write a Tester class with main function and show the use of the methods in Calculator class..
View Replies
View Related
Sep 21, 2014
I have an assignment where I'm supposed to write a program where the user inputs a month between 1-12 and then the right amount number in every month. I've tweaked the code a bunch of times, but I keep getting this error message:
insert "}" to complete StatementKALENDER_3.java
insert "}" to complete BlockKALENDER_3.java
The code:
import java.util.*;
import java.util.Scanner;
public class KALENDER_3
}
public static void main(String[] args){
Scanner scanner = new Scanner (System.in);
System.out.print("Skriv ett manadsnummer: ");
[code].....
I think I have just forgot to put in a few { } symbols, maybe an open loop?
View Replies
View Related
Dec 8, 2014
I need to write a program where the user inputs name, age, email, and cell and write the user inputs to a text file. I need to have it so the file can be added to if more than one set of information is added. Currently, every time I click the button, the file is overwritten instead of added to. How do I correct this? Current code is as follows:
try
{
FileWriter writer = new FileWriter("ContactInformation.txt");
BufferedWriter bw = new BufferedWriter(writer);
nameTextField.write(bw);
bw.newLine();
ageTextField.write(bw);
bw.newLine();
emailTextField.write(bw);
bw.newLine();
cellTextField.write(bw);
bw.newLine();
bw.close();
nameTextField.setText("");
ageTextField.setText("");
emailTextField.setText("");
cellTextField.setText("");
nameTextField.requestFocus();
}
View Replies
View Related
May 8, 2015
whats the problem in my code : if i enter 2 movies are being displayed,it accepts only 1.
The code:
class theatrebooking {
public static void main(String args[])throws IOException {
Scanner in=new Scanner(System.in);
System.out.println("********************************************************************************************");
System.out.println();
System.out.println("System requires updation");
[Code] ....
View Replies
View Related
Feb 19, 2014
So basically I have to create a java program that accepts a string and does the following:
1.) Insert a blank space before capital letters
2.) Convert any capital letters into lower case except the first letter(if it is capital).
So if the user enters "HiMyNameIsJohn", the result should be "Hi my name is john". I am having problems inside my changeMe method. Everything works fine including putting a blank space in between upper case words. So from the previous example, my code would show "Hi My Name Is John". I am having issues making the code to convert the upper case letters into lower case. Im pretty sure the code should be right after the str.insert(i, " "). But I do not how to code it. Ive thought about Character.toUpperCase(ch); but doesnt work.
Java Code:
import java.util.*;
public class WordSeparator
{
public static void main(String[] args)
{
String word1, word2;
Scanner userInput = new Scanner(System.in);
[code]....
View Replies
View Related
Sep 25, 2014
1. Write a Java program that randomly generates a five-digit lottery number and prompts the user to enter a five-digit number. Each digit in the number is in the range between 0~9. The program should determine which prize the user wins according to the following rule:
- The user wins the first prize if the user input matches all five digits in the lottery number in exact order.
-The user wins the second prize if the user input matches any four digits in the lottery number in exact positions.
-The user wins the third prize if the user input matches any three digits in the lottery number in its exact position.
-The user wins the fourth prize if the user input matches any two digits in the lottery number in its exact position.
- The user wins the fifth prize if the user input matches any one digit in the lottery number in its exact position.here is my code. I have tried replacing the && statements with || and it always returns either case 1 or case default.
import java.util.Scanner;
import java.util.Random;
class Hw5 {
static int getPrize(int g1, int g2, int g3, int g4, int g5,
int u1, int u2, int u3, int u4, int u5) {
[code]...
View Replies
View Related
Sep 2, 2014
I'm using Jgrasp and my prompt is asking me to write a program where the program prompts the user to enter 4 grades between 0 and 100. And you have to display the grades, and the program has to calculate the minimum grade, the maximum grade and the average.I'm just having problems with the max?
// Import Java Scanner.
import java.util.Scanner;
// Name Class.
public class Practice_4_1
[code]...
View Replies
View Related
Mar 24, 2014
a. Assume that we have a list of employees' names of a company and their ages. Write a program that reads from the user several lines of input. Each line includes an employee's name and his/her age (as an integer). The program should calculate and print the following:
- The average age of all employees (rounded to 2 decimal places).
- The oldest employee and his/her age.
Hints:
You could assume that the user will insert valid data and at least one employee.
You could assume that the oldest employee is only one person.
User could stop the program via entering the word "end" as an employee's name.
Sample Input and Output: In each line, insert an employee's name and his/her age To halt the program, insert "end" as an employee's name
Adam 30
Tom 41
Ted 45
Karl 30
end
The average age of all employees is 36.50.The oldest employee is Hisham whose age is 45
View Replies
View Related
Feb 15, 2015
So i need to write a program that prompts the user for 3 double numbers x, y, z that outputs 2x^3 + 3y^5 + 3x^3y^2 +xyz with
(1) 4 digits precision
(2) with a ',' to separate thousands
(3) all digits of the result including the precision are put to 20 positions (from right to left)
I am not really sure what it is suppose to look like or how to start it.how to mix Math.pow with multivariable and printf.
View Replies
View Related
Mar 30, 2015
i am trying to write a program in which the user will select a text file(which contains information that the graphical output will be based). I have successfully set up my file chooser however when i select the text file,i do not get any graphical out put. please see attached .zip file for code.
View Replies
View Related
Feb 15, 2014
write a program to sort names according to number of vowels sort({sam,ratan,alok,raj}) the op is {sam,ratan,alok,raj}
View Replies
View Related
Apr 24, 2015
I am trying to write a Random Number Generator that will not contain any repeat value in a given range
something this I have try so far
import java.util.Random;
/**
* This class is used to generate a
* Range of Random Number in a range from int a to int b
*/
public class RandomNumberGenerator {
public static void main(String[] args) {
int[] arr=randomNummbers(1, 20);
for(int j=0;j<arr.length;j++){
[Code]...
although this code generate random numbers but some values are also getting duplicate.So how to write a program for random number that will not repeat any integer in range?
View Replies
View Related
Oct 7, 2014
This is titled "Creating static methods that accepts arguments and returns a value". I think that I understood everything about this except for the very bottom part of the code. I wasn't really sure where to put it. From the errors that I am seeing, I know which line is giving the errors but I'm not sure what is wrong with it.
import java.util.Scanner;
public class ParadiseInfo2{
public static void main(String[] args){
double price;
double discount;
[Code] ....
Errors:G:ParadiseInfo2.java:29: error: illegal start of expression
public static double computeDiscountInfo(double pr, double dscnt)
^
G:ParadiseInfo2.java:29: error: illegal start of expression
public static double computeDiscountInfo(double pr, double dscnt)
[Code] ....
6 errors
Tool completed with exit code 1
View Replies
View Related
May 21, 2015
I am trying to write a java program that asks the user for a list of names (one per line) until the user enters a blank line. At that point the program should print out the list of names entered, where each name is listed only once (i.e., uniquely) no matter how many times the user entered the name in the program. I am supposed to use an ArrayList for this problem.
My idea for a solution is to create an ArrayList<String>, read each name, i.e., line, entered and then to see if that name is already in the ArrayList. I created a for loop to check each element in the ArrayList but when I try to assign an element to a string variable I get the error "Type mismatch: cannot convert from Object to String". Not sure why that is happening because the ArrayList is defined as a String list.
Here is the code so far.
/*
* File: UniqueNames.java
*/
import acm.program.*;
import java.util.*;
[Code].....
View Replies
View Related