I have tried as much as I can to place code to give me only two decimals in answers but cannot get it to work not sure if placement or syntax.This is code so far and it works but gives answers to 8 decimals.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
My program is supposed to operate on decimals because it concerns volume of packagings. I learnt that what normally is simple arithmetic (100 cm × 75 cm × 60 cm = 0.45 m³) in Java gives only approximate value (something like 0.44(9) m³ in this case). That's close enough so I probably shouldn't worry, but the thing is that although for one packaging the difference is barely visible—if at all—for thousands of packagings it'll make a difference. It'll be worse when I get to counting money.
I found two solutions: 1) Using integers and so-called decorative decimal point on display. I have a bad feeling about this, though. 2) Using BigDecimal.
Now, BigDecimal seems like a nice solution. I tried it and so far it looks okay. But just look at an excerpt from my program that I had to re-write (previously it looked perfectly fine as a single line):
I have made a program that is supposed to convert roman numerals to decimals. It is NOT supposed to convert decimals to roman numerals. The only problem it seems there is with the program is that it only adds and does NOT subtract. This causes some roman numeral conversions to be flawed. What can I try to fix this. Keep in mind that the reason some methods exist is because the directions for the code say that I have to make it this way.
Instructions:
Write a program that converts a number entered in Roman numerals to decimal. Your program should consist of a class called Roman. An object of type Roman should be able to do the following:
1) Store the number as a Roman numeral. 2) Convert and store the number into decimal. 3) Print the number as a Roman numeral or decimal number as requested by the user. (Be sure to over-ride the toString function). 4) Your class must contain the method romanToDecimal to convert a Roman numeral into its equivalent decimal number. 5) Test your program using the following Roman numerals: MCXIV, CCCLIX, and MDCLXVI.
This is what I have so far. It compiles and there are no errors, but it does not subtract I from X, or I from V and so on. For example,CMXLVII should be 947, but the program outputs 1067.
import javax.swing.*; import java.util.*; public class Roman{ private String roman; private int decimal; public int romanToDecimal(String s)
I need all of that to be combined into a single String.format and include the / and unicode symbols for degree fahrenheit. How String.format works so that I can figure out how to achieve that? I've tried a few websites but none of them explain it to the extent that I need to use it.
I'm currently working on a loan calculator... The only problem I'm having is occasional values that have very long decimals... How do I round the decimals?
I am making a small program that converts meters to feet. I want my answer to be printed with 2 decimals, but I am struggle. This is my current code, any takes on what needs to be changed and why?
import java.util.Scanner; import java.text.DecimalFormat; public class Chapter2PE3 { public static void main (String[]args){ Scanner input = new Scanner (System.in);
class A { List<StringBuilder> list; public void output(List<StringBuilder> objectToOutput){ try(BufferedWriter bw = new BufferedWriter(new FileWriter("temp.txt"))){ for(StringBuilder row:objectToOutput) bw.write(row.toString()); }catch(IOException e){}
[code]....
Why don't the a's show up on the console? I put them in as part of the debugging process and now I don't understand why they don't show up in both places.
If I for example choose 8 as "multiplikationstabell" and 4 as "faktor" the whole code works except that "svar" gets printed as 8 in every turn. Why? "Faktor" gets added with 1 every time but "svar" stays at 8.......
import java.util.Scanner; public class Multiplikationstabell { public static void main(String args[]){ Scanner Heltal = new Scanner(System.in);
I am new to programing and I am making a dice game where I have to roll two dice and add the total together for each dice (2, 3, 4 ect.) I have all the program finished except one thing.
How would I use the * character that shows the total percentage each number was rolled. Each * will represent 1% of the total rolls. Instead of saying there were ( 4 ) 2's rolled i have to put ( **** ) 2's rolled.
I am creating a body mass index calculator and i was wondering how i could make its so that the program resets itself once the BMI has been found....
My code is below...
package bmiCalculatorSource; import java.util.Scanner; public class BMICalculator { public static void main(String[] args) { final double KilogramsPerPound = 0.453; final double MetersPerInch = 0.026;
I would like to put the answer of JCheckBox inside of a JTextArea. How to call the answer of JCheckBox if its check the response should be Yes if its unchecked the response should be No, and the yes/no answer should be appear inside JTextArea. But my problem is inside the JTextArea the answer from a JTextField and JComboBox is also there, and they should be appear in a parallel. I attached the physical appearance of the GUI.
I want to design an open-answer quiz game using Java. Basically, the plan is to design a quiz where the name of a medicine is displayed as "the question" and the player will need to input the unique code (as "the answer") of the medicine in an open box (all the codes are two characters). The list has about 204 named medicine (with potentially more to be included at a later stage). The questions will not appear in the same order for each session restarted; they will appear randomly.
The player will have 60 seconds, and for each correct answer, will score 1 point and add 2 seconds to the timer. The player will also have 6 "lives", and for each incorrect answer, the player will lose a life, with no effect on the time.
The idea of the game is that the player memorise as many of these medicine codes as possible.
I am writing a simple learning program that does basic math. Everything is working as needed except for when it comes to division. I need to know if there is a way to format the users input to two decimal places and that when the program checks the users answer against the division, it gives it a yay or nay. Right now, it wants the answer out to 12 decimal places.
I am having trouble figuring out where to put %.2f in my code. I need it to get my answers for surfaceArea and Volume to be rounded to two decimal points. I have everything completed but wherever i put it, it seems to not work.
System.out.println("This program will compute the volume and surface area of a rectangular prism."); String output; double length; double width; double height; double volume = 0; double surfaceArea = 0; System.out.printf("%.2f", surfaceArea);
I want to design an open-answer quiz game using Java. Basically, the plan is to design a quiz where the name of a medicine is displayed as "the question" and the player will need to input the unique code (as "the answer") of the medicine in an open box (all the codes are two characters). The list has about 204 named medicine (with potentially more to be included at a later stage). The questions will not appear in the same order for each session restarted; they will appear randomly.
The player will have 60 seconds, and for each correct answer, will score 1 point and add 2 seconds to the timer. The player will also have 6 "lives", and for each incorrect answer, the player will lose a life, with no effect on the time.The idea of the game is to support the player memorise as many of these medicine codes as possible. How this can be achieved from total grassroots.
I want make a math equation game. usually math game use equation for the question and we answer that equation. ex : what is the result of 2*5 / 2+2/ 2^2 etc. and we answering that. but i want to make it different so i want to make the equation answer as the question and the equation as the answer of the game. Ex : the question is 54 so we can answer it with 9*6 or 24+30. and this is my java code
package coba; import java.util.Scanner; public class Coba {
public static void main(String[] args) { double angka = Math.random()*70;
[Code] ....
but when i run it the error code show like this : Quote
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: ");
import java.util.Scanner; public class AdditionQuiz { public static void main (String[] args){
//Generate random two integers using utility System.currentTimeMillis int n1 = (int)(System.currentTimeMillis() % 10); int n2 = (int)(System.currentTimeMillis() / 7 % 10);
[Code] ....
however the true/false result can not be printed due to the "answer" variable...
Is there any kind of way to generate HTTP request within a servlet, dispatch it to the server and get back the answer delivered to the servlet? Or are the servlets meant only to respond to passed requests, not generate them?
(I asked a similar question here: [Code] ..... but no luck)
The problem occurs after the user inputs the guess.... it either runs the for loop if guess = numtoguess and reveals the answer even if the user input is wrong.... or it always runs the first if statement in the while loop if guess!= to numtoguess... heres the code
public static void main(String[] args) { String[] Answers = {"yes", "Yes", "No", "no"}; String Name = JOptionPane.showInputDialog(null, "Hello, What is your name?","Random Game", JOptionPane.QUESTION_MESSAGE); String UI = JOptionPane.showInputDialog(null, Name + " do you want to play a game", "Random Game", JOptionPane.QUESTION_MESSAGE);
I'm trying to get the program to roll a four sided die between 100 and 1000 times, depending on your input, and then displaying the answer.
public class Lab08 { public static void main(String[] args) { int v1 =0, v2 = 0, v3 = 0, v4 = 0; int n; char response; System.out.print("Enter number of rolls (100-1000): ");
How do i make the 'date' column show only the date and 'timeIn' and 'timeOut' column only show the time. In my database table my 'date' column is a date type and 'timeIn' and 'timeOut' column is time.
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 want to make app in netbeans. When i write numbers in JTextField like 1,2,3,4,5,6... it should show me in JOptionPane information window result of ODD numbers.
I want my program to show 1st panel and when a person press image label 2nd panel showup which will have 2 tabs "oneway" and "round trip". But rightnow I only see 2nd panel with only 1 tab and don't see 1st panel at all.