I have an output of three columns, Total Income | Tax Payable | Net Income... however to output this I have the following code:
System.out.println(" Total Income | Tax Payable | Net Income");
int i = 0;
for (i=0; i <=18; i++){
if(incomes[i] < 0){
break;
[Code] ....
And the format of it comes out as: Screen Shot 2014-11-06 at 22.50.25.jpg
I'm getting very OCD about the format and I know there is a printf function which would solve this, however I don't really know how to use this correctly and it just messes up when I try to use it.
import java.util.Scanner; public class FindHexString { public static void main(String[] args) { String hexString = ""; //output a hex string int decNumber;//decimal number to be converted int storeInput; //copy f input decimal number
[Code] ....
I am trying to figure out how to convert from decimal to hexadecimal without using the java library function. This is just a guess. I could be wrong.
Using the concept of web service (SOAP), I need to have a web service running. The client page will pass an ID to the web service and in return the service will return some values retrieved from the database based on the ID passed, as output. The output so fetched has to be in XML format.
I am new to java and I have this assignment that I started but I am now stuck . The instructions are:
Create an ElapsedTimeCalculator class that computes the amount of time that passes between a starting time and an ending time, in military format.
For example, suppose the two times are 1445 and 1730. Then the program output should look something like this:
Start time:1445 End time: 1730
Exactly 2 hour(s) and 45 minute(s) have passed.
Total elapsed time in minutes:165 Total elapsed time in hours:2.75
ElapsedTimeCalculator Class Specifications:
1.Your class will have a constructor that takes two parameters: the starting time and the ending time in military format
2.Your class will also have these methods:
-Get method to return the starting and ending times -Set method that resets the starting and ending times to values passed as parameters -a method that returns the hour portion of the elapsed time -a method that returns the minute portion of the elapsed time -a method that returns the total elapsed time in minutes -a method that returns the total elapsed time in hours
Now here below you can see what I have so far...
public class ElapsedTimeCalculator { private int startTime, endTime; private int hours; private int minutes; private int seconds; //constructor ElapsedTimeCalculator(int start, int end)
[Code] ....
I don't have any errors so far, I am more stuck on how to begin a method that returns the hour, minute, etc.. (the third bullet).
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();
Write a class named FileDisplay with the following methods:
1.) constructor: the class's constructor should take the name of a fil as an arugment. 2.) displayHead: This method should display only the first five lines of the file's contents
Here is the following code I have made so far
import java.io.*; public class FileDisplay { private String filename; public FileDisplay(String Filename) throws IOException
[Code] ....
First, in my constructor I have taken in an argument and used that argument to open up an output file. Meanwhile, I'm trying to work n the displayhead method to print out information and to read data to. I haven't opened up my input file yet, but I'm not understand how can I read a print data to an output file. in
public void displayHead() {FileWriter file=new FileWriter(Filename)}
do I make create another instance of the filewriter class to output data?
In simple words, suppose to I want to display some messages on my output file in the displayhead function. Since I already have opened up the file in the constructor, how do I combine that in this method...
I have a program that I have created from scratch called Product and I also created a Tester program to test my theory. The only problem that I have is that I am getting an error with this statement System.out.printf statement. The statement needs to print out "Program [name = HP ENVY x360 TouchSmart, price = $xxxxxx". The error states that "The method printf(String, Object...) in the PrintStream is not applicable for the arguments (String, String, void).
Which tells me that it is referencing back to the class file where I have
public void applyDiscount(double percent) { percent = price - (price * percent); //establishing the discount }
The lines of code in my tester file are (partly displayed)
String formatString = "Product[name = %s, price = %.2f]"; System.out.printf(formatString, product.getName(), product.getPrice()) //user input the discount amount System.out.println("Enter discount percentage [0 - 100]: %.2f "); double discount = user_input.nextDouble(); System.out.printf(formatString, product.getName(), product.applyDiscount(discount)); //This is the line giving me an error. }
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.
I'm learning about the printf command, and when I have it, it is not letting me ad an input. Here is my quick little program:
import java.util.Scanner; public class TestingPrintF { public static void main(String[] args) { // Create a Scanner Scanner input = new Scanner(System.in);
[Code] ....
The first section works good, but when i move down to the second part it just automatically finishes without letting me enter a phrase.
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);
I am building a program that when you enter 1. it allows you to setup an item. However running my code my second if statement runs through.
import java.util.Scanner; public class InventorySystem { public static void main(String [] args) { Scanner input = new Scanner(System.in); int count=0; int inputEntered=0; int numberOfItems=0; double cost=0.00; String item; String description;
So i am creating a File object which has a text file passed to it. I then try to do logic with it using a BufferedReader. However, I get a FileNotFoundException on the using my code below. The Error is on the BufferedReader line. I
Java Code: System.out.println("--Reading text file--"); File file = getFile(c,fileName) // Returns a File object. System.out.println(file); // Shows me the file is looking correct. Displays contents to console. BufferedReader br = new BufferedReader(new FileReader(file)); System.out.println("BUFFERED"); while((line = br.readLine()) != null) { try { // Do Logic } catch(Exception ex){ ex.printStackTrace(); } br.close(); mh_sh_highlight_all('java');
I want to write simple game. Why if I press button UP and RIGHT it not move diogonally, may be it have special code. And how I need to write correctly border and gravity?
public class Main { public static void main(String args[]) { JFrame frame = new JFrame("Stickman"); Ground ground = new Ground(); frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); frame.setSize(710, 480);
I am trying to implement a game using the ACM graphics. For the game, I am trying to make the main frame a Grid of Cells.I made a Grid class which extends GCanvas:
import acm.graphics.GCanvas; public class Grid extends GCanvas{ private final static int WIDTH = 300; private final static int HEIGHT = 300; private final int DIMENSION = 5; Cell[][] grid;
If I run this code. I can manipulate it so that X wins. When the third X button is pressed, there is no display saying that X has won and that the game is over. I have read over this code for days and still have not figured it out.
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TicTacToe extends JFrame implements ActionListener, WindowListener{ public JFrame window = new JFrame("window");
I am currently trying to make a method that will enable a jLabel to be dragged across the screen. I want to be able to drag the object pretty much anywhere on the screen(I hope to eventually make a destination for it where it can be dropped but I will get to that later). I have looked on various places on the internet on how to achieve this and the most simple solution does something like this:
Java Code:
jLabel6.setText("jLabel6"); jLabel6.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { public void mouseDragged(java.awt.event.MouseEvent evt) { jLabel6MouseMoved(evt); } }); private void jLabel6MouseDragged(java.awt.event.MouseEvent evt) { x = evt.getX();
[Code]...
This actually works somewhat but it is very faulty. For example the jLabel keeps appearing and reappearing as I drag it. Furthermore when I drag it I can see a duplicate Jlabel being dragged as well in the top left hand screen. So how might I fix this?
I am trying to write a date program. I have it written and running correctly, except one issue. I cannot get the numerical date to display correctly. I know it is an issue with printf. I don't know anything about printf. Here is my method to return the day
public int getDay() { return day; }
When it returns, it is literally returning just the numeric date. I need it to show up as 02 or 03 instead of 2 or 3, respectively.
the dates are printing out of order. It should appear MM/DD/YYYY however with my code its printing DD/YYYY/MM.Here is my code.
public class DateTest { public static void main(String args[]){ Date date1 = new Date( 7, 4, 2004 ); System.out.print( "The initial date is: " ); date1.displayDate();
how to calculate the child's height in float value fixing value where if you choose male the accurate value, but if you choose female the value will be accurate too.
int heightMother, heightFather; int heightMaleChild, heightFemaleChild; String gender;
I'm unable to get the output for "AverageDriver" to print correctly(5 scores in descending order and average). The output displays the scores the same way they are entered and the average is always zero. The output for the Average program works fine and with the correct output.
import java.util.Scanner; //This class keeps 5 scores entered by the user public class Average { private int[] data; private double mean; public Average()
My console SQL Query app is not giving me the desired output.I am sure its might have something to do with my SQL Query.Its missing the description of the stock items and it prints a new line for each user as per number of stocks an repeats the user details and then prints the stock listed by that user(only want the user listed once with all its stocks). I will add my files and current output and desired out put below.
MakeDB.java:
import java.sql.*; import java.io.*; public class MakeDB { public static void main(String[]args) throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url="jdbc:odbc:StockTracker";