Elapsed Time Calculator - Output In Military Format

Feb 12, 2014

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).

View Replies


ADVERTISEMENT

Military Time - Adding Minutes Displaying Correct Time

Feb 9, 2015

I am working on an assignment that I can't seem to figure out the final part to. The program takes in course data such as the time the class starts and how long it lasts. The time is in military time (0000 - 2400)

I need the output time to be the time the class started, plus the length of the class, and displayed in military time.

for example,

Start Time = 0930
Length = 50 minutes
Endtime = 1020

I can't for the life of me figure out how to do this. I have gotten a program that works for this time and minutes, and displays the correct 1020. But when I change the information to say

Start time: 0700
Length = 90 minutes

I get:

Endtime = 90

90 is technically correct, the way the formula is setup, but I need it to display 0900 not 90.

Here is the code that I have. Be easy, I'm still learning, and this is just the file I created to get the formula to work. Also, the verbose in here is just for my own debugging to make sure values should be what I'm expecting them to be.

public class calc
{
public static void main(String[] args) {
double hours, minutes, length;
double temp;
int time = 2400;
hours = time / 100;
System.out.println("Hours are: " + hours);

[Code] ....

View Replies View Related

Converting Military Time To Standard Time?

Jan 29, 2014

I have two classes. time_runner is used for testing my code.

This is what I'm using to test my code:
 
class time_runner
{
 public static void main(String str[]) throws IOException {
 Time time1 = new Time(14, 56);
System.out.println("time1: " + time1);
System.out.println("convert time1 to standard time: " + time1.convert());
System.out.println("time1: " + time1);
System.out.print("increment time1 five times: ");
time1.increment();

[code]....

The two constructors are "Time()", which is the default constructor that sets the time to 1200, and "Time(int h, int m)" Which says If h is between 1 and 23 inclusive, set the hour to h. Otherwise, set the hour to 0. If m is between 0 and 59 inclusive, set the minutes to m. Otherwise, set the minutes to 0. Those are my two constructors that I pretty much have down. The three methods however I'm having trouble with. The "String toString()" Returns the time as a String of length 4. The "String convert()" Returns the time as a String converted from military time to standard time. The "void increment()" Advances the time by one minute.

public class Time {
private int hour;
private int minute;
  public Time(int h, int m) {
if(h > 1 && h < 23)
hour = h;

[code]....

View Replies View Related

How To Get Time Elapsed While Opening PDF File

Jul 27, 2014

I want to get the time elapsed while opening a pdf file . I am not able to find a way to do it using PDFBox, Is there any way using which I can create a PDDocument in my java program and use some API to launch the PDF file and measure the time elapsed in opening it.

View Replies View Related

Represent Time Span Of Hours And Minutes Elapsed - Method Is Undefined For Type TEST

Jul 29, 2014

I am trying to run a class with a client code and I get the following error

The method add(TimeSpan) is undefined for the type TEST

Why i get this error?

package timespan;
// Represents a time span of hours and minutes elapsed.
// Class invariant: minutes < 60
public class TimeSpan {
private int hours;
private int minutes;

[Code] ....

View Replies View Related

JSP :: Using JSTL To Format Date And Time

Jul 14, 2014

How to format this "2014-07-14T19:40:46" date to dd-mm-yyyy with time using jstl?

View Replies View Related

Convert Time In Seconds To Hhmmss Format?

Apr 8, 2014

I am trying to convert time in seconds to hhmmss format.How do i get the minutes and seconds.

View Replies View Related

Basic GUI Calculator - Display Amount Of Commission And Total Annual Salary In Dollar Format

Apr 28, 2014

So, I am supposed to write a program that calculates the total annual compensation for a salesman using user input for the salary, sales, and commission rate (list of 3 predefined commission rates. have to display in dollar format the amount of commission and total annual salary.

CommCalc class

public class CommCalc
{
//attributes of class, stored data
private double sales;
private double salary;
private double rate;
//and a total field? beware stale data.
//store sales argument from sales field
public void setSales(double sal)

[Code] ....

I know that i have to fix some of the semantics . I have this code that I made earlier, is there an easy way to make it into a GUI interface? Or will I have to go throughthe code lines to add the JOptionPane? And I am a little confused on how to make a list (array) for the commission rate.

View Replies View Related

Trigonometry Calculator - Output Of If / Else Statements

Feb 10, 2015

Here is my code. Basically a trigonometry calculator (I hope).

import java.util.Scanner;
public class first {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
double hy;
System.out.println("Please enter length of hypotenuse:");
hy = in.nextDouble();
double op;

[Code] ....

My input:

Please enter length of hypotenuse:
20
Please enter length of opposite:
10
Please enter length of adjacent:
15
Which value would you like to calculate?
(sinA, cosB or tanC)
sinA
Please enter one of the options.

It runs and everything is fine, just that the if statement seems to get skipped over and direct straight to the else and I'm not sure why.

View Replies View Related

SOAP Output Required In XML Format

Mar 21, 2014

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.

View Replies View Related

Making Time Calculator Work / Modulo Division Not Working

Oct 22, 2014

Prompt for the project is "Write a program that will ask the user for a number of seconds and output the equivalent period of time in days, hours, minutes, and seconds.The program should:

-Use modulo division to calculate the number of days, hours, and minutes.
-Use compound operators when making assignments.
-Proper formatting and use of comments
-Symbolic constants defined as the number of seconds in a minute, hour, and day.

For example: final int sec_in_min = 60;"

public class Mod1
{
public static void main (String[] args)
{
int sec, min, hr, day;
final int SEC_IN_MIN = 60;
final int SEC_IN_HR = 60 * 60;
final int SEC_IN_DAY = 60 * 60 * 24;
 
[code]....

View Replies View Related

Unix Timestamp Conversion To EST Timezone Date Time Format

Dec 26, 2014

I have a requirement to convert 'unix time stamp' to 'Date time format'

Input (Unix time stamp) : 1426013480000

Output should show : 3/10/2015 2:51 PM EST (or) 10th March 2015 2:51PM EST

View Replies View Related

Format Output Correctly Using Printf Function

Nov 6, 2014

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.

View Replies View Related

Area Calculator - How To Move All Input / Output To Main

Nov 11, 2014

I am stuck on one of the projects: Area Calculator

I am able to code an area calc that works, but am unsure how to move all the input/output to main like the project wants. here is a piece of my code so far:

public static void main( String[] args )
{
Scanner kb = new Scanner(System.in);
int base = 0, height = 0, width = 0, radius = 0, choice;
System.out.println( "-=-=-=-=-=-=-=-=-=-=-" );
System.out.println( "1. Triangle" );
System.out.println( "2. Rectangle" );
System.out.println( "3. Square" );
System.out.println( "4. Circle" );
System.out.print( "Pick a shape: " );

[Code] ....

I have the same thing for rectangle, square, and circle (of course with the correct formulas) and the program works perfect, but the assignment is still wrong until I can move the input/output to main. what do I do?

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

Print Writer Won't Fill Output File / Blank Every Time

Apr 10, 2014

I am trying to write to an output file that the user names. I have flushed and closed the printwriter, so now I am at a loss. The console output works fine with the formatting, and the file is created, but I cannot get the file to populate. I have the following:

public static void main(String[] args) {

try
{
Scanner kb = new Scanner(System.in);
System.out.print("Input file: ");
String inputFileName = kb.next();
System.out.print("Output file: ");
String outputFileName = kb.next();
// Construct the Scanner and PrintWriter objects for reading and writing
File inputFile = new File(inputFileName);
Scanner in = new Scanner(inputFile);
PrintWriter out = new PrintWriter(outputFileName);

[code]....

View Replies View Related

Program To Read / Compare Time Intervals - Showing Wrong Output

Feb 24, 2015

the below program is to read the time intervals (HH:MM) and to compare system time if the system time between your time intervals print correct time and exit else try again to repeat the same thing. By using StringToknizer class. and i have written like this

import java.io.*;
import java.util.*;
public class Main
{
static int k1,k2,v1,v2;
public static void main(String args[]) throws IOException
{
DataInputStream o=new DataInputStream(System.in);

[Code] ....

but is showing correct for some inputs and wrong for some inputs ....

View Replies View Related

Output For If Else Is Missing Second Output

Feb 15, 2015

my output fails to display me the 2nd output.Here's my code.

import java.util.Scanner;
public class year
{
public static void main (String [] args)
{
Scanner console = new Scanner (System.in);
System.out.print("Enter the choice of book(A-ABC,D-EFG):");
String x = console.next();
System.out.print("Enter the rate (1-3):");
int y= console.nextInt();
System.out.print("Enter number of kids reading:");
int k = console.nextInt();
 
[code]....

When I key '0" for kids, it did not appear the second print out. I don't want the first print out to be the output.

View Replies View Related

Tip Calculator For Fun

Oct 18, 2014

So, I'm working on a Tip Calculator for fun. I have everything worked out for the most part. The feature I am trying to add is to give the user the amount of change they'll get back from their transaction. I do not ask the user any information other than what is their bill.

Please enter your bill total : 5.50
Please enter your name : some name
Total : 5.50
Tax : 0.48 -- Based off a tax rate of 8.75%
Total with Tax : 5.98 --
20 percent Tip : 1.10
Total with Tax and 20 percent Tip : 7.08
Total change : <-- I believe this will be about $2.92

I want the total bill to round to the nearest $10 value (e.g. for $5.50, calculate bill to $10. For $13.00, calculate bill to the $20.00, and so on... This way I get an accurate amount of change to give back to the user.

View Replies View Related

MVC Calculator - How To Get It To Actually Calculate

Sep 28, 2014

I made a MVC calculator. I was wondering if you could take a look at my design and if I was on track. I am still working on getting it to actually calculate something. All the buttons respond and print text on the JTextField but it is not calculating.

package calculator.MVC;
import javax.swing.JButton;
import javax.swing.JTextField;
public class CalculatorModel {
private int sum;
private int number;
private char opt;

[code]....

View Replies View Related

Calculator Only Return 0.0?

Sep 2, 2014

I am making a calculator in Java. However, when I press the "=" button on my calculator, it always returns 0.0, no matter what. I don't understand why? The code is below:

import javax.swing.*;//import the packages needed for gui
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import java.util.List;
import static java.lang.Math.*;
public class CalculatorCopy {

[Code] ....

View Replies View Related

How To Add Loop In Calculator

Mar 11, 2015

import javax.swing.*;
public class BasicCalculator{
public static void main (String[] args) {
String output="";
double n1,n2;
String operation;
operation= JOptionPane.showInputDialog("Please enter your operation");

[Code] ....

How to add a loop in this problem:

View Replies View Related

While Loop Pay Calculator

Dec 2, 2014

I have the basic workings of this program just doing all the printing at the end is throwing me off. Anyway here are some of the requirements and my code:

1. Allow the user to input an individual's hours worked.
2. Accumulate the total regular hours worked, the overtime hours worked, the amount of the regular pay, the amount of overtime pay, and the total payroll, for all of the employees entered.
3. Allow the user to enter a zero (0) as the Boolean expression to end the loop.
4. When the loop ends print out all of the accumulated totals with appropriate labels, each on a separate line.

import java.util.Scanner;
public class WhileLoopPayCalc
{
public static void main(String [] args)
{
final double REGULAR_HOURS = 40f;
final double HOURLY_WAGE = 12.5f;
final double OVERTIME = 1.5f;

[code]....

View Replies View Related

Calculation In Awt Calculator

Jul 10, 2014

I am facing problem during calculation in my awt calculator. It is showing NumberFormatException. Below is part of code.

if(e.getSource()==b14)//On button 14, label is "/"
{
String v1=tf.getText().toString();
num1=num1+Integer.parseInt(v1);//num1 is as integer variable
tf.setText("");//tf means textField
}else

[code]....

View Replies View Related

Calculator In Java

Oct 28, 2014

I can not this to work correctly.

public static void main(String[] args) {
FloatWrapper x1=new FloatWrapper(0);
FloatWrapper x2=new FloatWrapper(0);
do{
switch(menu()){
case 'a': if(dataInput(x1,x2)) add(x1,x2); break;
case 'b': if(dataInput(x1,x2)) subtract(x1,x2); break;

[code]....

View Replies View Related

Trying To Create A Calculator

Sep 16, 2014

I'm new to java and have been coding for a few hours. I tried to create a calculator (Which has no GUI, just text inputs)which will let you select how to process the two integer (Add, minus, times etc.) I cant seem to get it to work. I will put in the process way such as times and have entered two integers and every time it doesn't work. Here is my code:

import java.util.*;
public class Calculator
{
public static void main (String args[])
{
int input1 = 0;
int input2 = 0;
int answer = 0;

[code]....

View Replies View Related







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