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


ADVERTISEMENT

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 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

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

How To Make Print Employee Button To Print Info Of Other Class

Apr 12, 2014

Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.

The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.

company class:

import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;

[Code] ....

error message when print button is clicked:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)

[Code] ......

View Replies View Related

Two Threads - One Will Print Odd And Other Will Print Even Numbers In Sequence

Jul 25, 2014

I want to create two thread one thread will print odd number and another thread will print even number. but the number should be in a sequence like

1 2 3 4 5 6 7 8 9 10

View Replies View Related

Decimal To Hex - Not Getting Value 0 When Input Is 0

Mar 4, 2014

Why do i not get a value 0 when my input is 0.

import java.util.Scanner;
public class Dec2Hex {
public static void main(String[] args){
int dec;
String hexStr = "";
int radix = 16;

[Code] .....

View Replies View Related

Add A Zero For Decimal Part

Apr 19, 2015

Add the following method to the BankAccount class: public String toString()Your method should return a string that contains the account's name and balance separated by a comma and space. For example, if an account object named benben has the name "Benson" and a balance of 17.25, the call of benben.toString() should return:

Benson, $17.25

There are some special cases you should handle. If the balance is negative, put the - sign before the dollar sign. Also, always display the cents as a two-digit number. For example, if the same object had a balance of -17.5, your method should return:

Benson, -$17.50

Here is my code:

public String toString() {
String result = name + ", ";
if (balance < 0) {
result += "-";
}
return result += "$" + Math.abs(balance);
}

My code only works in case there are full two numbers for the cents part, not for the case when there's only one number. So I wonder how I can add an extra zero when needed.I can get only the decimal part and add a zero if it's less than 10, but I don't know how I can extract just the decimal part from the number. (The balance is just a double and it doesn't have any separate field for dollars and cents).

View Replies View Related

Binary To Decimal Using Array

Jan 28, 2015

I do not know how to convert a reversed array to decimal.

The output should be:

How many digits to convert?
(user will input) ex. 3
Please input digits:
(user will input 3 digits)
ex. 0
1
1
The binary digits are: 110 (<-reversed)
The decimal value is: 6

Here is my code:

package numbersystemconversion;
import java.util.Scanner;
public class BinarytoDecimal {
static {
int digit=0;
Scanner input = new Scanner(System.in);

[Code] ....

View Replies View Related

Numbers After Decimal Won't Add Together For Total

Sep 26, 2014

The code is below and the problem I am having is the numbers after the decimal won't add together for the total I am teaching myself java through liang's 10th edition book and I took one of the sample programs further than what was shown. The one in the book only shows the tax amount I simply wanted to make it so that the purchase amount and the tax amount would add together

package javalearning;
import java.util.Scanner;
public class FindingTax {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter Purchase amount: ");

[code]....

View Replies View Related

Display Decimal Numbers Only

Jul 6, 2014

What code to use to display decimal numbers only. for example 125.50. the program will only display .50

View Replies View Related

Converting Octal To Decimal

Sep 26, 2014

I'm trying to complete a code to convert decimal to octal. however i can't figure out how to print the output correctly. it should be.. Your integer number 160000 is 0470400 in octal. (160000 is the number you input). My code is...

Scanner input = new Scanner(System.in);

int value;
int a;
int b;
int c;
int d;
int e;
int f;
int g;
String result;

[Code] .....

Lastly, my output prints everything correctly, but the input number always is 0.

Ex error: input= 160000

Your integer number 0 is 0470400 in octal.

it should be.. Your integer number 160000 is 0470400 in octal.

View Replies View Related

Decimal Point On Jtextfield

Apr 26, 2014

designing a program which allows you to buy stuff from the jframe with 10x items each with different pricing, so once you click the image button the cost of that is displayed in the textfield, ive been trying to set the jtextfield to a decimal point but have not been able to so far,

if (source == jBSofa) {
System.out.println("Sofa");
{
dTotal = dTotal + 599.99;

jTotal.setText(Double.toString(dTotal));
DecimalFormat myFormatter = new DecimalFormat("#####.#");
String output = myFormatter.format(dTotal);
a visual aspect of it.

View Replies View Related

Convert Binary To Decimal Such As Bin

Sep 20, 2014

I am having an issue with my program. It is supposed to convert from a binary number to a decimal number such as bin 101 = dec 5. my first and foremost issue is that when I use System.out.println(parseBin("101")); it returns 5 as it should. However when I change 101 to 1013 it returns 13??? Why is this happening and why are my exceptions not catching the issue?

//import java.util.Scanner;
public class BinaryFormatException {
public static void main(String[] args) throws BinFormatException{
System.out.println(parseBin("1013"));
//Scanner input = new Scanner(System.in);
//System.out.println("Please enter a binary number using 1's and 0's: ");
//String binString = input.nextLine();

[Code] ....

View Replies View Related

Decimal To Binary - Not Getting Any Input

Dec 13, 2014

import java.io.*;
class Binary_Displaying
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int d,r,bi=0,i=0,dup;

[Code] ....

I am not getting any output.........

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

Decimal Values - JOptionPane

Jul 1, 2014

I am a beginner in Java and I am currently learning about JOption pane.Using Strings I am accepting an input from the user and by using the Interer.ParseInt(variable) option I am able to multiply this two strings using the code below.

String Length;
Length = JOptionPane.showInputDialog("Enter the Length");
String Breadth;
Breadth = JOptionPane.showInputDialog("Enter the Breadth");
System.out.println(" Area is " + (Integer.parseInt(Breadth) * Integer.parseInt(Length)));
System.exit(0);

How Do I make my code accept Decimal values. E.g. My Code should accept 10.02 as Length and 20.42 as Breadth and give the product a Decimal.

View Replies View Related







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