For Loop To Display And Increment?

Mar 1, 2015

I'm trying to display an columns and rows. The first column has integers and the rest are doubles. The initial calculations are correct, but I cannot figure out how to total last column, which is interest paid, and then start the iteration over.

int paymentNumber;
//print out the colum labels
System.out.printf("%7s %9s %10s %8s %15s %n", "Payment", "Interest"
, "Principal", "Balance", "Interest Paid");
System.out.print(" "); //put three blank spaces first
//Test For Loop Output:
for ( paymentNumber = 1; paymentNumber <= period*12; paymentNumber++) {

[Code] .....

Here's the output: It displays the payment number correctly. Am I supposed to write a for loop for each column?

run:
Please enter the amount of the loan:
1000
Please enter the interest rate:
1
Please enter the loan period in years.
1
Your Monthly Payment is:$83.79

[Code] ....

View Replies


ADVERTISEMENT

How To Automatically Increment ID And Then Display Only One ID In Report

Jun 7, 2014

The program shall assign a new employee ID to the employee and display it on the screen.

The employee ID shall be generated by adding 1 to the largest employee ID already in the employee.txt data file.

You can see I've tried variations of identification++ but have not been successful. I've also tried to get the last or the highest identification in the arrayList but have not done that right.

public static void addEmployee() {
String firstName = Validator.getString(
sc, "Enter First Name: ");
String lastName = Validator.getString(
sc, "Enter Last Name: ");
int identification = 0;

[Code] ....

I also can display all of the employees their identifications and their punches but I cannot narrow it down to searching one employee and displaying information for just the one.

-If the selected value is ‘I’, prompt the user to enter the employee’s ID number.
-If ‘I’ is selected the display shall show the employee’s name and ID, list out each day worked in chronological order, the number of hours worked that day and a total number of hours worked in the two week period.

The report shall prompt the user to re-enter an employee ID of it does not exist in the employee file.

private static void displayReports() {
System.out.println("Report");
Scanner sc = new Scanner(System.in);
String action = " ";
while (!action.equalsIgnoreCase("d"))

[Code] ....

View Replies View Related

Increment Variable Each Time It Goes Through For Enhanced Loop

May 28, 2014

I am trying to increment a variable named counterVariable each time it goes through a for enhanced loop. It is stuck on 0.

Java Code:

valuesProcessor:
for(String[] row : values) {
for(String col : row) {
int counterVariable = 0;
if(col == null)
break valuesProcessor;

[Code] .....

View Replies View Related

For Loop Program - Increment Hours By 12 And Double Population By 2 Each Time

Oct 3, 2014

So I need to make a for loop for this problem: A certain type of bacteria doubles its population every twelve hours. If you start with a population of 1000, how many hours will it take for the population to exceed 1,000,000? Output needs to be in table format, such as:

Hours: - Population:
0 ------- 1000
12 ----- 2000
24 ----- 4000

I've created the code, but don't understand how to increment hours by 12 and double the population by 2 each time.

public class Population
{
public static void main (String[] args) {
int hours = 0;
int population;

[Code] ....

View Replies View Related

Display Text In Label From For Loop

Oct 2, 2014

I'm trying to display all the values from a for loop into a label control in my application. Problem is, its only displaying the last number.
 
--------------------------------------------Code----------------------------------------------
 
int lottoNumbers1 = Integer.parseInt(txtLotteryNumbers1.getText());
        int lottoNumbers2 = Integer.parseInt(txtLotteryNumbers2.getText());
        int lottoNumbers3 = Integer.parseInt(txtLotteryNumbers3.getText());
        int lottoNumbers4 = Integer.parseInt(txtLotteryNumbers4.getText());
        int lottoNumbers5 = Integer.parseInt(txtLotteryNumbers5.getText());
        //int lottoNumbers6 = Integer.parseInt(txtLotteryNumbers6.getText());

[Code]...

View Replies View Related

Program Should Exit Repetition Loop And Compute And Display Average Of Valid Grades Entered

Oct 26, 2014

My homework assignment is: Using a do-while statement, write a Java program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should display an appropriate message informing the user that an invalid grade has been entered; a valid grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered. Run the program on your computer and verify the program using appropriate test data.

When I run it, I don't get the correct average. I know that i'm supposed to enter 999 to exit the loop and to display the average, but 999 is being added with the loop. I'm not sure how to make it not do that.

//stephanie
import java.util.Scanner;
public class gradeAverage
{
public static void main(String[] args)

[code]....

View Replies View Related

Java Program Using Nested Loop To Compute / Display Average Of Test Results For Each Experiment

Apr 2, 2015

Four experiments are performed, each consisting of six tests. The number of test results for each experiment is entered by the user. Write a Java program using a nested loop to compute and display the average of the test results for each experiment.

You can run the program by entering the following test results:

Experiment 1 results:23.231.516.927.525.428.6
Experiment 2 results:34.845.227.936.833.439.4
Experiment 3 results:19.416.810.220.818.913.4
Experiment 4 results:36.939.549.245.142.750.6

View Replies View Related

Increment Counter By Recursion

Mar 22, 2015

I have a question related to the code below, that I do not understand. The aim is to count all files and subdirectories in an ArrayList full of files and subdirectories. So I have to count every file and every subdirectory.

The code concerning counting files is clear to me - every time d is of the type file I have to increment n by one. However I thought that I have to do the same thing in case d is a directory, so I would have written the same code for directories.

So what does "n += ((Directory) d).countAllFiles();" mean? In my understanding the method countAllFiles() is applied again on the object Directory ( as Directory is the class that contains this method), but how is n incremented by this? I thought n should be incremented by one as we did with files.

public int countAllFiles() {
int n = 0;
for(SystemFile d : content) {
if(d instanceof File) {
n++;

[Code] ....

View Replies View Related

Increment Array Values

Jul 5, 2014

I'm attempting to increment the values by 1 in an array of objects but I'm not able to increment with the increment operator.

for(int i=1;i<a.length;i++){
a[i].getHour(); hour = hour++;
a[i].getMin(); miinute = minute++;
a[i].getSec(); sec = sec++;
}

It just loops the value of hour without incrementing.

View Replies View Related

How To Call Increment Method

May 26, 2015

I have the following:

public class HistoricalMoment{

private String eventName;
private ClockDisplay timeOfEvent;
public static final int MIDNIGHT_HOUR = 00;
public static final int MINUTE_ZERO = 00;
}

How can I create a method called public void addMinuteToTimeOfEvent() which calls the timeOfEvent's increment() method to add one minute to the timeOfEvent?

View Replies View Related

How Does Post Increment Work

Mar 5, 2014

I have a code issue and I have a below question for the same.Assuming data[] is of type byte[], is the below statement in java -

while((data[p++] & 0x80) == 0x80);

same as -

while ( (data[p] & 0x80) == 0x80 ) { p++; }

I tried with do { p++; } while ( (data[p] & 0x80) == 0x80 ); That also doesn't seem to be the same thing. I am not putting code around this but essentially if I make this change for not using data[p++] code stops working!

View Replies View Related

Increment / Decrement Buttons

Nov 17, 2014

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

import javax.swing.*;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.*;
public class IncrementDecrementPanel extends JPanel {

[Code] ....

View Replies View Related

How To Increment URLs In String

Apr 13, 2013

I need open a url every time I want to refresh system with an update. Each update has a number so my urls are url1, url2, url3, ... I know how to put it in a loop to increment the urls in a String. I do not know how to make it open and close the url in a browser.

public class Test {
public static void main( String args[]) {  
for (int i = 201; i < 300; i++){
System.out.println("http://url=" + i);

[Code]....

View Replies View Related

Increment Array And Got Unexpected Result

Aug 16, 2014

Java Code:

char array[] = new char[10];
int i = 0;
array[i++] = (char)('A' + i);
System.out.println("char for array is: " + array[0]); mh_sh_highlight_all('java');

However, the result for array[0] is B. Not A. from my understanding, the array[0] should be 'A'.

View Replies View Related

GUI Bars - Increment Height By About 10 Pixels

Nov 12, 2014

So I'm trying to make a bar graph, each bar will increment the height by about 10 pixels. To do this, I'm making an array of bars. For some reason, using fillrect I cannot not increase the size more than 10 by 10, if I do, it will only show the 10 by 10. I want the bars to increase in height by 10 each time.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class AssortedAssortmentsOfSorts extends JFrame

[Code] .....

View Replies View Related

Print Range Of Integers From X To Y With Increment Of 5

May 6, 2015

Working on problem in my book in which I have to print a range of integers from x to y with an increment of 5. I thought I had the right idea when writing out this code, but apparently, it only gives a few of the numbers in the range, not all, what I am doing wrong?

import java.util.Scanner;
public class Ranges
{
public static void main (String[] args) {
Scanner input = new Scanner (System.in);
System.out.print("Enter a value for x and y: ");
int x = input.nextInt();

[Code]...

import java.util.Scanner;
public class Ranges
{
public static void main (String[] args) {
Scanner input = new Scanner (System.in);
System.out.print("Enter a value for x and y: ");
int x = input.nextInt();

[Code]...

View Replies View Related

Increment Array And Got Unexpected Result

Aug 16, 2014

char array[] = new char[10];
int i = 0;
array[i++] = (char)('A' + i);
System.out.println("char for array is: " + array[0]);

However, the result for array[0] is B. Not A. from my understanding, the array[0] should be 'A'.

View Replies View Related

JSP :: Increment Variable From JavaScript - Function Is Undefined

Nov 13, 2014

I've a simple logic Code to increment a variable from javascript and Send it back to jsp. I just writing simple code to explain the logic. My code will have scritplets. I know usage of scriptlets is inside jsp is oldest but for the sake of logic.

<!--Jsp Page -->
<%
int i=0;
<input type="button" onclick="fun()"/>
%>
<!-- Script as Follows-->
<script>
function fun(){
<%i++;5>
}
</script>

But My value of i is not incrementing its showing that function is undefined

View Replies View Related

Which Axis To Increment / Decrement With Inclusion Of Speed Variable

Jan 30, 2015

if I move object A to one area of the screen I want object B to to move to object A's location but I also want object B to move at a fixed speed (movement variable). How do I go about doing this? Both the x and y coordinates of object B would need to know the coordinates of object A to calculate the distance between the two and to determine how much of which axis to increment/decrement (if that makes sense?) with the inclusion of the speed variable.In other words I'm just trying to create a homing object.

View Replies View Related

Amount Of Spell User Uses - How To Increment Initial Randomized Output

Feb 16, 2015

I created my own class and it basically randomizes the amount of 'spells' [magic] a user uses (range 1-5). I can't figure out how to increment the initial randomized output to make something like this :

User X : uses 2 spell.
User Y : uses 3 spells.

User X : uses 3 spells. (Taking the randomized 2 and increment by 1)
User Y : uses 4 spells. (Taking the randomized 3 and increment by 1)

My current setup looks like this : First one is the class I created and the second one is just how the output would look like. (seperate by +++++...)

My goal is to create a METHOD to increment it.

public class Spell {
// Max number of spells
private final int MAX_FACE_VALUE = 5;
// Current face value
private int faceValue;
// New instance of Spell
public Spell() {
faceValue = 1;

[Code] ....

+++++++++++++++++++++++++++++++++

public class SpellOutput {
public static void main(String[] args) {
//Object creation
Spell spellCasterOne = new Spell();
Spell spellCasterTwo = new Spell();
Spell spellCasterThree = new Spell();

[code] ....

View Replies View Related

When Remove Increment Operator Program Shows Invalid Statement

Feb 19, 2015

class Brain56
{
public static int[] get()
{
return null;
}
public static void main(String...a)
{
int k=1;
get()[k]++;
}
}

when i remove the increment operator(get()[k]) program shows invalid statement may i know the reason behind it?

View Replies View Related

Calculate Distance Between Two Coordinates And Determine How Much Of Which Axis To Increment / Decrement

Feb 1, 2015

Basically I'm looking for a way to make one object follow another. For example, if I move object A to one area of the screen I want object B to to move to object A's location but I also want object B to move at a fixed speed (movement variable). How do I go about doing this?

Both the x and y coordinates of object B would need to know the coordinates of object A to calculate the distance between the two and to determine how much of which axis to increment/decrement (if that makes sense?) with the inclusion of the speed variable. In other words I'm just trying to create a homing object.

View Replies View Related

Swing/AWT/SWT :: How To Make One Auto-increment MySQL Table Column Invisible

Dec 8, 2014

The problem is that I populate the table with autoincrement primary key. I don't want it to be visible. I have been googling for hours to find no solution. It seems that sql/mysql provides no solution by selecting all table columns except one. So I wonder, how I could overcome this problem. Here is some of my code:

public void tableChanged(TableModelEvent e) {
int row = e.getFirstRow();
int col = e.getColumn();
model = (MyTableModel) e.getSource();
String stulpPav = model.getColumnName(col);
Object data = model.getValueAt(row, col);

[Code] .....

The ID is used in

stmt.addBatch("update finance.fin set " + stulpPav + " = " + duom
+ " where ID = " + studId + ";");

I tried to omit ID from my SELECT statement, I tried to put Date as a first element in data[iEil][0] but neither options were successful. Data hasn't been changed in database. NOW, everything works fine, except I don't want ID column to be visible in my table.

View Replies View Related

Unable To Print A Loop Inside Array Of Greater Size Than Loop Itself

Jan 27, 2015

I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.

int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;

now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.

View Replies View Related

While Loop Inside A For Loop To Determine Proper Length Of Variable

Feb 25, 2014

Here's the code: it's while loop inside a for loop to determine the proper length of a variable:

for (int i = 0; i < num; i++) {
horse[i]=new thoroughbred();
boolean propernamelength = false;
while (propernamelength==false){
String name = entry.getUserInput("Enter the name of horse "

[code]....

I was just wondering what was going on here -- I've initialized the variable, so why do I get this message? (actually the carat was under the variable name inside the parentheses.

View Replies View Related

When Type Quit To Close Outer Loop / It Still Runs Inner Loop

Nov 2, 2014

I have everything else working. My problem is that when i type "quit" to close the outer loop. It still runs the inner loop. The National Bank manager wants you to code a program that reads each clients charges to their Credit Card account and outputs the average charge per client and the overall average for the total number of clients in the Bank.

Hint: The OUTER LOOP in your program should allow the user the name of the client and end the program when the name entered is QUIT.In addition to the outer loop, you need AN INNER LOOP that will allow the user to input the clients charge to his/her account by entering one charge at a time and end inputting the charges whenever she/he enters -1 for a value. This INNER LOOP will performed the Add for all the charges entered for a client and count the number of charges entered.

After INNER LOOP ends, the program calculates an average for this student. The average is calculated by dividing the Total into the number of charges entered. The program prints the average charge for that client, adds the Total to a GrandTotal, assigns zero to the Total and counter variables before it loops back to get the grade for another client.Use DecimalFormat or NumberFormat to format the numeric output to dollar amounts.

The output of the program should something like this:

John Smith average $850.00
Maria Gonzalez average $90.67
Terry Lucas average $959.00
Mickey Mouse course average $6,050.89
National Bank client average $1,987.67

Code:

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String name = "";
int charge = 0;
int count = -1;
int total = 1;
int grandtotal = 0;
int average = 0;
 
[code]....

View Replies View Related







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