Include Three Sides Of Triangle Formatted To Two Decimal Places

Sep 9, 2014

My program is supposed to include The three sides of the triangle formatted to two decimal places The perimeter formatted to one decimal place The area formatted to one decimal place The unformatted area. It does run, but it is not decimal formatted. I have read my book to try and figure out how to do this, but it doesn't make since to me.

import javax.swing.JOptionPane;
import java.util.*;
import java.text.DecimalFormat;
import java.util.StringTokenizer;
 
public class ShelbyHarms_3_03 {
public static void main (String [] args) {
double a, b, c; //Input sides of triangle

[Code] ....

View Replies


ADVERTISEMENT

User Input 3 Sides - Output Invalid If Does Not Make A Triangle

Nov 4, 2014

I had to make a program that allows the user to enter 3 sides and it should output "invalid" if it does not make a triangle and if it does make a triangle it calculates the area of the triangle and it doesnt seem to do anything but say "invalid" as the out put.

import java.util.Scanner;
public class MyTriangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
boolean valid = true;
double side1, side2, side3, area, A;
 
[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

Formatting Answers To 2 Decimal Places

Sep 8, 2014

I've been scanning forums for answers to this problem, but most deal with simple programming that you might find in a classroom (i.e. "System.out.printf") which will not work in the GUI I'm attempting to complete. Here's the tale of the tape:

The GUI is a price calculator I'm developing for my company that takes input from drop-down menus and several Jtextfields and calculates the answer based on the values contained within each. It's completely done (and functional), so I'd rather not change too much if at all possible. Because I'm dealing with decimal values then I'm getting 9 decimal places in the output JLabel, though. In order to display the answer, I'm using a series of "totalPrice.setText(..." declarations.

Because there is a fair amount of text and the values in the calculation are constantly changing, is there a way to 'simply' format the output JLabel to display only 2 decimals? Or is there an alternative solution that would work--say with a JTextfield instead--without having to completely re-code the calculator?

View Replies View Related

Formatting User Answer To Two Decimal Places

Nov 20, 2014

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.

So for 5/3

I would like it to accept the answer 1.67

not 1.666666666667

Is there a way to do this?

View Replies View Related

Printing 2 Decimal Places - Printf Not Working?

Mar 22, 2014

I need to print to 2 decimal places and I'm trying to use the printf method, but for some reason I keep getting an error. I've looked through my code, but unless I'm missing a small detail, it looks okay to me.

float sum = 0;
float avg = 0;
double[] rain = {0, 1.9, 1.5, 1.2, 1.1, 0.5, 0.03, 1.0};
 
//Calculate sum of rain.
for (int i = 1; i <= 7; i++) {
sum += rain[i];
 
[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

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

Floating Point Precision - Output With Two Decimal Places?

Jan 27, 2015

Consider this small program and output.

public class Floating{
public static void main( String[] args ){
System.out.println( 2.80 - 1.75 );
}
}

The output is 1.0499999999999998. Why not 1.05?

View Replies View Related

Type Casting - Getting Number With Two Decimal Places As Output?

Jun 7, 2013

"Type Casting" .... So the question is "How am I getting a number with two decimal places as output?"

import java.util.Scanner;
public class SalesTax
{
public static void main(String[] args) {
double purchase, tax;
Scanner input = new Scanner(System.in);
System.out.print("Enter purchase amount: ");
purchase = input.nextDouble();
tax = purchase * 0.06;
System.out.println("Sales Tax: $" + (int)(tax * 100) / 100.0); +//this will give two decimal places??+
}
}

View Replies View Related

Convert Java Code To Display Using Printf Statement With Two Decimal Places To Right

Feb 26, 2015

How i would convert this java code to display using the printf statement, with two decimal places to the right...here is the source code so far, but it has a few errors and needs to be reformated for printf

import java.util.Scanner; // scanner class
public class PROB3_CHAL15
{
public static void main(String[] args)
{
double checks =0,
totalfee =0,
fee = 10,
fee1 =.1,
fee2 = .08,
fee3 = .06,
fee4 = .04,
checkFee;
String input;
Scanner keyboard = new Scanner(System.in);
 
[code]...

View Replies View Related

Area And Perimeter Of Triangle - Decimal Formatting Error?

Sep 28, 2014

I am also having trouble with another program.

Java Code:

import javax.swing.JOptionPane;
import java.util.*;
import java.text.DecimalFormat;
import java.util.StringTokenizer;
public class ShelbyHarms_3_03 {
public static void main (String [] args) {
double a, b, c; //Input sides of triangle
double x; //Perimeter of triangle
double area; //Area of triangle

[Code] .....

Here are the errors:

ShelbyHarms_3_03.java:39: error: variable x might not have been initialized
JOptionPane.showMessageDialog(null, formatter.format(x));
^
ShelbyHarms_3_03.java:42: error: variable area might not have been initialized
JOptionPane.showMessageDialog(null, formatter.format(area));
^
2 errors

Am I not formatting the decimal format right?

View Replies View Related

Returns Area Of Triangle / Unless Triangle Not Value So Return String?

Dec 28, 2014

I'm doing a problem where the area of a triangle is returned (if valid). However, I want to return a message (i.e. 'triangle is not valid) if the triangle is invalid.

I'm not sure how to go about to doing this as my method (called area) will only let me return doubles. Possible to return a string in an else within my area method?

public class MyTriangle {
public static void main(String[] args) {
//triangle is valid if the sum of any two sides is bigger than the third
System.out.println(isValid(3, 4, 5));
System.out.println(area(543, 4, 5));

[Code] ...

View Replies View Related

How To Switch Sides

Oct 21, 2014

I had to make a chart where it took miles 1-10 and convert it to kilometers and then on the other side it needs to show 25-65 (in 5's) kilometers to miles and I dont know how to switch the sides...

import java.util.Scanner;
public class MilesAndKilos {
public static void main(String[] args) {
int miles;
double kilometers=1.60934;
System.out.println(" Miles Kilometers Kilometers Miles");
for(miles=1;miles<10;miles++){
kilometers = miles * 1.60934;
System.out.printf(" %2d %8.3f |
", miles,kilometers);
}
}//end of main method
}

View Replies View Related

Changing Number Of Sides On A Dice From 6 To 12

May 29, 2014

I have this really a graphics program that I'm working on which displays a single die, and right now it is set to the default 6 sides. I need to change it to 12. Here is the program:

package homeworkweek6;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

[code]...

Do I have to add more code somewhere further up in the program, or is there a line to replace these two lines to make it 12-sided?

View Replies View Related

Pythagorean Theorem Java Applet - How To Get Hypotenuse Of Sides A And B

Apr 3, 2014

I am not sure whats wrong with my code. I need to get the hypotenuse of sides a and b and I am having problems in the code.

// The "Components" class.
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
 public class ButtonDemo extends JFrame implements ActionListener {
// Declare objects
JLabel label;

[Code] ....

View Replies View Related

Formatted Input And Output In Java?

Feb 23, 2014

What are formatted input & output in Java? I want to know the difference between general "input & output" & "formatted input & output"? And what is the reason of the naming it as formatted.

View Replies View Related

How To Convert Formatted String To Integer

Feb 15, 2014

If I use the class DecimalFormat to format long number, how can I convert it back to integer?

DecimalFormat longFormat = new DecimalFormat("#,###");
long testLong=11000;
String strLong=longFormat.format(testLong);
System.out.println("NUM : " + strLong);
//Assume that at this point I don't have
//testLong, I have only the strLong value...
long newLong=Long.parseLong(strLong) * 2; 
//java.lang.NumberFormatException: For input string: "11,000

View Replies View Related

JavaFX 2.0 :: How To Access The Formatted Text Of A TableCell

Nov 20, 2014

Our users want us to build the following ontop of a TableView: When a key was typed, the row selection shall change to the first row showing a cell in a given column whose getText() starts with the typed letter. Such a functionality is known from lots of other software, like the Windows file explorer, where you can type a key to jump to the first file starting with that letter. It shouldn't be too complex to build, but due to the separation of "items" and "formatted cell text" it actually is... :-(
 
Using TableColumn.getCellData(S) we can access the item, but at that point, we don't want to repeat the formatting just for the sake of this functionality. We have set a cell factory providing this format, so the view looks great, but how can we access that formatted String programmatically to jump to the right row at a later time?

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

Reading Text File With Specific Input Format - Output Formatted Report

Apr 10, 2014

Here's a link to it : [URL] ....

The basic gist is it's "A program that reads in a text file that uses a specific input format and uses it to produce a formatted report for output."

Specifically :"For this lab you will write a Java program that produces a simple formatted report. The program will prompt the user to enter a file name. This file must contain information in a specific format (detailed below). Each "block" of the file contains information for one player in a competition -- the name of the player followed by a number of different scores that that player achieved. The program should find each player's average score, median score and best and worst scores and display them in a line on the final summary report. The program should also determine which player has the highest average score and which player has the lowest average score."

I get the following errors when I try and compile it:

Enter an input file name: Project11.txt
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException... -1
at java.util.ArrayList.elementData(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at Project11.getMedian(Project11.java:68)
at Project11.main(Project11.java:27)

I get that the error(s) reside in lines 68 and 27, among problem other areas, but I'm not exactly sure how I can fix them.

Here's my code:

import java.io.*;
import java.util.*;
public class Project11 {
public static void main(String[] args) throws IOException{
Scanner in = new Scanner(System.in);
System.out.print("Enter an input file name: ");
String input = in.nextLine();

[Code] ....

View Replies View Related

JSP :: Include From A Different Folder

Apr 17, 2015

I am creating a very simple webpage where I am using just a little bit of JSP to include partials (header, footer and asides) that are centrally located. One of the constraint that the site owner has put is that, for SEO reason, he wants to keep the url's the way they are. Most of the pages are located in the same folder, except for one which is in a subfolder.

Here is my problem, I have the partials in a folder and at the same level the images. Now, for that page located in the subfolder, when I include the partials, it is not able to locate the images because they are located in a folder one level up. What I could do is create a copy of the image folder in the subfolder or an adapted copy of the partials (referring to the images one level up), but either solution would make for a maintenance nightmare and repeat information on the server.

Here is a visual representation of my file system:

- Top level folder
- Partial_Folder
- header.html
- footer.html
- images
- picture_1.jpg
- Page_1.html
- Page_2.html
- Another_Folder
- Page_3.html

View Replies View Related

Include EAR File In Classpath?

Jan 23, 2014

I am writing an Ant script using the javac command but the library I need is bundled in an ear file, how can I reference this jar in ear file without extracting the ear file.

View Replies View Related

Manually Include Java API?

May 7, 2014

For some reason, when I generate a Javadoc (using javadoc.exe of JDK 8), it displays Java-defined classes like java.lang.String and java.lang.Object by their full names rather than simply String or Object. Only the classes inside the packaged contents were represented by their simple names and linked to them (had visible coloured bolding). Was I supposed to manually include the Java API?

View Replies View Related

How To Include Java File In All Projects

Mar 23, 2015

1) I have a file .java with some great functions, this functions i need use in all projects, then what is the easy by moment i start a project, and copy this file to project.. is possible have only 1 file with these utilities functions? (if yes how to declare or use in all projects?)

Note these utilities file i want use on JAVA desktop(swinf and javafx), on JSP webpages and in the futhurer on the mobile.
 
2) I have a JSP project in 1 .JSP file i have 8 Tabs (CSS tabs) when user click on tab1 i execute some jsp java code. and if user click on tab2 i execute a different JSP code, but my problem is, the JSP file is large large large, 1500 lines, my question is: is possible (similar in PHP) do an include?
 
<%
   include tab1.jsp
%>

View Replies View Related







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