Set And Assign Doubles - String For Gross Pay?

Dec 15, 2014

I'm working with doubles I'm trying to figure out how to set this up so it works?

I'm just stuck on how to set and Assign a double FedTaxWitholding that gets the Fed Tax Withholding = Gross Pay * Fed
Tax Withholding Rate.

Do I need a string for Gross pay?

View Replies


ADVERTISEMENT

Value Assign To A String

Sep 25, 2014

I am doing an assignment where I have to find the price per square inch of a pizza, compare them and display the results. I have everything figured out with the values and stuff. Now when I have to displays the results I have to display which of the two pizzas is more favorable.

I have both values / square inch for both. and I know how to find the minimum value of the two wit the Math.min class.
My question is how can I assign the char, PIZZA A to the value that I had so I can display it in the output statement, without writing PIZZA A. It should display after the difference is calculated.

Here's my code so far.

// This programs finds the price per square inch of a pizza

import java.util.Scanner;
import java.text.DecimalFormat;
public class PizzaSquareInches {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.###");

[Code] .....

View Replies View Related

Getting Error When Assign Word To A String?

Jan 29, 2014

Below is my first ever code. I bolded where i am getting a syntax error. Why am i getting an error here if i assigned that word to a string?

public class BeerBottleTest {
public static void main(String[] args) {
int beerNum = 99;
String bottle = "bottles";
while (beerNum > 0) {
if (beerNum == 1) {
bottle = "bottle"; }

[Code] ....

View Replies View Related

Assign A Value To Numeric Variable Then Manipulate It And Return A New String

Aug 18, 2014

At first I wanted to just use an array and set each day a value, however I was told that it has to be stored as a string.

Design and implement the class Day that implements the day of the week in a program. The class Day should store the day, such as Sun for Sunday. The program should be able to perform the following operations on an object of type Day:

A. Set the day.
B. Print the day.
C. Return the day.
D. Return the next day.
E. Return the previous day.
F. Calculate and return the day by adding certain days to the current day. For example, if the current day is Monday and we add four days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.
G. Add the appropriate constructors.
H. Write the definitions of the methods to implement the operations for the class Day, as defined in A through G.
I. Write a program to test various operations on the class Day.

import java.util.*;
public class Day {
static Scanner readinput = new Scanner(System.in);
String day;
public Day(String day) {

[Code] ....

So right now if I run my code it allows me to type in a day, then it gives me the next and previous day, the last part is to add X days to it. Ideally I would like to be able to take the day entered, depending on the day set a numeric value, then add prompt for number of days you want to add. The program should then use modal (%7 ) to add value to the value that was given based on the day, and then translate it back into a String value (the day).

View Replies View Related

Gross Pay Using Array

May 4, 2014

This is my program

import java.util.Scanner;
public class grossPay {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("The Acme Company pays all their employees the same ratee");
Scanner input = new Scanner(System.in);

[Code]....

I know for sure that line 32 is wrong but I don't know why. There is a red line under the brackets.

View Replies View Related

Payroll Class - Displaying Gross Pay?

Jan 25, 2015

I am having trouble with this displaying the grosspay. Why it is not displaying it right. All I am getting is 0.00 all the time, everything else seems to work great.

// This program shows the payroll coding challenge

public class PayRoll
{
// Constant for the number of employees
public final int NUM_EMPLOYEES = 7;
private double[] employeeID = {5658845, 4520124, 7895122,
8777541, 8451277, 1302850,
7580489};
// To hold hours worked
private int[] hours = new int[NUM_EMPLOYEES];

[Code] ....

View Replies View Related

Cannot Assign Cloned String Array To Generic Type Array

Jun 21, 2014

I have the following code in which I am looping through the rows of one array (composed of Strings) and copying it to another array. I am using .clone() to achieve this and it seems work as it changes the memory location of the rows themselves. I did notice that the String objects are still pointing to the same location in memory in both arrays but I won't worry about that for now, at the moment I just want to understand why the array I am cloning is not successfully assigning to the other array.

This is the incorrect line: ar[r] = maze[r].clone();

My code:

private String[][] maze = {{"*","*","*"," ","*","*","*","*","*","*"},
{"*"," ", "*"," "," "," ","*"," ","*","*"},
{"*"," ","*","*","*"," ","*"," ","*","*"},
{"*"," "," "," "," "," "," "," "," ","*"},
{"*","*","*","*","*"," ","*","*","*","*"},
{"*","*","*","*","*"," ","*","*","*","*"}};
//private String[][] mazeCopy = copyMaze(new String[6][10]);
private <T> T[][] copyMaze(T[][] ar){
for (int r = 0; r < ar.length; r++){
ar[r] = maze[r].clone();
}
return ar;
}

My compiler says: Required: T[]. Found: java.lang.String[]

Since ar[r] is an array and .clone() also returns an array why is this line incorrect.

View Replies View Related

Add Doubles In Array

Jan 20, 2014

I'm allowing the user to choose certain items to buy that is moved to an array.Now I'm trying to add those thing in the array use a different class. how I can call the array from my driver class to my checkout class that adds them together.

View Replies View Related

Scanner Isn't Accepting Doubles

Jan 25, 2014

I had to use scanner to receive input from the user for a formula and everything compiled and worked correctly except when I entered a double into the Scanner, it only accepts ints and gives me this error every time I enter a double:

java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextDouble(Unknown Source)
at TestA1Q2.main(TestA1Q2.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)

I know that you usually get that error when the Scanner expects something else that is different from what you type and I have looked over my code time and time again and cannot find anything. I created a test program to see if it was just that problem and not something else in the code and I still got the same error but when I tried compiling and running it here browxy.com everything worked and I got the right answer for the formula. Here's the test I used:

import java.util.Scanner;
public class TestA1Q2 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a double");
double velocity = keyboard.nextDouble();
}
}

At this point I'm thinking it might be a problem with my install of DrJava and I've tried re-installing but nothing changed.

View Replies View Related

How To Add Doubles From A Text File

Apr 13, 2014

I have a text file that looks like this:

JacobAndrews8159RoseCtMill CityOR97322555212787964.00
RyanPerkins7546PrinceAveLas VegasNV87126555345198913.00
JoshuaGilbert9278MonroeDrCorvallisCA97330555283265695.00
MilesCrain4578ChesterDrCorvallisOR9733155523456781544.00
ButchCassidy5498SuttonPlGresham AZ9738054165657971798.56
PerryWinkle8185ShaverAveLas VegasNV871265553812346195.66

everything is separated by tabs.

My while loop is like this:

while(fileScan.hasNextLine()) {
String currentLine = fileScan.nextLine();
String[]dataSet = currentLine.split(" ");
String zip = dataSet[7];
String phone = dataSet[8];
String donation = dataSet[9];
int ZIP = Integer.parseInt(zip);
Double Donation = Double.parseDouble(donation);

As you can see I made the donation read as a double, my question is how do I get the donation total? I need to write the code to add up and get the total donations but cannot figure it out.

View Replies View Related

How To Work With Doubles In Arrays

Sep 13, 2014

import java.util.*;
public class OneDimenArray {
public static void main(String[] args) {
double[] decimals = new double[12];
double nums = 0.0;
double a = 1.0;
[Code] ....

These are the erroe codes I'm getting;

OneDimenArray.java:13: error: ']' expected
double[] decimals = double[Scanner.nextDouble()];
^
OneDimenArray.java:13: error: ';' expected
double[] decimals = double[Scanner.nextDouble()];
^
2 errors

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

View Replies View Related

Floats / Doubles And Currency

Mar 8, 2014

Just done a quick test to try and figure out the difference between floats and doubles.I made a quick program which outputs the result of 3.3 * 2 as both a float and a double.

I assumed since a float is the larger and more precise of the two data types that there would be more numbers after the decimal point, however this was not the case, it was in fact the double which had more numbers after the decimal point. Result was as follows:

Float: 29.699999
Double: 29.7

BTW for the above code I simply had a few text fields and a button with the following code:

Java Code:

textBox3.setText("" + Float.parseFloat(textBox1.getText()) * Float.parseFloat(textBox2.getText()));
textBox6.setText("" + Double.parseDouble(textBox1.getText()) * Double.parseDouble(textBox2.getText())); mh_sh_highlight_all('java');

Also, as these are limited to a certain amount of numbers im thinking there must be a more precise way for currency, if so what would I use for that? I suppose what im trying to figure out is what data type to use in different scenarios? When to use integer, float, double and long.

View Replies View Related

Java Program Using If / Else - Multiple Doubles

Oct 14, 2014

I am new to Java and I am having trouble figuring out why input.nextDouble(); is not working for the multiple doubles.

import java.util.Scanner;
public class SimpleMenu
{
public static void main(String [] args)
{
int userInput;
int input = 0;
double circleArea = 0;
double triangleArea = 0;
double rectangleArea = 0;

[Code] ....

View Replies View Related

Method That Returns Largest Value Of Array Of Doubles?

Jan 26, 2015

Write a Java method that returns the largest value of an array of doubles passed to the method as an argument.

Back into java wasn't sure how to do it for doubles did one in the main for integers and then added a method changed from int to double and now i'm lost as go why its not working.

package kickstarter9;
public class Kickstarter9 {
public static void main(String[] args){
double myList;
double[] myList = {6.0, 4.1, 2.4, 6.8, 1.9, 9.4, 2.8, 4.6, 9.3};
// find the largest value in the list

[Code]...

View Replies View Related

Infix To Prefix - Pow Only Takes Int Values Not Doubles

Feb 7, 2014

I am having a problem with infix and prefix ... Here is the code

import java.util.StringTokenizer;
import static java.lang.Math.pow;
import java.util.Stack;
 public class Calculator {
static int precedence(char op) {
switch(op) {

[Code] ....

it says in line 72
possible loss of precision
required: int
found: double
the pow only takes int values?not doubles?how do i fix it?

View Replies View Related

Return Smallest Of 10 Doubles (User Input)

Oct 1, 2014

This code will let a user type 10 double's, and return the smallest of those 10 double's. But I don't really understand what happens in de last for-loop.

package hsleiden.webcat.exercise06_09;
import java.util.Scanner;
public class Exercise06_09
{
public static void main (String[] args){
double[] allNumbers = new double [10];
 
[Code] ....

View Replies View Related

Swing/AWT/SWT :: Using Doubles For Positioning Objects And Testing Equality

Aug 15, 2014

I've been noticing some of my programs have been a little buggy recently, and think it's down to confusion over doubles and positioning. Lets say I have a label called banner that I want to scroll across the screen. Now I need to know the label's width in order to position it, but the width depends on the amount of text, so i use this code:

double bannerWidth = banner.getWidth();

Which forces me into using a double if I want to be accurate.

But the problem is that I'm trying to use a condition that compares the label's horizontal position (currentX) to the left edge of the screen (LEFT_EDGE), minus the width of the label (bannerWidth). In other words when the label is off the screen, it should go back to its starting position.

I assume that means that any variables I use to track the label's position (in this case currentX), or constants that I use to check equality (LEFT_EDGE), have to be doubles as well?

My difficulty is that I iterate currentX. But currentX--; won't work because doubles don't iterate as I'd expect.

So casting becomes an option..... but if I cast to an integer I effectively lose width on the label. And that is magnified each loop, resulting in the label's starting position moving further and further to the left.

View Replies View Related

Arithmetic Expression That Will Display Doubles To Only One Decimal Place?

Sep 29, 2014

I am looking to find a way to display the number of decimal places without using any type of formatting string.

Only to make it xxx.x instead of xxx.xxxxxx.

View Replies View Related

Formatting Doubles To Two Decimal Places Within Return Statement

Jan 25, 2015

I'm attempting to format my doubles to two decimal places within my return statement. I have tried to use DecimalFormat but it gives me an error because my method needs to return a double and that results in a string being returned. I have also tried using the *100.00/100.00 method and that doesn't work when the number already ends in 0.

If I pass -150.00 it gives me -150.0 when I need two decimal places.

How can I go about doing this?

View Replies View Related

Program To Store Total Rainfall For Each Of 12 Months Into Array Of Doubles

Oct 26, 2014

"Create a project called RainFall and a class nameD RainFall. Write a program that stores the total rainfall for each of 12 months into an array of doubles. The program should display total rainfall for the year, the average monthly rainfall, the month with the most rain and the month with the least rain. When outputting the month with the most and least rain, output the name of the month. This is what I have so far.

Scanner keyboard = new Scanner(System.in);
double averageMonthly;
double mostRain;
double leastRain;
int months;
double monthlyRain = 0;
double totalRain = 0;

[Code] ....

View Replies View Related

How To Assign Values To Object

Apr 25, 2015

simple assignment of values to a previously initialized object?

See the method useModel ()

The idea is, assign the values to the temporary object, data

Then plunk it into this statement:

model.addRow ( data );

Simple enough?

I've been putzing with the syntax for multiple hours, over days, now.

With and without

[0];,

Netbeans keeps giving me: Illegal start of expression data is declared as an array of Object, although, in this case, it does not need to be an array. What is the correct syntax?

Java Code: //--
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Date;
import javax.swing.JFrame;

[Code]....

View Replies View Related

Assign Values To ArrayList?

Apr 27, 2015

This code currently just prints out the memory for the objects. What I am doing that it obviously wrong?

import java.util.ArrayList;
import java.util.List;
public class deck extends Card {
public final String[] SUITS = { "Heart", "Diamond", "Clubs", "Spade" };
ArrayList<Card> deck = new ArrayList<Card>();

[Code] .....

View Replies View Related

How To Assign Value To Next Object In Other Class

Jul 12, 2014

I've been referencing my text and a few other sites to assist in building this class...and I'm still uncertain of the purpose of a few of the methds: next(), hasNext().

Also, I have not found a clear explanation of the following code example: tail.next = tail; There are several instances of this in the code below....I'm just not sure exactly how this assigns the value to the next object in the other class..?? ??

public class MySinglyLinkedList<T> implements SinglyLinkedList<T>{
protected NodeList<T> head, tail, current, newNode;
String name;
int size = 0;
public MySinglyLinkedList(){
head = null;
tail = null;

[Code]...

View Replies View Related

Assign Float Value To Int Variable

Feb 24, 2015

//Output is:ERROR.. one of the books says, we can assign float value to int variable, but its giving error.

class floint
{
public static void main(String arg[])
{
int i;
float j=10.12f;
i=j;
System.out.println(i);
}
}

View Replies View Related

Can Assign Multiple Values To One Variable

Apr 25, 2014

Can I assign multiple values to one variable? For example I want myNum = 0 thru 9 you see im trying to program a password checker program to verify that the password meets all the criteria 8 char long, 1 upper case, 1 lower case, 1 numeric, 1 special, and don't contain and or end

View Replies View Related

Input Won't Assign Temp The Correct Value

Feb 3, 2015

I'm focusing on the player1Turn() method. When I run this and say temp = A, it says pit = 0. I don't know why this is.

import java.util.*;
public class Mancala {
Scanner input = new Scanner(System.in);
public static void main(String[]args) {

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved