I'm trying to increment the values inside of an array that corresponds to how many times that discount has been used. The incrementation works well if the discount is 0% (discount = 1.0) but for 20%, 30%, and 40% (discount is 0.8, 0.7, 0.6 respectively) the related index in the counts array is incremented by 2. Finally, if discount = 0.5 counts[4] is incremented by 8. I feel like it has something to do with what iteration of the for loop I'm in but I can't figure it out.
Heres the class that I think holds the problem:
/*
* 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.
*/
package softwaresales;
/**
*
* #author python
*/
public class SoftwareSales {
private int unitsSold;
private final double UNIT_PRICE = 99.0;
private final int[] UNITS_LOW_RANGES = {1, 10, 20, 50, 100};
private final double[] DISCOUNTS = {1.0, 0.8, 0.7, 0.6, 0.5};
private static int[] counts = {0, 0, 0, 0, 0};
SoftwareSales(int u){
unitsSold = u;
}
public int getUnitsSold(){
return unitsSold;
}
public double getDiscount(){
double discount = 1;
for (int i = 0; i < 4; i++){
if((unitsSold >= UNITS_LOW_RANGES[i]) &&
(unitsSold < UNITS_LOW_RANGES[i+1])){
counts[i] += 1;
discount = DISCOUNTS[i];
}
else if (unitsSold >= 100){
counts[4] += 1;
discount = DISCOUNTS[4];
System.out.print("*");
}
}
return discount;
}
public double getCost(){
return unitsSold * UNIT_PRICE * getDiscount();
}
public int[] getCounts(){
return counts;
}
}
Here's a sample input :
13
31
115
101
96
8
29
103
27
129
And the related output:
Units sold: 13
Discount: 19.999999999999996%
Price: $1029.6000000000001
Units sold: 31
Discount: 30.000000000000004%
Price: $2148.2999999999997
Units sold: 115
Discount: 50.0%
Price: $5692.5
Units sold: 101
Discount: 50.0%
Price: $4999.5
Units sold: 96
Discount: 40.0%
Price: $5702.4
Units sold: 8
Discount: 0.0%
Price: $792.0
Units sold: 29
Discount: 30.000000000000004%
Price: $2009.6999999999998
Units sold: 103
Discount: 50.0%
Price: $5098.5
Units sold: 27
Discount: 30.000000000000004%
Price: $1871.1
Units sold: 129
Discount: 50.0%
Price: $6385.5
=================
= =
= DISCOUNTS =
= =
=================
0% discounts: 1
20% discounts: 2
30% discounts: 6
40% discounts: 2
50% discounts: 32
As you can see there is only one instance where a 0% discount was given which is represented in the output. There is also only one instance each of 20% and 40% discounts but the output shows 2 for each, similar to the 30% discount. Also there was 4 instances of a 50% discount being given, but as you can see the array was incremented 32 times...
Here's my main program where I call getDiscount().
/*
* 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.
*/
package softwaresales;
import java.io.*;
import java.util.Scanner;
/**
*
* #author python
*/
public class SofwareSalesDriver {
/**
* #param args the command line arguments
* #throws java.io.IOException
*/
public static void main(String[] args) throws IOException {
String file_location;
Scanner kb = new Scanner(System.in);
CreateInputFile inputs = new CreateInputFile();
System.out.println("Enter the PATH to the folder where you would like" +
" the in/out files: ");
System.out.println("\nExamples:\nLinux: /home/%USER_NAME%/Documents/" +
"\nor Windows: C:\\\\users\\\\%USER_NAME%\\\\Documents\\\\");
System.out.print("\nEnter PATH: ");
file_location = kb.nextLine();
String infile = file_location + "Inputs.txt";
String outfile = file_location + "Outfile.txt";
File file = new File(outfile);
FileWriter writer = new FileWriter(file);
int unitsSold = 0;
SoftwareSales customer = new SoftwareSales(unitsSold);
int[] counts = customer.getCounts();
inputs.createInputFile(file_location);
Scanner fileLine = new Scanner(new File(infile));
while (fileLine.hasNextInt()){
unitsSold = fileLine.nextInt();
customer = new SoftwareSales(unitsSold);
writer.write("Units sold: " + unitsSold + "\n" +
"Discount: " + (1 - customer.getDiscount())*100 + "%\n" +
"Price: $" + customer.getCost() + "\n\n");
}
writer.write("=================\n= =\n" +
"= DISCOUNTS =\n= =\n" +
"=================\n" +
"0% discounts: "+ counts[0] / 2 +
"\n20% discounts: " + counts[1] +
"\n30% discounts: " + counts[2] +
"\n40% discounts: " + counts[3] +
"\n50% discounts: " + counts[4] + "\n\n");
writer.close();
}
}
If I get your code correctly, the error is related to the if-statement in your for loop. You should have the check before the for loop, otherwise you increment the counter multiple times per loop if unitsSold >= 100 because the else statement is called for each loop iteration.
if (unitsSold >= 100){
counts[4] += 1;
discount = DISCOUNTS[4];
System.out.print("*");
} else {
for (int i = 0; i < 4; i++){
if((unitsSold >= UNITS_LOW_RANGES[i]) &&
(unitsSold < UNITS_LOW_RANGES[i+1])){
counts[i] += 1;
discount = DISCOUNTS[i];
}
}
}
The reason for the double counting of some numbers is due to that function:
public double getCost(){
return unitsSold * UNIT_PRICE * getDiscount();
}
Here, you call getDiscount() again, which will again trigger the whole process and add the respective value to counts[i].
I would recommend you the following: Instead of calculating the discount twice, you could just pass the discount as a parameter like getCost(double discount).
This way, you prevent calling this function twice.
Just a quick notice at the end: Normally, you should refrain from performing modifications of global variables in getters if you do not intend to actually count the number of getter-calls. Probably, the discount calculation could be moved to the constructor and the getDiscount() only returns the discount that has been previously calculated in the constructor. But that just as a side note.
Related
I am trying to figure out how to use the string.format feature into the return statement. Each line has to be a system out? so that means ill have 3 seperate system out?
/*
0 - 4 miles = $2
5 - 15 miles = $5
16 - 25 miles = $10
26 - 50 miles = $15
More than 50 miles = $20
WRITE A PROGRAM THAT CALCULATES TOTAL COST OF USER'S ITEMS
YOUR OUTPUT SHOULD BE FORMATTED AS SEEN BELOW!!
Product Qty Price Miles Total
---- --- ----- ----- -----
Rice 20 5.0 10.0 105.0
Thank you. Come Again!!!
*/
Above is the format that is wanted, I was able to create a method that calculates and returns the correct values, i just need to format the string variable receipt.
public class Test {
public static void main(String[] args) {
methods Rice = new methods();
methods Beans = new methods();
System.out.println(Rice.getTotal("Rice",20,5.0,10));
System.out.println("\n"+ Beans.getTotal("Cake",200,5.75,102.78));
}
}
public class methods {
int qty;
double price;
double miles;
double total;
int i;
String product;
String receipt;
public String getTotal(String product, int qty, double price, double miles){
// 0 - 4 miles = $2
// 5 - 15 miles = $5
// 16 - 25 miles = $10
// 26 - 50 miles = $15
// More than 50 miles = $20
this.qty = qty;
this.price=price;
this.miles = miles;
this.total = 0;
this.product = product;
for(i = 0; i < miles; i++){
if(i < 5){
total = qty * price + 2;
}
else if(i > 4 && i < 16){
total = qty * price + 5;
}
else if(i > 15 && i < 26){
total = qty * price + 10;
}
else if(i > 25 && i < 51){
total = qty * price + 15;
}
else if(i > 50 ){
total = qty * price + 20;
}
}
//return
}
}
I commented out the return statement where the code should go. I can use print method or string.format method.
Hi im having trouble with this Cash Register program im writing. Specifically the output2 method. Im attempting to to find a way to output the specific dollar amounts the user will receive in change without writing it as:
system.out.println("Your change will be "+hundred+" on hundred dollar bills
"+fifty+" fifty dollar bills ETC");
But instead include the dollar value if it fits with the change the user will receive.
I hope this wasnt too confusing to read.
int ranNum, hundred, fifty, twenty, ten, five, one, quarter, dime, nickel, penny;
double original, discount, savings, salesprice, tax, total, payment, change, quarterV = .25, dimeV = .10, //V as in value
nickelV = .05, pennyV = .01;
DecimalFormat percent = new DecimalFormat("0%");
DecimalFormat money = new DecimalFormat("$0.00");
public void input()
{
System.out.println("Hello, this program will ask you for a price of an item you would like to purchase");
System.out.println("and return a random discount from 5-75 (multiple of 5). Then return the following:");
System.out.println("original price, discount percent, discount amount, sales price, tax and total price with 7% tax.\n");
System.out.println("Please give me the price of an item you would like to purchase");
original = scan.nextDouble();
scan.nextLine();
}
public void calculations()
{
//This will be used to find the random discount given to the user:
ranNum = random.nextInt(15)+1;
discount = ((ranNum*5)*.10)*.10;
//This will be used to find the amount the user will save:
savings = (discount*original);
//This will be used to find the salesprice of the item being purchased:
salesprice = original - savings;
//This will be used to find the total price of the item after 7% tax deductions
tax = (salesprice*7)/100;
//This will be used to find the final total the customer must pay
total = salesprice + tax;
}
public void change()
{
change = payment - total;
hundred = (int) Math.floor(change/100);
fifty = (int) Math.floor((change - hundred * 100)/50);
twenty = (int) Math.floor((change - hundred * 100 - fifty * 50) / 20);
ten = (int) Math.floor((change - hundred * 100 - fifty * 50 - twenty * 20) / 10);
five = (int) Math.floor((change - hundred * 100 - fifty * 50 - twenty * 20 - ten * 10) / 5);
one = (int) Math.floor((change - hundred * 100 - fifty * 50 - twenty * 20 - ten * 10 - five * 5) / 1);
quarter = (int) Math.floor((change - hundred * 100 - fifty * 50 - twenty * 20 - ten * 10 - five * 5 - one * 1)
/ quarterV);
dime = (int) Math.floor((change - hundred * 100 - fifty * 50 - twenty * 20 - ten * 10 - five * 5 - one * 1
- quarter * quarterV) / dimeV);
nickel = (int) Math.floor((change - hundred * 100 - fifty * 50 - twenty * 20 - ten * 10 - five * 5 - one * 1
- quarter * quarterV - dime * dimeV) / nickelV);
penny = (int) Math.floor((change - hundred * 100 - fifty * 50 - twenty * 20 - ten * 10 - five * 5 - one * 1
- quarter * quarterV - dime * dimeV - nickel * nickelV) / penny);
}
public void output1()
{
System.out.println("The original price of your item was "+money.format(original));
System.out.println("You will be granted a " +percent.format(discount)+ " discount on your purchase.");
System.out.println("Your discount amount (amount you are saving) is "+money.format(savings)+".");
System.out.println("The sales price of your item is "+money.format(salesprice));
System.out.println("The 7% tax payment will come out to be "+money.format(tax));
System.out.println("Thus your total will be "+money.format(total)+"\n");
System.out.println("How much money are you using to purchase your item?");
payment = scan.nextDouble();
scan.nextLine();
}
public void output2()
{
System.out.println("Your change is");
if (change>=100)
{
System.out.println(hundred+" one hundred dollar bills");
}
else
{
if (change>=50)
{
System.out.println(fifty+" fifty dollar bills");
}
else
{
if (change>=20)
{
System.out.println(twenty+" twenty dollar bills");
}
else
{
if (change>=5)
{
System.out.println(five+" five dollar bills");
}
else
{
System.out.println(one+" one dollar bills");
}
}
}
}
}
public void run()
{
input();
calculations();
output1();
change();
output2();
}
public static void main(String[] args)
{
CashRegister phill = new CashRegister();
phill.run();
}
}
Try this. I only did your cash register for 100, 50, and 20 dollar bills because you can get the hang of it from here. All this code does is go through the highest denomination bill to the lowest, subtracting the number of bills from the amount of change to get the remaining amount of change.
public void output2()
{
int remainder = change; //make a copy of change variable so it remains final.
int count=0;
System.out.println("Your change is");
if(remainder>=100){
hundred = (int)remainder/100;
remainder %= 100;
}
if(remainder>=50){
fifty = (int)remainder/50;
remainder %= 50;
}
if(remainder>=20){
twenty = (int)remainder/20;
remainder %= 20;
}
...
System.out.print(hundred + " one hundred dollar bills,");
System.out.print(fifty + " fifty dollar bills,");
System.out.print(twenty + " twenty dollar bills,");
...
}
This could do the trick
public void output2(){
String changeMessage = "";
double _change = change; //In case you need the change value somewhere else
int numberOfNotesInHundred = (int)(_change / 100);
if (numberOfNotesInHundred > 0){
changeMessage += (numberOfNotesInHundred + " one hundred dollar bills ");
_change = _change % 100;
}
int numberOfNotesInFifty = (int)(_change / 50);
if (numberOfNotesInFifty > 0){
changeMessage += (numberOfNotesInFifty + " fifty dollar bills ");
_change = _change % 50;
}
// And so on for 20, 5 and 1
System.out.println("Your change will be: " + changeMessage);
}
Here is a quick look at the program that I made to give a better example of my question.
Loop code
public void scheme1(int d) {
// first modification
if (mark<=20){
System.out.print("\nBecause mark under 20 mark stays as its original value. mark="+mark);
return;
}
int total = mark;
int finalMark=20;
System.out.print("Scheme 1"+"\n");
// Loop
for(int loopParameter = START_CONDITION;
loopParameter <= d;loopParameter++){
System.out.print("(" + loopParameter + ") " + total + " ");
total = total + constantDiffSch1;
// second modification
if (total < 40){
System.out.print("\nThis work can be up to " + loopParameter);
return;
}
// third modification
if (total<=20){
System.out.print("\nBecause mark drops below 20, mark stays as 20. final mark="+ finalMark);
return;
}
} // End
System.out.print("\n\n");
}
This is what my program outputs
Please input mark: 64
Please input number of days to display: 10
Scheme 1
(0) 64 (1) 59 (2) 54 (3) 49 (4) 44
This work can be up to 4 days late before failing.
This is what the output is supposed to be
Please input mark: 64
Please input number of days to display: 10
Scheme 1
(0) 64 (1) 59 (2) 54 (3) 49 (4) 44 (5) 39 (6) 34 (7) 29 (8) 24
This work can be up to 4 days late before failing.
I have to display how many days late the assignment is and calculate the late penaltie (mark -5) I also have to display the number of days needed needed to fail the assigment ( number of days until failure might be larger than the number (d) of days that the user input ) . the failing mark is less than 40.
2nd example (output)
Please input mark: 64
Please input number of days to display: 2
Scheme 1
(0) 64 (1) 59 (2) 54
This work can be up to 4 days late before failing.
I have almost complete my code but this problem is slowing me down.
P.S. I am new at java
here is my full program
LatePenalties calss
public class LatePenalties {
// attributes
private int mark;
private static final int constantDiffSch1 = -5;
private static final double constantDiffSch2 = 0.9;
private static final int START_CONDITION = 0;
// constructors
public LatePenalties(int m) {
mark = m;
}
// methods
public void scheme1(int d) {
// first modification
if (mark<=20){
System.out.print("\nBecause mark under 20 mark stays as its original value. mark="+mark);
return;
}
int total = mark;
int finalMark=20;
System.out.print("Scheme 1"+"\n");
// Loop
for(int loopParameter = START_CONDITION;
loopParameter <= d;loopParameter++){
System.out.print("(" + loopParameter + ") " + total + " ");
total = total + constantDiffSch1;
// second modification
if (total < 40){
System.out.print("\nThis work can be up to " + loopParameter);
return;
}
// third modification
if (total<=20){
System.out.print("\nBecause mark drops below 20, mark stays as 20. final mark="+ finalMark);
return;
}
} // End
System.out.print("\n\n");
}
public void scheme2(int d) {
double total = mark;
System.out.print("\n\nScheme 2"+"\n");
// Loop
for(int loopParameter = START_CONDITION;
loopParameter <= d;loopParameter++){
System.out.print( "(" + loopParameter + ") " );
System.out.printf("%.02f",total);
System.out.print(" ");
total = total * constantDiffSch2;
} // End
System.out.print("\n");
}
}
Main class
import java.util.Scanner;
public class LatePenaltiesUser {
public static void main(String [] args) {
// local variables
Scanner input = new Scanner(System.in);
LatePenalties latePen;
int mark;
int days;
// input
do{
System.out.print("Please input mark (between 0 and 100) --> ");
mark = input.nextInt();
if (( mark < 0 ) | (mark > 100 )){System.out.print("\n" + "Input value outside the range!!!" + "\n");}
}while(( mark < 0 ) | (mark > 100 ));
do{
System.out.print("Please input number of days to display (between 0 and 20) --> ");
days = input.nextInt();
System.out.print("\n");
if (( days < 0 ) | (days > 20 )){System.out.print("Input value outside the range!!!"+ "\n");}
}while(( days < 0 ) | (days > 20 ));
// computation
latePen = new LatePenalties(mark);
latePen.scheme1(days);
latePen.scheme2(days);
}
}
I have to show when the faling mark occurs(at less than 40), but I have to stop the loop at 20 or when the number of days is reached, as I show in the example on what it is expected.
You can use break to come out of the loop as soon as total is less than 40. You can update your scheme1 method as below
public void scheme1(int d) {
int total = mark;
System.out.print("Scheme 1" + "\n");
int days = 0;
// Loop
for (int loopParameter = START_CONDITION; loopParameter <= d; loopParameter++) {
System.out.print("(" + loopParameter + ") " + total + " ");
total = total + constantDiffSch1;
if(total < 40)
break;
days++;
} // End
if (total <= 40) {
System.out.print("\nThis work can be up to " + days +" days late before failing.");
}
System.out.print("\n\n");
}
Please input mark (between 0 and 100) --> 82
Please input number of days to display (between 0 and 20) --> 10
Scheme 1 (0) 82 (1) 77 (2) 72 (3) 67 (4) 62 (5) 57 (6) 52
(7) 47 (8) 42
This work can be up to 8 days late before failing.
You don't need to know your loopParameter to calculate the number of days. You can calculate it like so:
int days = (d - 40) / -constantDiffSch1;
You can use break when you want to quit loop. So:
if (total < 20) break;
And off topic. Don't call loopParameter like that. It is good practice to call it in one symbol (or short word) like i or day. It makes code easier to read and understand.
Java input;
import java.util.*;
public class NetPay3
{
public static void main()
{
// Define Scanner object
Scanner inLine = new Scanner (System.in);
// Define other variables
float pay;
int OneHundredPounds, FiftyPounds, TwentyPounds, FivePounds,
OnePound, FiftyPence, TwentyPence, FivePence, TwoPence, OnePenny;
// Ask for the time in seconds
System.out.print ("Enter Net Pay : ");
pay = inLine.nextFloat();
// Calculate the hours. There are (3600)
// i.e. 60 x 60 seconds in every hour
OneHundredPounds = (int) pay / 100;
// Calculate what is left over and store back into seconds
pay = pay % 100;
// Calculate the minutes. There are 60 seconds
// in a minute.
FiftyPounds = (int) pay / 50;
// Whatever is left over must be the seconds
pay = pay % 50;
// Calculate the hours. There are (3600)
// i.e. 60 x 60 seconds in every hour
TwentyPounds = (int) pay / 20;
// Calculate what is left over and store back into seconds
pay = pay % 20;
// Calculate the hours. There are (3600)
// i.e. 60 x 60 seconds in every hour
FivePounds = (int) pay / 5;
// Calculate what is left over and store back into seconds
pay = pay % 5;
// Calculate the hours. There are (3600)
// i.e. 60 x 60 seconds in every hour
OnePound = (int) pay / 1;
// Calculate what is left over and store back into seconds
pay = pay % 1;
// Calculate the hours. There are (3600)
// i.e. 60 x 60 seconds in every hour
FiftyPence = (int) pay / 2;
// Calculate what is left over and store back into seconds
pay = pay % 2;
// Display the hours, minutes and seconds
System.out.println ("Amount of £100 notes " + OneHundredPounds);
System.out.println ("Amount of £50 notes " + FiftyPounds);
System.out.println ("Amount of £20 notes " + TwentyPounds);
System.out.println ("Amount of £5 notes " + FivePounds);
System.out.println ("Amount of £1 coins " + OnePound);
System.out.println ("Amount of 50p coins " + FiftyPence);
}
}
Screen input and output;
Enter Net Pay : 176.50
Amount of £100 notes 1
Amount of £50 notes 1
Amount of £20 notes 1
Amount of £5 notes 1
Amount of £1 coins 1
Amount of 50p coins 0
Hi relatively new to programming,
having trouble with me modulus and int operators in terms of getting them to function with the correct output on screen, previous syntax's worked correctly bar the 50p, anyone care to shed any light? thanks :)
Try changing FiftyPence = (int) pay / 2; toFiftyPence = (int) (pay / 0.5f);
Here is your code corrected and improved.
Don't use floats here, use integer arithmetic.
import java.util.*;
public class NetPay3 {
public static void main(String[] args) {
// Define Scanner object
Scanner inLine = new Scanner(System.in);
// Define other variables
int pay;
int OneHundredPounds, FiftyPounds, TwentyPounds, FivePounds, OnePound, FiftyPence, TwentyPence, FivePence, TwoPence, OnePenny;
System.out.print("Enter Net Pay : ");
float pay1 = inLine.nextFloat();
pay = (int) (100 * pay1);
OneHundredPounds = (int) pay / 10000;
pay = pay % 10000;
FiftyPounds = (int) pay / 5000;
pay = pay % 5000;
TwentyPounds = (int) pay / 2000;
pay = pay % 2000;
FivePounds = (int) pay / 500;
pay = pay % 500;
OnePound = (int) pay / 100;
pay = pay % 100;
FiftyPence = (int) pay / 50;
pay = pay % 50;
System.out.println("Amount of £100 notes " + OneHundredPounds);
System.out.println("Amount of £50 notes " + FiftyPounds);
System.out.println("Amount of £20 notes " + TwentyPounds);
System.out.println("Amount of £5 notes " + FivePounds);
System.out.println("Amount of £1 coins " + OnePound);
System.out.println("Amount of 50p coins " + FiftyPence);
System.out.println("Leftover pence: " + pay);
}
}
But I would further simplify this to (for example) this program:
import java.util.*;
public class NetPay3 {
public static void main(String[] args) {
Scanner inLine = new Scanner(System.in);
float[] val = new float[]{100, 50, 20, 5, 1, 0.5f, 0.2f, 0.05f, 0.02f, 0.01f};
int pay;
System.out.print("Enter Net Pay : ");
float pay1 = inLine.nextFloat();
pay = (int) (100 * pay1);
for (int i=0; i<val.length; i++){
int m = ((int)(val[i] * 100));
int cnt = pay / m;
String s1 = val[i] < 1 ? " coins: " : " notes: ";
String s2 = val[i] < 1 ? "" : "£";
String s3 = val[i] < 1 ? "p" : "";
String s4 = val[i] < 1 ? m + "" : (m/100) + "";
System.out.println("Amount of " + s2 + s4 + s3 + s1 + cnt);
pay = pay % m;
}
}
}
I am trying to replicate a list of conversions from kg to lbs and vice versa. I've found my desired code for output and functionality, but I am missing something to align my values to the right of the column.
Here is my code:
import java.text.*;
public class KilosTwoColumn {
public static void main(String[] args) {
System.out.println("Kilograms" + "\t" + "Pounds" + "\t" + " | " + "\t" + "Pounds" + "\t" + "Kilograms");
int count = 0;
while (count < 100) {
int kilos = count * 2 + 1;
int pounds2 = (count + 4) * 5;
double pounds = kilos * 2.2;
double kilos2 = pounds2 * .453;
DecimalFormat df = new DecimalFormat("#.#");
//if (count > 1 && count < 98) {
//System.out.println("...");
//break;
//}
System.out.printf("%-17d %.1f | %7d %.2f%n", kilos, pounds, pounds2, kilos2);
count++;
}
}
}
I am also trying to create a break in the list three rows in and resume the last two.
The problem is that you are not specifying a width for the float values, just the number of decimal places.....
For example, consider "%-17d %.1f ..." which will set the second value to be a float value with 1 decimal place, but no indication of how much space to occupy. By changing that to "%-17d %12.1f it will occupy 12 characters, with 1 decimal.
Try something like:
public class KilosTwoColumn {
public static void main(String[] args) {
System.out.printf("%12s %12s | %7s %12s\n", "Kilograms", "Pounds", "Pounds", "Kilograms");
int count = 0;
while (count < 100) {
int kilos = count * 2 + 1;
int pounds2 = (count + 4) * 5;
double pounds = kilos * 2.2;
double kilos2 = pounds2 * .453;
DecimalFormat df = new DecimalFormat("#.#");
//if (count > 1 && count < 98) {
//System.out.println("...");
//break;
//}
System.out.printf("%12d %12.1f | %7d %12.1f\n", kilos, pounds, pounds2, kilos2);
count++;
}
}
}
For me, the above process outputs:
Kilograms Pounds | Pounds Kilograms
1 2.2 | 20 9.1
3 6.6 | 25 11.3
....
199 437.8 | 515 233.3