Program To Print In Decimal Format

Oct 24, 2014

so I need my program to print in decimal format and I keep getting an error saying that it cant find symbol "decimalFormat". here's what I have so far.

import java.util.Scanner;
public class GPACalculator {
public static void main(String[] args) {
int creditHours = 0;
int gradePoints = 0;

[Code] .....

View Replies


ADVERTISEMENT

Print Out GPA In Decimal Format

Oct 25, 2014

I need this program to print out the gpa down to 2 decimal places and I can't figure out how to do it. It keeps saying it can't find decimal format and I'm not sure how to define it.

Java Code:

import java.util.Scanner;
public class GPACalculator {
public static void main(String[] args) {
double creditHours = 0;
double gradePoints = 0;

[Code] ....

View Replies View Related

Program Cannot See DECIMAL FORMAT

May 12, 2015

I am using NetBeans IDE 8.0.2 to program Java code. I am a beginner in Java.

Instead of getting two decimal places after the point, I am getting three despite using the code format for two ("##.##"). Actually, this happens even if I remove the format code between the quotes. It is as if the program cannot see the format code. Why this happens ?

Here is the relevant program code:

private void convertButtonActionPerformed(java.awt.event.Action Event evt) {
double inputNumber = 0;
// sets the decimal format

[Code]....

View Replies View Related

How To Add Decimal Format Up To Two Places

Jul 25, 2014

import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Sample3 {
public static void main(String args[]){
double amount,iRate,monPay,totalPay;
int years;
String amountStr;

[Code] ....

View Replies View Related

Decimal Format Utility Of Java

Oct 13, 2014

I am working on a program where i calculate a fee using a method. I know i have to import the decimal format utility of java. "import java.text.DecimalFormat;" then i have to create an object for the decimal format. With "DecimalFormat f = new DecimalFormat("0.00");" What i am wondering how do i apply it to my system.out.println statement. I know i have to use for instance f.format(calculateFee()); Is that the right syntax for displaying the results because i generate a syntax error that way.

View Replies View Related

Decimal Format Errors - String Cannot Be Converted To Double

Jun 19, 2014

I am working on a project that just calculates simple interest based upon a principal and a percent interest rate written as .xxxx from user.

I need the Loan amount and the final interest calculation to show up as a currency with commas in appropriate areas, the Rate to be expressed as X.xxx% instead of .xxxx

I keep getting this error when I compile:

C:JavaInterestCalculator.java:46: error: incompatible types: String cannot be converted to double
principal = formatter.format(principal);
^
C:JavaInterestCalculator.java:49: error: incompatible types: String cannot be converted to double
rate = formatter.format(rate);
^
C:JavaInterestCalculator.java:52: error: incompatible types: String cannot be converted to double
totalInterest = formatter.format(totalInterest);
^
3 errors

Tool completed with exit code 1

And here is my code

import java.util.Scanner;
import java.text.NumberFormat;
import java.text.DecimalFormat;
// class declaration
public class InterestCalculator
{
// main method declaration

[Code] .....

View Replies View Related

How To Format Methods To Display Number With 1-2 Decimal Places

May 8, 2014

I am working with a program I wrote for class. I got it to compile and do what I want, But I was wondering how I can format my methods to to display a decimal with 1-2 decimal places. Would I create a method in my NumberAnalysis class to do it for me? Or would I declare an instance of the DecimalFormat class in my main method?

import java.util.Scanner; //Needed for Scanner Class
import java.io.*; //Need for File and IOException
import java.text.DecimalFormat;
public class Ex8_11 { 
public static void main(String[] args) throws IOException{
{
DecimalFormat decformatter = new DecimalFormat("#0.00");
 
[Code] .....

This is my output:

Lowest Number: 1.09
Highest Number: 82.76
Total Number: 367.89000000000004
Total Average Number: 30.657500000000002

Think I just solved the answer to my own question, I did it by declaring double variables in my main method and called the methods and instantiated the variables into the methods... Is there a better way to do this?

package lesson4.skowronek;
 import java.util.Scanner; //Needed for Scanner Class
import java.io.*; //Need for File and IOException
import java.text.DecimalFormat;
public class Ex8_11 {
public static void main(String[] args) throws IOException{
 
[Code] ....

View Replies View Related

Calculate Total Price At The End Of Order - Decimal Format

Apr 13, 2015

I have an assignment to create a JFrame pizzaorder and at the end of this order after the totalprice is calculated I need to format the number to ##.## but I keep getting a cannot find symbol error.

Source Code:

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
public class pizzaorder extends JFrame implements ItemListener, ListSelectionListener
//top section will have centered title telling the name, and under it seperate instructions to choose your pizza and toppings

[Code] ....

View Replies View Related

How To Print Double With 2 Decimal Numbers

May 3, 2014

I am trying to cast an integer into a double. it works but I need two decimal number after the dot and for example I can print 7.51 but how can I get it to print 7.50 and not 7.5

public int compareTo(Money o){
int d1 = (this.dollars * 100) + this.cents;
int d2 = (o.dollars * 100) + o.cents;
return d1 - d2;
}

On my main method I have

public static void main(String[] args){
Money money1 = new Money(10, 49);
Money money2 = new Money(2, 99);
System.out.println("result: " + "$" + (double)money1.compareTo(money2)/100);
}

It prints 7.5 but I want it to print 7.50, how do I do this .....

View Replies View Related

Print All Values In A Format Showing Their Key

Jun 14, 2014

Java Code:

public static void main(String[] args) {
HashMap<Integer, String> stuff = new HashMap<>();
stuff.put(1, "Book");
stuff.put(2, "Pancake");
stuff.put(3, "Waffle");

for(Map.Entry thing : stuff.entrySet())
System.out.println(thing.getKey() + ": " + thing.getValue());
} mh_sh_highlight_all('java');

So I make a HashMap which is pretty simple. My book showed me how I would print all the values in a format showing their key a ": " and the the actual value. What I don't understand is why the type element for the for each loop is the interface, Map.Entry.

View Replies View Related

Physical Print Out For Bill In Proper Format

Sep 23, 2014

I am trying to take physical print out for bill, But i am receiving some problems:

Java Code:

import java.awt.Color;
import java.awt.print.PrinterException;
import java.util.ArrayList;
import javax.print.attribute.AttributeSet;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
public class Printme {

[Code] .....

But My Output is

What i have to do / learn to get the proper bill format ....

View Replies View Related

Octal To Decimal Program

Oct 19, 2014

I'm trying to convert an octal number into a decimal number. I keep getting a big error that says java:63: error: class, interface, or enum expected. i need to use a public static int convert ( int octalNumber ) along with a public static void main ( String args[] ).

Here is my code. />

[public static void main ( String args[] )
{
int foo;
int valid = 0;
Scanner sc = new Scanner (System.in);
System.out.print ("Enter up to an 8-digit octal number and I'll convert it: "); foo = sc.nextInt();

[code].....

View Replies View Related

Program To Convert Binary To Decimal

Oct 13, 2014

I'm working on creating the Binary to Decimal program . hat is wrong with this part of my code. Why does it not take you into the loop.

import java.util.Scanner;
public class question5 {
public static void main(String[] args) {
System.out.println("Enter a Binary number. "); // collect
Scanner keyb = new Scanner(System.in); //

[Code] ....

View Replies View Related

Calculator Program - Using Decimal And Operators

Oct 20, 2014

How do I get the code to use decimals? Also whenever you input 1, 2 or 3 as one of the operators, it always does that operator as well as the 4th operator at the end. So it always does subtraction. However when you use 4 as the only operator it works perfect.

import java.util.Scanner;
public class Program05 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
 double left;
double right;
 
[Code] ......

View Replies View Related

Program To Change Base Of Integer Decimal

Nov 2, 2014

I know how to do this program it is just not coming to me. The whole point is to calculate and display the base (base-2 or binary, base-8 or octal and base-16 or hexadecimal) in representation of 'N'. The symbols A, B, C, D, E, F should display 10, 11, 12, 13, 14, and 15 in hexadecimal system.

import java.io.*;
import java.util.Scanner;
public class ChangeBase
{
public static void main(String[]args) {
double num;

[Code]...

View Replies View Related

Java Program - Distance Traveled (Formatting And Decimal Place)

Apr 10, 2014

I'm having trouble formatting my output and issues with the decimal places. Here's my code:

import java.util.Scanner;
import java.text.DecimalFormat; // Imports DecimalFormat class for one way to round
 public class lab3 {
public static void main(String[] args) {
String heading1 = "Hour", heading2 = "Distance Traveled";
int timeElapsed, hour, speed;

[Code] ....

And here's my output (Click on the image since it's pretty small):

javaIssues.png

Issue:
1) The Hours 2 and 3 aren't aligned to 1.
2) The 80 and 120 in Distance Traveled have 6 decimal places when it should not have decimals.

View Replies View Related

How To Write JAVA Program That Read Whole Number And Tell Decimal Place

Oct 10, 2014

Ex. If I type 5943, the program will say
mill = 5
hun = 9
ten = 4
uni = 3

get the picture I had to translate the decimal value names from a different language.

This is what I have tried...,

Java Code:

import java.util.Scanner;//Permite el uso de leer el teclado del usuario
public class DeterminarValorDecimal//Nombra el documento
{
public static void main(String [] args)//Podemos ver la clase
{

[Code].....

But what this does is I have to enter the single digits one by one. I want to be able to type the whole number. Is there a method that reads the length of the whole number and lets me classify each digit so I can do what I want to do?

View Replies View Related

Average Program - Number Format

May 5, 2015

I am writing a program using a given test drive... I am supposed to write two classes according to the test drive. The calculated correct answer should be 115.50 but i keep getting 115.52 instead and i just can't figure out what i'm doing wrong.

Here is the test drive code:

import java.text.NumberFormat;
public class FinalTester
{
public static void main(String[] args)
{
double avgPurchase;
Order[] lastYear = new Order[4];

[Code] ....

View Replies View Related

Program To Convert Utf-8 To Cp1251 Format

Apr 11, 2014

I am trying to covert utf-8 encoding into CP1251 encoding. But i am getting null pointer exception.
 
package ProcessDefinition;
import java.util.*;
import java.io.*;
import java.lang.String;
public class Process

[Code] .....

View Replies View Related

Passcode Program - Enter Password In Exact Format

Apr 14, 2014

I simply need to write a program that asks a user to input a password. It has to be in this format: DDD-LL-DDDD. The D's mean Digit and the L's stands for Letter. The User has to enter the Hyphens.

If the password isn't entered in that exact format the program should read out a error. If the hyphens aren't entered the program should read out a error. If there are too many characters entered, there should be a error.

import java.util.Scanner;
public class security {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter Security Code: ");
System.out.println("Use the format: DDD-LL-DDDD and include dashes");
String code = input.next();
char c;

[Code] ....

I'm trying to figure how how to get the code to check if the values entered are in the correct place. I'm also not sure how to make the program check for hyphens. I feel like I'm close though. I can easily add the correct error and valid messages later if I could just figure out this part.

View Replies View Related

Not Getting Decimal For Surely Decimal Answer?

Jan 1, 2015

I'm using eclipse. I'm going to get straight to the point and give all the info I can, if the values in the first code box are used, shouldn't these values be left after all in the second box is done:

remainder=23, arr[0]=100, div=23/10=2.3, whole=2, and decimal=3?

When I use this code, div comes out to be just (2.0).

Java Code:

int leng=10;
arr[0]=123; //int
arr[1]=100; //int mh_sh_highlight_all('java'); Java Code: if (arr[0]!=arr[1]){
int remainder=arr[0]-arr[1];
arr[0]=arr[0]-remainder;
double div=remainder/leng; //double div=Double.valueOf(remainder/leng);
int whole=(int) Math.floor(div);
int decimal=(int) ((div-whole)*leng); mh_sh_highlight_all('java');

I'm not sure were I'm going wrong in how div is being calculated, but I ultimately need div to be 2.3.

I've also used the second option commented out which still gives (2.0).

View Replies View Related

Round Decimal Number Into 2 Decimal

Apr 2, 2014

Here is my code and i want to convert number into 2 decimal but this code not give me result how to check my code.

import javax.swing.JOptionPane;
public class showtime{
public static void main(String[] args){
double total_mili=System.currentTimeMillis();
JOptionPane.showMessageDialog(null,total_mili, "Total milisecond",JOptionPane.INFORMATION_MESSAGE);
double seconds=total_mili/60;
double sec=(double)(seconds * 100) / 100.000;
JOptionPane.showMessageDialog(null,seconds, "Total Second",JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,sec, "Total Second",JOptionPane.ERROR_MESSAGE);
}
}

View Replies View Related

Program Does Not Print The List?

Aug 22, 2014

the program does not print the list when i select choice 3 it only prints the original 2 elements, same happens if i use if else statements instead of switch statement. Quote public class linklistdemo{

public static void main(String args[]){
while(true) {
System.out.println("press one enter element");

[Code]....

View Replies View Related

Writing A Java Program To PRINT?

Oct 19, 2014

how to print from bluej onto actual paper? how to do the formatting and configuration etc.

View Replies View Related

Can't Get GUI Program To Print Out Queue List

Apr 11, 2014

I have been working on this Java Gui program and i cant get it to print to the textbox correctly.i originally had it displayed in a dialog window but it would print one integer a time in a seperate window.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.lang.*;
import java.io.*;

[code]....

View Replies View Related

Program Prints 2 Values When It Should Only Print 1

Feb 4, 2015

When I run this code, it is supposed to get one value from turnTimer(); and return it, just as a test. This works when I enter a valid pit. For example. If I were to input "A" when it's player one's turn, it will return 1, like it should. However, if I were to type "H" when it's player one's turn, it returns "Not a valid pit!"(like it should) but then it also returns 12. It shouldn't know that H is 12 because it's in a separate method. I'm confused as to why it's printing both values.

import java.util.*;
public class Mancala
{
static Scanner input = new Scanner(System.in);
public static int pit;
public static void main(String[]args)
{
Mancala mancala = new Mancala();
int[] board = {0,3,3,3,3,3,3,0,3,3,3,3,3,3};

[code]....

View Replies View Related







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