Writing A Program To Dynamically Update XML File To Add
Feb 8, 2014
I'm writing a program to dynamically update an xml file to add, delete, and edit entries in the file. I've run into an issue with the add method because when I write into the file, a random letter is added before the line. EX:
I want to add "<item> ..." to the end of the list of entries, but when it is added, this is what is added "Z <item> ..."The spacing for the <item> is correct, however, I don't see where or why the Z is added.
public static void insertItem(Item i)
{
try {
String insert = " <item>";
String text = "";
Scanner in = new Scanner(file);
[code]....
View Replies
ADVERTISEMENT
Feb 11, 2014
I'm writing a program that dynamically updates an xml file as it is being edited. It needs an add function, delete, and save, and so far, I've gotten only the add function working properly. I've got a delete method that works when I run only that method, but not when I run the program as a whole. I don't get any exceptions or errors and I'm trying to edit the file via printwriter. It creates a new temporary file with the new xml with the deleted section and then overwrites the current .xml file. It runs flawlessly when I run only the delete method, but not when I run the program as a whole.
public static void removeFromFile(String file, String lineToRemove) {
try {
System.out.println("Removing: " + lineToRemove);
File inFile = new File(file);
if (!inFile.isFile()) {
System.out.println("Parameter is not an existing file");
[Code] ....
View Replies
View Related
Feb 1, 2014
I am new to JSF, trying to customize the primefaces picklist, I want to update the picklist Source List dynamically on certain events like onclick or change?
I tried to write an Listener and populate the dualModel, the call is going to the method and List is getting updated but in UI, the old list is only maintained . I have also asked this question in stackoverflow ,
Refer this link for further details : stackoverflow [URL] .....
View Replies
View Related
Nov 26, 2014
I need to convert a .txt file to html text, where the first line is changed to have < h1 > < /h1 > around it and the rest is wrapped in < p > < /p > so for example I read a .txt file that says:
chapter 1
this is a sentence
it would output:
<h1>chapter 1</h1>
<p>this is a sentence</p>
here is what I have so far and I cannot get anything to output.
FileInputStream filestream;
BufferedReader reader;
FileOutputStream output;
String firstline;
String body = "<p>";
String line;
[Code] ......
View Replies
View Related
Jul 20, 2013
So I am trying to write the output of two different java class files to one txt file while the program runs. The file name is determined before the program is ran, through the command prompt as arguments. How can I get the second class file to edit the same txt file without running into compile errors.
For right now I'm just going to send everything that the second file outputs to a message String variable, so that the Main class outputs to the the text file. I still want to learn how to write to the same text file directly from the second class file.
import java.io.*;
public class Test{
public static void main(String[] args) throws IOException{
int x;
//create a new file internally called doc. But externally labelled the user input
File doc = new File(args[0]);
if (doc.exists()){
[Code] .....
View Replies
View Related
Mar 21, 2014
Lets say I have a program that is not in any way connected to the Internet. I post it for for downloading, but I know that I will need to update it fairly often. I don't want people to have to redownload the entire program, I just want to send out a patch to update it. How can I do this?
View Replies
View Related
Sep 8, 2014
I am writing a program in Java where a user adds 1 stamp on a letter for every five sheets of paper in it (or fraction thereof)For example, I if I have 11 sheets of paper, I add 3 stamps. If the total number of stamps is more than 3, they don't send it.
I need to ask the user how many sheets of paper they have, and then calculate the appropriate number of stamps based on the formula above. I just don't know how to write the math formula to calculate this, i'm stuck. So far I have:
package test;
import java.util.Scanner;
public class LetterMailing {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int numSheets;
[Code] .....
What should I do next?
View Replies
View Related
Feb 9, 2015
I am trying to create an array list without using the built in arrayList class that java has. I need to start the array being empty with a length of 5. I then add objects to the array. I want to check if the array is full and if not add a value to the next empty space. Once the array is full I then need to create a second array that starts empty and with the length of the first array + 1.
The contents of the first array are then copied into the new array without using the built in copy classes java has and then the new array ends up containing 5 elements and one null space the first time round. The first array is then overwritten with the new array containing the 5 elements and the null space. The process then starts again adding values until the array is full which will be 1 more value then recreating the second array empty and the length of the first array + 1. This is my attempt at creating this but I have run into multiple problems where I get only the last value I added and the rest of the values are null:
public class MyArrayList {
public Object arrayList[];
public MyArrayList(Object[] arrayList) {
this.arrayList = arrayList;
[code]...
View Replies
View Related
Oct 19, 2014
how to print from bluej onto actual paper? how to do the formatting and configuration etc.
View Replies
View Related
Oct 23, 2014
Writing a program to take input from user. This input must be done with numbers only. If the input is a string I would like the program to loop and ask for input again.
double depositCheckingAmount;
do
{
System.out.println("Please insert amount to deposit into checking.");
[Code]....
As you can see my attempt is to use the ! expresssion incase the input does not equal a double. Is there another method I should be using?
View Replies
View Related
Apr 30, 2015
I'm getting ready to code a program that takes record of items loaned and return in a table. I want more than one user to access the program to be able to update the data in the table. For instance, if one user added 5 new items to the table, all other users would be able open the program to see a modified table with 5 new items. Was looking for some advice and was wondering if implementing a database would work best.
View Replies
View Related
Sep 22, 2013
So i was assigned to write a program that would print the answer to the system of two linear equation. the form of ax+by=c and dx+ey=f..I wrote this program, but it is incorrect since I tried it out on my terminal and I keep getting incorrect values.
import java.util.Scanner;
public class Quest4 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
[code]....
View Replies
View Related
May 2, 2014
Im trying to write a java program to search nearby bluetooth devices.. Im using Bluecove-glp-2.1.0 and bluecove 2.1.0..Im working on Ubuntu 13.04 LTS.I typend a code to get the local Device name..
public class BluetoothSearch {
public static void main(String[] args) {
LocalDevice ld= null ;
String name = ld.getBluetoothAddress();
System.out.print(name);
}
}
this is my code.. It returns me null. doesn't return me the local Device.
View Replies
View Related
Apr 3, 2015
I'm in the process of writing a program that determines if a number is a Palindrome or not. I'm not allowed to use strings and am required to use the getSize method shown below. I believe my issue that I'm having is that the "num" is not being called in the getSize method, and therefore not running the while loop, or at least that is what I believe is the issue.
import javax.swing.*;
public class getSize{
public static void main( String[] args )
{
int num;
num = Integer.parseInt (JOptionPane.showInputDialog ( "Please input a number" ));
[code]....
View Replies
View Related
Apr 30, 2015
It was quite recently that Data Structures was introduced to me, so I started out writing some iterative programs recursively.I found some strange output which shouldn't have come out but if you take a look at these three codes
long factorial(long n)
{
if(n == 1)
{
return 1;
}
else
{
result = n*factorial(n-1);
[Code] ....
These are three versions of the code, achieving the same objective of obtaining a given number and returning the factorial, but in spite of the changes made to the code, they produce the same result. I needed a reason as to why it is so? I tried to dry run all the codes but at some point or the other I got confused, and had to start all over again and couldn't come up with a proper result.
View Replies
View Related
Nov 4, 2014
User-defined classes. The concept of getters and setters goes right over my head. Right now we're to write a program to test the Person class below. We have to create 2 instances of the class to test each constructor, and test each method.
class Person {
// Data Members
private String name; // The name of this person
private int age; // The age of this person
private char gender; // The gender of this person
// Default constructor
public Person() {
this("Not Given", 0, 'U');
[code]....
then my output will print out the name. But the assignment doesn't tell us to modify the Person class at all, just to create a tester one.
View Replies
View Related
Sep 13, 2014
The manager of a football stadium wants you to write a program that calculates the total ticket sales after each game. There are four types of tickets: box, sideline, premium, and general admission. After each game, the data is stored in a file in the following format:
ticketPrice numberOfTicketsSold
Sample data might look like:
250 5750
100 28000
50 35750
25 18750
The first line indicates that the box ticket price is $250 and that 5750 tickets were sold at that price.
Your program should input in this data (using Scanner or an input dialog box), then output that data to a message dialog box along with total ticket sales information. Output the total number of tickets sold and the total sale amount. Make your output user-friendly and "pretty". Format your output with two decimal places. Use JOptionPane and the formatting techniques learned in chapter 3 for your output. Example output might be:
5750 Box Tickets sold at $250.00
28000 Sideline Tickets sold at $100.00
35750 Premium Tickets sold at $50.00
18750 General Admission tickets sold at $25.00
View Replies
View Related
Feb 24, 2014
Java Code:
public class Search
{
public static final int NOT_FOUND = -1;
public static int binarySearch( int [ ] a, int x )
{
int low = 0;
int high = a.length - 1;
int mid;
while ( low <= high )
[Code] ....
I keep getting illegal start of expression at ={-3,10,5,24,45.3,10.5}
It says I have 12 errors and I have tried so many things to fix it and I just don't know what to change to make it work.
View Replies
View Related
Jul 10, 2014
I'm (failing at) writing a program that searches an array using binary search, but I can't get it to work.
My code so far is this:
Java Code:
package sorting;
import java.lang.*;
import java.util.*;
public class sorteh {
public static void main(String [] args){
int[] array=new int [20]; //creates new array
for (int x=0;x<array.length;x++){ //populates array
array[x]=x*3+1;
[code]...
I copied what a website did for the sorting part, but if I have low=0 and high=19, wouldn't mid not be an int?
View Replies
View Related
Sep 19, 2014
Here is the objective of the assignment:
Quote : A bank in your town updates its customers' account at the end of each month. The bank offers two types of accounts: savings and checking. Every customer must maintain a minimum balance. If a customer's balance falls below the minimum, there is a service charge of $10 for savings accounts and $25 for checking accounts. If the balance at the end of the month is at least the minimum balance, the account receives interest as follows:
- Savings accounts receive 4% interest.
- Checking accounts with balances of up to $5000 more than the minimum balance receive 3% interest; otherwise, the interest is 5%.
Write a program that reads a customer's account number (integer), account type (character: s for savings or c for checking), minimum balance that the account should maintain, and the current balance. The program should then output the account number, account type, current balance, and an appropriate message.
Your program should only allow 'c', 'C', 's', or 'S' as valid input, any other character for the account type should result in an error message. Format your monetary output to two decimal places, and use constants for all the above constant values.
Sample output:
Please enter your account number (int), account type (char), minimum balance, and current balance:
46728 S 1000 2700
Account Number: 46728
Account Type: S
You have earned 0.04 interest on your account.
Current Balance: $2808.00
[Code] .....
Invalid account type!
View Replies
View Related
May 7, 2014
I am new to programming and we are writing a program to make a tic tac toe game utilizing inheritance, client-supplier, arrays, and EventButton. I am still trying to wrap my head around events and inheritance. We are instructed to write 4 classes (a TicTacToeModel, a TicTacToeView, a TicTacToe Controller, and a TicTacToeButton). I got the TicTacToeModel down, but am having trouble with the other classes.
Instructions for View: Write a class that implements the UML class diagram below. The only purpose of this class is to draw a picture of the specified TicTacToeModel. For purposes of this assignment, we understand a ‘theme’ to include such things as the background color of the tic‐tac‐toe board, the shape and color of the X indicator and the shape and color of the O indicator. While you are free to select your own personalized ‘theme’ your TicTacToeComponent must always be proportionally ‘correct’ regardless of the client‐determined width and height of the Component.
Instructions for the Controller: Write a controller that controls the game. There is one human player (the X player) and the computer player (the O player). The name of the class must be TicTacToeController. In a sense, the controller is the game since the controller will
1) create a TicTacToeModel
2) create a TicTacToeView and
3) create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game. While you are free to change the appearance of the controller, the basic elements must be provided
These are our instructions for the TicTacToeButton: create a TicTacToeButton (you must write this class following the design pattern covered in class lectures), a label, and text field such that when the button is pushed, the player moves into the cell selected by the text field. After every player move, the computer moves into a randomly selected empty cell. When the game is over, a text message must be displayed somewhere on the screen the gives the status of the game.And this is the code I have thus far for the button:
import java.awt.event.*;
import java.awt.*;
public class TicTacToeButton extends EventButton{
public TicTacToeButton(int x, int y, int w, int h) {
super("Move");
setBounds(x, y, w, h);
[code]....
View Replies
View Related
Oct 9, 2014
I'm trying to write a program that will output the total number of large,medium,and small pizza along with the average cost of an order. I'm stuck on this error , "Else without if" on line 48 else ...medium.
import java.util.Scanner;
public class PizzaOrder
{
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
double cost,total, average;
String name,response,size,type;
int count,l,m,s;
[code]....
View Replies
View Related
Jul 10, 2014
I am using a FileOutputStream to write a file but it is not writing data to destination file from source
Here is my code
package org.kishor.outputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class WriteToaFile {
public static void main(String args[]) throws IOException
{
FileOutputStream fout = null;
[code]...
find a bug where i am wrong why data is not on output file?
View Replies
View Related
Sep 9, 2014
I've looked at multiple sources and everyone is saying different stuff. Which one should I be using? FileWriter/FileReader, other people was saying PrintWriter, and one even said : "Formatter" which is the one I'm doubting mostly. My purposes for writing files is for like saving maps, saving high scores, etc.
View Replies
View Related
Jan 10, 2014
I have accountsData.txt file in my default package, this is the file it should be writing to and reading from.
There is an ATM class, which has the main in it. From here the program is supposed to work like an atm, you type in your account number and can withdraw or deposit. It is supposed to then write the changes to the file.
//Read from a file.
public void loadAccounts(String inputFileName) throws IOException
{
Scanner fin = new Scanner(new File(inputFileName));
// Variables to store the values.[/color]
int account = 0;
double balance = 0.0;
[Code] .....
View Replies
View Related
May 14, 2014
I have a strange behaviour when trying to update a bean. Here is the edit page:
<h3>Edit Post</h3>
<div class="row">
<h:form>
<div class="small-3 columns">
<label for="right-label" class="right inline">Title</label>
[Code] ....
Here is the bean class:
package com.airial.controllers;
import com.airial.domain.Post;
import com.airial.service.PostService;
import com.ocpsoft.pretty.faces.annotation.URLMapping;
import com.ocpsoft.pretty.faces.annotation.URLMappings;
import org.springframework.beans.factory.annotation.Autowired;
[code]...
postToUpdatet is always NULL. Why the title property is not binded ? What is wrong here ?
View Replies
View Related