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;
package FracCalc; import java.util.Scanner; public class FracCalc { public static void main(String[] args) { Scanner scan = new Scanner(System.in);
int n1 = 0; //n1 = first numerator user have to enter int d1 = 0; //d1 = first denominator user have to enter int n2 = 0; //n2 = second numerator user have to enter int d2 = 0; //d2 = second denominator user have to enter int numeratorAnswer = 0; //calculates numerator of an equation int denominatorAnswer = 0; //calculates denominator of an equation
[code]...
I mean its not that important but i figure it will be better if I could print out the answer both in fraction format and decimal format. while my answer prints in fraction just fine how do i show it in decimal?
System.out.println("");
System.out.print("And "); System.out.print("answer in Decimal is: ");
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
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();
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;
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); //
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;
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.
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?
how to I modify my program so that it asks the user how many studens are in the class then according to the value the user inputs that is how many times the program will ask the user for a grade. Once the graded are entered it will then output the class average, minimum, and maximum. I believe that you'd use a for loop yet I am troubled.
import java.util.Scanner; public class GetLetterGrade{ public static void main(String [] args){ Scanner reader = new Scanner(System.in);
i have a similar problem but what i need to do is to detect an exused absent of which in my notepad is represented by 00 and 0 being an unexcused absent, anyway if a student has an excused absent example a quiz for that day will be deducted from the total quizzes example if i was the teacher and had 2 quizzes of 10 items each and she was absent in one of the quizes instead of let say her score was 9 on the first quiz it should go 9/10 and if it was an unexcused absent 9+0/20 anyway this is my java code and notepad example
import java.io.*; import java.util.*; import java.lang.*; public class GradingSystem { public static void main (String[] args) throws FileNotFoundException
I am making a programme for a calculator to - Divide, multiply, add and subtract. I have the code written but when I am running it and trying to add it was for some subtracting ....
import javax.swing.JOptionPane; public class calculator3 { public static void main(String[] args){ String number1,number2,operatorstring; double result=0,a,b;
My assignment is to essentially update a calculator program that uses strings, and methods, to include arrays. How to create and call an array that the user defines the size of and then inputs the numbers to fill the array. Here's the example my prof gave us of what the output should look like:
Menu 1. Add 2. Subtract 3. Multiply 4. Divide 5. Dot product 6. Generate random array 7. Quit
What would you like to do? 1
How many values are in the arrays? 3
Enter the values in the first array, separated by spaces: 2 4 6
Enter the values in the second array, separated by spaces: 1 3 5
The result is [3.0, 7.0, 11.0]
How to create an array that would allow the user to define the size of the array and then inputs the values for the array? I'm completely lost. I never should have taken java as an online class.
I'm writing a command line application of a calculator in Java. I need to be able to (as per program requirements) split the array of strings (6+3) into an array of strings? How would that be done? I know you can use the split method, but I am not really sure how that wold work to perform math with them?
On a side note: for this application, how could you make the program accept a variety of different lengths of strings to perform math with them?
I am required to make a console calculator that takes the values as strings and turns them into doubles. The user needs to be able to enter something like 3+4+5*9/13 on one line and the application give the answer. As of this point I am currently on at the last section as making the user be able to enter the expression and present the answer. I have added an array list containing + - / * and the same with the numbers 1-9...I now need to actually get the information to all come together. I'm not sure how to do that. I *think* I have all the parts for it to work.
public static void main(String[] args) { String input = ""; // initalize the string boolean isOn = true; // used for the while loop...when false, the // program will exit. final String exitCommand = "Exit"; // exit command
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).
I've created a truth table for logical operators. Now I'm supposed to alter the code so the table prints 1's and 0's instead of true or false. Here's a bit of the original code - just the header and the first line of the table.
System.out.println("p q AND OR XOR NOT"); System.out.println(); boolean p, q; p = true; q = true; System.out.print( p + " " + q + " " ); System.out.print( ( p & q) + " " + ( p | q) + " "); System.out.println(( p ^ q ) + " " + ( !p) );
All of my ideas involve using an if-then statement, but that would be all kinds of inefficient and unwieldy, I think.
if (number % 2 == 0 && number % 3 == 0) System.out.println(number + " is divisible by 2 and 3");
if (number % 2 == 0 || number % 3 == 0) System.out.println(number+ " is divisible by 2 or 3");
if (number % 2 == 0 ^ number % 3 == 0) System.out.println(number + " is divisble by 2 or 3 but not both");
I understand the logic operators and the variable number, what i dont understand is what number % 2 == 0 and number % number == 0 mean. I know that % is a remaining operator and == means equals, i know that = and == are not the same.
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;
So my little math game is working so far. I can only do addition though. I know how to fix it if I can find out how to generate random math operators. After that I want to use a loop (or a better technique) to ask ten different math questions before the game is over.
package pkgnew; import java.util.Scanner; import java.util.Random; public class New { public static void main(String args[]) { //Declare and construct variables Random randomnum = new Random();
I was told to create a class named Billing that includes three overloaded computeBill methods for a photobook store.
The first method takes the price of the book ordered, adds 8% tax and returns the total due. The second method takes the price of the book, and the quantity, adds tax and returns the total. The final method takes the price, quantity and a coupon discount, adds tax and returns the total.
All of this I have managed fairly well, although I keep getting a strange error at the end of my program that the constructor is undefined. The problem bits of code(the one throwing the errors) are under the comment //Enter values into each of the methods
Code:
package org.CIS406.lab2;
public class Billing { //Declarations double bookPrice; int quantityOrdered; double couponValue;
[Code] ....
My first thought was to create a constructor for each of the methods that I am using...
I'm building an application in Netbeans and so far I'm making good progress with it. I have created an animated splash screen in myspacegen.com and then downloaded it as a GUI file. I've then imported it into my application in Netbeans but I was restricted in myspacegens.com to the size of the image I could create. I want to know if it is possible to add code to the splash screen project within Netbeans so that it automatically adjusts to fill the screen. I have used the java commands get width and get height elsewhere in my application so that the window I create in a project automatically adjusts to fill the operator's screen but that has a 'window' to adjust and I do not want my splash screen to have a visible window.