This is a college course assignment that consists of classes TotalSales and TotalSalesTest.In the main program I have created a two dimensional array to output a columnar layout with cross-totals in 4 rows and 5 columns. This program outputs sales totals by row for each sales person(1 - 4) and output by column for products(1 - 5). I have created extra elements in the array to store total for rows and columns. So far both classes compiles. The problem is that although the PrintWriter creates a notepad file, it doesn't print to it. I don't seem to understand the input and output methods completely. I finished another program similar to this using basically the same try and catch that read the file and printed out a document in notepad. Here is the code and I'll try include the input file.
import java.util.Scanner;
import java.io.*;
public class TotalSales {
private int salesPerson; //declare class variable
private int productNumber;//declare class variable
You are given a file containing the names and addresses of company employees from many years ago that your manager has asked you to import into a database. You can use a CSV file and your database application to load the file, but the file your manager gave you was exported from an old, non-standard accounting system. Here is its format:
If I am using the File object to read a file and PrintWriter object to write to a separate file, can I use them under one method. Or is the File one method and the PrintWriter another method?
I am creating a car simulator that simulators the odometer and fuel gauge on a car. I want to print the results to a text file but it seems to be printing only the last two lines instead of all of them. How can I make it so it doesn't overwrite the previous input?
Here's my main method:
public static void main(String[] args) throws FileNotFoundException { CarInstrumentSimulator carInstrumentSimulator = new CarInstrumentSimulator(); FuelGauge gas = carInstrumentSimulator.new FuelGauge();
Working on a program that creates an array from a file, organizes it in various ways, and then prints the results. Right now I'm specifically having trouble with the printAry() method - when I try to run it, I receive a NullPointerException for the active line in printAry() (EDIT: line 102). Not sure which sections are important to this, so I will include the client class and most of the service. I realize that the amount of documentation I included is not necessary, but it is required for the class.
class Lab3StudentAryService { private int count; private Lab3StudentData [] studentAry = new Lab3StudentData[50];
/* @param: none @return: none reads file and converts to array. */ public void fillAry() //constructor { Scanner scan = new Scanner(System.in);
New to programming. Am supposed to create a program that reads a text file (of integers) and computes a series of computations on these integers. I don't have the code for the integers in my code yet, (i know how to do those), but am struggling getting the array to simply print in the print writer. I have the user select a text file, read the file with a scanner, and then save the computations done from my code into another file. specifically, the problem is as follows: Write a program that uses a file chooser dialog to select a file containing some integers. The file contains an integer N followed by N integers. The program then uses a file chooser dialog to let the user specify the name and location of an output file to write results to.The data written to the output file will be as follows
(1) The original list of N numbers from the input file, (2) The original list of N numbers printed in reverse order of how they appear in the input file. (3) The sum and average of these numbers, (4) The minimum of all the numbers, (5) The maximum of all the numbers.
is my current exercise.so far i have gotten the code to create a file, and ask the user to input their age.what should i use to save what the user writes into the file?
Java Code:
package assignment7; import java.io.*; import java.util.*; public class Exercise2 { public static void main ( String [ ] args ) throws IOException { Scanner scan = new Scanner(System.in);
so i followed a tutorial on youtube called "Java Game Development with Slick" - by thenewboston,URL....okay, so i have made my game / program, and now i just want to export it to a jar file that people can double click and play..unfortunately when i double click the .jar file nothing happens...i get the little "loading" thingy on my courser but it disappears after about 5 seconds and then nothing happens :(the way i made it into a jar file is by doing the following:
-right clicked my java project.. -clicked on "export".. -clicked on java / Runnable JAR file -filled in the stuff, (JARs destination ect..) -pressed finish.. -then i got a jar file on my desktop and double clicked it....but as i said....nothing happens
So I was going to try to create a program that prompts input and creates a file (That didn't exist before) with that input as name.Then, the program prompts inputs after stating questions such as 1 + 1, then if the user inputs an answer, put "Question # = Correct "or" Wrong.Code SO Far:
Java Code:
import java.io.BufferedReader; import java.io.File; import java.io.InputStreamReader; public class File_Read { public File_Read() {//File_Read is the Interactive object
[code]....
So that it puts the Correct or Wrong into the file.
I have two files - I can get the second one to populate with the first ones data and then delete the first one. I cannot get it to then rename itself to the name of the first file. It also only hits the 'rename' section of the code providing I place system.gc in otherwise it completely skips it.
I compiled the applet, then put the applet in an HTML file using notepad and saved the html file in the right place for it to run correctly. The HTML file runs smoothly, but then it only shows the scrollbar part of my applet, and not the images or any text...
Why is This?????
Java Code:
import java.awt.*; import java.applet.Applet; import java.awt.event.*; import javax.swing.ImageIcon; public class Temperature_Convert extends Applet implements AdjustmentListener { private Image temp; private Scrollbar bar; private int old, newtemp = 0;
I have a question about the following snippet concerning the steps the javac compiler follows to compile a program:
[...]at first, searching a class within a package is discussed if the latter doesn't contain a full package name[...]
It is a compile-time error if more than one class is found. (Classes must be unique, so the order of the import statements doesn't matter.)
The compiler goes one step further. It looks at the source files to see if the source is newer than the class file. If so, the source file is recompiled automatically. Recall that you can import only public classes from other packages. A source file can only contain one public class, and the names of the file and the public class must match. Therefore, the compiler can easily locate source files for public classes.
However, you can import nonpublic classes from the current package. These classes may be defined in source files with different names. If you import a class from the current package, the compiler searches all source files of the current package to see which one defines the class. I don't quite understand the red fragment. I wondered if the word "import" nonpublic classes from the current package weren't a synonym for the word "use", since why would we want to import a class from the same package when compiler searches the current package automatically anyway?
However I wanted to test nonpublic classes that are contained in source file which name doesn't match the class name:
NonpublicClass.java:
Java Code:
package com.work.company; class NonpublicClass { public void description() { System.out.println("Working!"); } } mh_sh_highlight_all('java');
[Code] ....
Everything's fine when the source file names are the same as above. However, when I change NonpublicClass.java to a different name, there's an error "cannot find symbol" in:
Java Code: NonpublicClass v = new NonpublicClass(); mh_sh_highlight_all('java');
I noticed that the class file for NonpublicClass isn't even generated so that's probably the cause. If I change to the directory of the package the NonpublicClass is contained in and compile it directly, i.e. issue for example:
I'm trying to read a xml file and delete it's contents. I do this by reading the file,writing it to a temp and then overwriting the original with the temp by renaming it
//overwrite original xml file with new file boolean successful = outputFile.renameTo(inputFile); System.out.println("success");
It does say the value of the local variable is not used however. I've debugged to ensure it hits the code it always prints out the line after too.It just does not overwrite my original xml file with the temp one.
It's had votes on stack so I thought that would of been reputableStack - overwrite but the second one got voted as a good answer. But still I would like to know if my code can work or not.
I am kind of new to programming in java and I am trying to run a first time setup type of thing for my program so I am saving the settings to a file. If the file doesn't exist I want it to run the first time setup but if the file does exist I want it to skip that process. My problem is that .exists() says reads true whether the file is there or is not there.
public static void main(String[] args)throws IOException{ new Window(); //Runs the Window() PrintWriter writer = new PrintWriter(path); boolean bool = new File("path.txt").exists(); System.out.println(bool); if(!new File("path.txt").exists()){
Barbara is opening a book store, and she needs an effective, efficient, object-oriented program to keep track of her inventory. Barbara would like to maintain the following information about the books she sells: title, author, price, number in stock, and category. She categorizes her books into fiction, nonfiction and children’s books, because she has a separate room in her store for each category. Each book also needs an inventory number, and Barbara would like these numbers to start with 1000. She also needs to be able to keep track of the total number of books in inventory.
Barbara often facilitate her customers find books, and the program needs search capabilities to do this. Keeping an accurate inventory count of each book in stock is critical; both for accounting purposes and so she will know when to reorder. Barbara expects to have at most 2,000 differet books in her store.Barbara is very organized, and would like a nice menu, from which she can make choices that will enable her to do the following:
Add a new book to inventory This adds a new Book object (title, author, etc) into inventory It does not increase the number in stock of an existing book Search by title Search by author Search by inventory number Search by category Print out all info for all books This is the only output that should be on the command line
Please hard code the following book info into your program, so Barbara has some test data avaiable to test your program:
title: Crime and Punishment; author: Dostoevsky; price: 39.95; number in stock: 5; category: fiction title: Brothers Karamazov; author: Dostoevsky; price 34.50; number in stock: 3; category: fiction title: Java; author: Liang; price: 59.29; number in stock: 12; category: non-fiction title: Java, author: Horstmann; price: 14.33; number in stock: 4; category: non-fiction title: The Lion, the Witch and the Wardrobe; author: Lewis; price: 12.50; number in stock: 3; category: childrens
Here is my code so far. The first one is the "Blueprint" and the second one is the main.
public class Book { private String title; private String author; private double price; private int stockNumber; private String category; private int inventoryNumber =1000; private static int numberOfBooks = 0; public Book(String theTitle, String theAuthor, double thePrice, int theStockNumber, String theCategory)
I'm not getting text in the Pledge.txt file. Do I need to assign the pledge to a String variable?
Java Code:
import java.io.*; import java.util.*; public class ReadMe { public static void main(String[] args) throws IOException{ File file = new File("Pledge.txt"); PrintWriter output = new PrintWriter(file);
I have printed the result of my program into an output file.
For some reason I can't figure out how to get the file output.txt to actually print.
I've tried printing it like I would normally print a file but it's not working.
Java Code:
final PrintStream console = System.out; File file = new File("output.txt"); PrintStream out = new PrintStream(new FileOutputStream(file)); System.setOut(out); System.out.println(collection.toString()); System.setOut(console);
What do I do after this? mh_sh_highlight_all('java');
In a text file, I have individual titles (starting with ">" character), and under those titles, I have calculated values for a Counter. I want to search the entire text file for the highest counter under every title. After I get the highest counter, I would like to print it's title, name of the counter, and counter value. Example of the code I already have:
int letterCounter; String line; if (line.startsWith (">")) { bw.write (""); bw.write (line); } else { //code that counts how many total letters (letterCounter) under title }
I am trying to create a java file that will print out the temperature in Fahrenheit. This is my code.
import java.util.Scanner; public class TemperatureConverter { public static void main(String[] args) { float temperature; Scanner in= new Scanner(System.in); System.out.printf("Enter temperature in degrees Celsius: "); temperature = in.nextInt(); //Getting a red X next to this line. fahrenheit = temperature * 9/5 +32; //Add this line System.out.printf(+temperature + " degrees Celsius is " + fahrenheit + " degrees Fahrenheit."); //System.out.println(temp1 + " degrees celsius is " + fahrenheit + " degrees Fahrenheit."); } }
I need to know what I am doing wrong. Using Eclipse as my platform. I have entered comments where I am getting red X's.
The error I get when I run the program.
Exception in thread "main" java.lang.Error: Unresolved compilation problems: fahrenheit cannot be resolved to a variable fahrenheit cannot be resolved to a variable at TemperatureConverter.main(TemperatureConverter.jav a:24)
I am writing to a text file via user input and it is saving all the user input to the file but it is just printing one word per line. I would like it to print the string on one line and print the next string on the next line upon them hitting enter.
public void textFile() { Scanner reader = new Scanner(System.in); System.out.println("Enter file name: "); String fileName = reader.next(); File f = new File(fileName); PrintWriter p = null;
I am trying to remove a line based on user input. myFile.txt looks like:
Matt Brian John
However when I enter "Brian" (to remove this line), It is deleted on the temp file (myTempFile.txt), but not renamed back to the original file (myFile).