Tip Calculator - OptionPane Not Printing On 2 Different Lines
Jan 30, 2015
So I'm having an issue. I need the Option Pane to print on 2 different lines but it is only printing on 1. Here is my code:
public class TipCalculator
{
public static void main(String[] args) {
String finalBillString = JOptionPane.showInputDialog(
"Enter the bill amount before tip, for Example, 35.49");
double finalBill = Double.parseDouble(finalBillString);
[Code] ......
View Replies
ADVERTISEMENT
Jan 19, 2015
I am having trouble with reading specific lines from a text file in to a JTextArea. I want it to read only the first line of my text file and print it out in my JTextArea, however nothing is printing out.
BufferedReader a = null;
try {
a = new BufferedReader (new FileReader ("D:/FinalProjectFile.txt"));
a.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
[Code] ....
View Replies
View Related
Feb 13, 2014
Here's the lab assignment: This program is a simple "printing" calculator. It will accept input from the user in the following form:
number operator
The number entered will be expected to be a float type.
The operator will be expected to be one of the following:
'E' or 'e' - Enter the number into the accumulator (this will destroy the current value). This operator is used to set the accumulator to a known value.
'A' or 'a' - Add the number to the current value in the accumulator
'S' or 's' - Subtract the number from the current value in the accumulator
'M' or 'm' - Multiply the number times the current value in the accumulator
'D' or 'd' - Divide the current value in the accumulator by the number (do not divide the accumulator by zero)
'P' or 'p' - Raise the current value in the accumulator to the power of the number, for this problem truncate the number to its integer value. (negative numbers will not be allowed) SDo not use the "Math.pow()" method to solve this problem.
'T' or 't' - Terminate processing and print the final result. The number accompanying this operator should be ignored.
The 't' or 'T' stop signal is entered by the user, the program will print out the final value contained in the accumulator and terminate.
A sample session would be the following:
User inputs: Calculator outputs:
10.0 e = 10.0000
2 D = 5.0000
2 P = 25.0000
55.0 s = -30.0000
100.25 E = 100.2500
4 m = 401.0000
0 t = 401.0000
When the program starts the initial value for the accumulator is set to zero.
If the user gives an input that would result in an error if the operation were to be attempted, an error message is printed and the current accumulator value. This calculator handles three types of input errors:
1). if the user enters an invalid operator, the message is printed : an invalid operator was entered - please reenter
2). if the user attempts to cause a divide by zero, the message is printed : attempt to divide by zero - please reenter
3). if the user attempts to raise the accumulator to a negative power, the message is printed: negative powers are not allowed - please reenter
By looking at the requirements, here's how I would like to setup the program if I knew the proper syntax and all:
Step 1: Create Class called 'calculatorProgram'
Step 2: Use code that will allow UserInput after program executes (Our teacher forbids us to use Scanner, wants us to use InputStreamReader and BufferedReader)
Step 3: Create Variables:
*Fnum (It will be the Accumulating number)
*Ans (displayed after Fnum + operator)
*Operators: E, A, S, M, D, P, T (define their functions)
Step 4: -Tell user: "How to use the calculator and what letters to use for their function"
-Ask user to: "enter a number and an Operator function"
Step 5: Begin with a While loop( != 'T' || != 't'){} -I think that's how the loop should be formatted
Step 6: Design proper If/else and nested If/else statements for each operator and its function, be sure to use nested if/else for invalid operators, divide by 0, and using negative powers.
Assuming I knew how to write Java this is how I would want to code my program. I understand the concept or I/O and the purpose of Conditional statements just I have a hard time knowing how to place the variables in the right places and writing proper syntax.
View Replies
View Related
Jan 29, 2014
If you were given a problem to search for an error in a section of code but it is incredibly long, what are some ways you can go through the lines of code quickly?
View Replies
View Related
Dec 19, 2008
I'm working or better say.. I'm trying to work :) with Maven projects (m2eclipse plug-in) and Eclipse IDE. The problem I have is that sometimes the debugger seems to skip some lines of the code without a reason.
Is there an issue of synchronisation with my .class files?
View Replies
View Related
Jan 21, 2015
I have this part of the file.
class CreateFile implements ActionListener{ // MailOrderCreateFile.java
@Override
public void actionPerformed(ActionEvent ae){
String getDestination = txtDestination.getText();
file = new File(getDestination); // needed for Creating and Displaying the file
currentTime = txtCurrentTime.getText();
try {
FileWriter fw = new FileWriter(file);
[Code]...
What I wanted to do is that every time I press the button that will activate this part of the code, it will write to a .txt file defined in my txtDestination var (a JTextField). After the first time the file was created, it must append a new line every succeeding presses. However, everytime I do this, it just simply overwrites the contents of the .txt file. The example output would have been like this:
First time.
O R D E R D E T A I L S:
Time ordered: 01/21/2015 Wed 10:21:54 PM
Item number: 10
Item price: $4.59
Quantity ordered: 12,321
Total: $56,553.39
[Code]...
I've tried createDetails.write but to no avail.
View Replies
View Related
Jul 19, 2014
This what the data file looks like -
5165168416516988798484984984984984
9898798798798
1556516846516518498
51688484979789798798798491
The problem was to make code which will combine consecutive lines which contain some data into one line and print it. I made a solution that works.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class Filez {
public static void main(String[] args) {
File file = null;
[code]...
View Replies
View Related
Oct 24, 2014
A friend and I are working on a project in which we must test "super anagrams" (anagrams in which all characters in the first string are found in the second). We have a driver and definitions class pasted below:
Definition
class SuperAnagram{
String left = new String("");
String right = new String("");
[code]....
In the driver class, we get "cannot find symbol" errors at the beginning of cleanStrings and isSuper, both inside and outside of the if statement.
View Replies
View Related
Feb 10, 2014
I'm using the Spring Layout Manager to put a form in a JPanel and I'm trying to center the lines horizontally so they will stay centered when the window is resized. Nothing I've tried has worked, I can't find anything on the web, and even my fallback of seeing how Netbeans does it fails as Netbeans doesn't seem to support the Spring Layout.
View Replies
View Related
May 24, 2015
My code is like follows. I want add the lines of data from text file to arraylist.After add the lines to array list,i want to get the interesection between the lines of data. But I could not get the intersection and it returns empty. My sample data from specific line in text file as follows,
line 1 data:5 1 1 1 2 1 3 1 1
line 2 data:5 4 4 5 7 10 3 2 1
try {
File f1 = new File("C:/users/User1/Desktop/Datasets/Dataset.txt");
String filename = f1.getAbsolutePath();
FileReader reader = new FileReader(filename);
BufferedReader br1 = new BufferedReader(reader);
[Code] .....
View Replies
View Related
May 21, 2014
I have a text file with the below details and we get the input as name CONNECTION_PORT and we need to delete the matching global variable which as CONNECTION_PORT and keep the remaining global variable in file without using any temp files.
for example
input:
CONNECTION_PORT
Text file
<globalVariable>
<name>CERTIFICATE_PASSWORD</name>
<value>fgfdgfgf</value>
<deploymentSettable>true</deploymentSettable>
<serviceSettable>false</serviceSettable>
<type>Password</type>
<modTime>1398834966045</modTime>
[code].....
View Replies
View Related
Feb 6, 2015
Lets say this txt file contains 2 lines.
---------
hello
bye
---------
What would i have to do to insert a a piece of text in between hello and bye? I would like for the it to search for "hello", then add a line after it so it would look like :
-------
hello
newtext
bye
-------
I have these 2 methods that work as intended, but i just cannot seem to do what i've stated above.
Java Code: /**
* @param location
* Location of the .txt file.
* @param text
* The String to search for in the .txt file.
[Code] ....
View Replies
View Related
Nov 19, 2014
I've to read in an array of 1000 random numbers, and then my program sorts them depending on whether the user chooses bubblesort, selectionsort, etc...My code all works fine, my problem is with the actually output display. I have method that displays the content of the array that I call for the unsorted array, and for the sorted array. So at the moment the output to the user looks like:This program sorts an array of numbers by your choosing.
Array before sorting:
148
626
817
4
312
652
643
134
etc... for 1000 numbers
----------------------
1. Bubble Sort
2. Selection Sort
3. Insertion Sort
4. Merge Sort
5. Quick Sort
----------------------
Please enter your sort choice: 4
Array after sorting:
1
3
4
4
5
6
6
7
etc... for 1000 numbers
is there a way that I can display the unsorted and sorted array's content on various lines like so:
150 312 149 31 392 384 66
498 909 35 602 568 897 131
654 645 274 264 895 281 462
244 171 958 649 740 351 344
I just think it'll look nicer if I can do it like that.My display method looks like this:
//method to display array
public static int[] displayArray(int[] array){
//display array
for (int i =0; i < array.length; i++)
[code]...
View Replies
View Related
Jul 1, 2014
Using JOptionPane, I want to display in one window:
1: ***
2: *****
etc
where 1 is the element of the array, and the * are a percentage calculated in a loop. My variables are all being input fine, but the output is 100+ windows:
1:
*
*
*
2:
*
The CLI way would be with print() and println(), but I'm having a tough getting it to be visual.
View Replies
View Related
Feb 16, 2014
I am just displaying my values in different ways and I can't seem to get my values to display one at time on new lines. I dont know why that isn't compiling. The part i am having trouble with has the "Not Working" tag in the code.
[highlight=Java]
//Trying to figure out how to use /n
public class Test
{
public static void main(String[] args)
{
int gold= 5;
int silver= 3;
int bronze= 1;
[Code] ......
View Replies
View Related
Jun 28, 2014
the number of lines that can be printed on a paper size, the point size of each character in a line, whether lines are double-spaced or single-spaced,the top and the bottom margins of the paper. assume that all characters are of the same point size, and all lines are either single-spaced or double-spaced. note that 1 inch = 72 points. make over, assume that the line are pointed along the width of the paper. for example, if the length of the paper is 11 inches and the width is 8.5 inches,then the maximum length of a line is 8.5 inches.write a program that calculates the number of characters in a line and the number of lines that can be printed on a paper based on following input from the user.
a.the length and width, in inches, of the paper.
b.the top, bottom, left, and right margins.
c.the point size of a line.
d. if the lines are double-spaced, then double the point size of each character
View Replies
View Related
Jan 30, 2015
Me and my mate are struggling to get our code to split a line in a text file which are separated by (":") and store into an array. We've managed to split each individual line into an array, but cannot work out how to do it with multiple splits over one line.
try{
FileReader fr = new FileReader("C:UsersTomDocumentsNetBeansPro jectsfootballA2_Tom_Tyler2srcukackingsto nci5100football_a2 om_mcLean_tyler_wattsmo delfootball_teams_phase1a.txt");
BufferedReader br = new BufferedReader(fr);
while(br.ready()){
String nextLine = br.readLine();
String[] fTArray = nextLine.split(",");
System.out.println();
for(String str : fTArray) {
System.out.println(str);
}
}
This code works but how would we do it for multiple splits over one line, along with this array?
View Replies
View Related
Apr 7, 2013
I am trying to write a java code for a homework problem in my intro java class but im having problems. This is the problem:
Write a program that open the MyFile.txt and read from a file with these criteria.
1)-The program should display the first five lines of the file’s contents only.
2)-If the file contains less than five lines, it should display the file’s entire content. You must check for end of file and less than 6 lines on the loop iterations.
3)- your program should use loop to read the line by line of the file MyFile.txt.
The serperate myfile.txt has this
I can still remember, at the end of that year, we sat for the last time in our circle together. She played us her favorite song, "like a bridge over troubled water" and quietly passed out a gift she had made for each of us.She had made each of us a pottery heart with our name and the date on it on the back each read "I believe in ME".We all cried including her. She told us she would always remember US. We believed she would.
and this is what the code is suppose to look like after you run it : Java33.png
And this is what i have so far : Java22.png
what needs to go next to complete the javascript to show the first 5 lines of the text files?
View Replies
View Related
Feb 10, 2015
Basically it prompt from a user for a text file name and save the content as an array. some part of my code is here:
public class arraysort{
static BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws Exception {
System.out.print("Enter the first name of the file: ");
String input = kb.readLine();
[Code] ....
As you you may figure, it works if I put numbers separated by each lines. I was wondering if I can change it so that it works when I put numbers separated by space rather then each lines.
View Replies
View Related
Apr 28, 2014
When I open applications specially high graphics applications, the screen flashes with whole black display with a number of horizontal white lines then after 2 or 3 flashes it opens the desired program. What is the cause, is it low graphics memory, physically damaged screen or ?
View Replies
View Related
Oct 21, 2014
I did the update to JavaFX 8.0 and the grid lines of LineCharts have become dashed. I want them to be solid like they were before the update.
View Replies
View Related
Nov 29, 2014
I can't seem to understand how to change certain line of text, inputted from a file. For this I really don't know where to begin. I have got the input from the file. But I want to change like very other line in the file. Can't seem to understand how this could be done. Is there away to access specific lines from the file and edit them? So far, i have this:
import java.util.*;
import java.io.*;
public class ChangeEveryOtherLine {
public static void main(String[] args){
//Constructing file object representing input file
File inputFile = new File("input.txt");
[Code] .....
View Replies
View Related
Jul 2, 2014
I am writing to a file coordinates of texts using PathIterator (Java Platform SE 7 ) saved as SVG format i defined the Font attributes using AttributedString (Java Platform SE 7 ) and TextLayout (Java Platform SE 8 ). It is saving to the file and working properly, but it is just writing as a single line of text where is my target is multiple lines of text, i began using LineBreakMeasurer (Java Platform SE 7 ) Class, but some text is removed plus i got single line of text only, where i face the problem that , How to determine the width to get multiple lines of text ? i tried to figure out from this exampleDrawing Multiple Lines of Text (The Java - Tutorials > 2D Graphics > Working with Text APIs) where is drawing multiple lines of text but i am using getBounds().getWidth() of TextLayout object the code i tried
View Replies
View Related
Apr 8, 2014
I am trying to write a code to remove comment lines from the input java file.
I am getting an error -Exception in thread "main" java.lang.NullPointerException.
Whats wrong in the code. It is showing error- Exception in thread "main" java.lang.NullPointerException in- return new String(buffer),, and the word "String" everywhere present in the program.....
public static void main(String[] args) {String source = readFile("sorce.java");
System.out.println(source.replaceAll("(?:/*(?:[^*]|(?:*+[^*/]))**+/)| (?://.*)",""));
}
static String readFile(String fileName) {
File file = new File(fileName);
[Code] ....
View Replies
View Related
May 4, 2014
Im doing a problem where i have to find the area of four triangles split by two intersecting lines, All i have are the points for x1, y1, x2, y2, x3, y3, x4, y4. My question is how do i find where these two lines intersect?
View Replies
View Related
Jan 9, 2014
Here's a snippet of code from a program I'm making:
private void init() {
...
testInfo = new JTextArea("Progress log:
");
testInfo.setEditable(false);
testInfo.setLineWrap(true);
testInfo.setPreferredSize(new Dimension(testInfo.getPreferredSize().width, 200));
scrollPane = new JScrollPane(testInfo);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
...
add(scrollPane);
}
The problem is, the JTextArea that's created has a "limited" number of rows - it seems you can still enter more lines than the "limit", but they don't show. I thought it was a problem with the JScrollPane but I'm not so sure...
View Replies
View Related