I am making a pet veterinary system that has a payment transaction like this.
Whenever I tried to input on 1 jtextfield and calculate it while leave other jtextfield empty, error pops up :
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: empty String
Here is the attached payment transaction menu form
Payment Transaction Menu
How can I get the input and calculate it while ignoring the other text field empty (because for example the customer didn't get the other services, only the consultation service)
Below is my attached code :
double Qty1 = Double.parseDouble(qty_consult.getText());
double Qty2 = Double.parseDouble(qty_dogvac.getText());
double Qty3 = Double.parseDouble(qty_catvac.getText());
double Qty4 = Double.parseDouble(qty_antirabies.getText());
double Qty5 = Double.parseDouble(qty_deworm.getText());
double Qty6 = Double.parseDouble(qty_blood.getText());
double Qty7 = Double.parseDouble(qty_urinalysis.getText());
double Qty8 = Double.parseDouble(qty_skin.getText());
double addup, subTotal, subtotal,tax_ratefee, fee1, fee2, fee3, fee4, fee5, fee6, fee7, fee8;
String consult_fee = String.format("%.2f", price_consultfee);
price_consult.setText(consult_fee);
String vac_fee = String.format("%.2f", price_vacfee);
price_vac.setText(vac_fee);
String vac2_fee = String.format("%.2f", price_vac2fee);
price_vac2.setText(vac2_fee);
String rabies_fee = String.format("%.2f", price_rabiesfee);
price_rabies.setText(rabies_fee);
String deworm_fee = String.format("%.2f", price_dewormfee);
price_deworm.setText(deworm_fee);
String cbc_fee = String.format("%.2f", price_cbcfee);
price_cbc.setText(cbc_fee);
String urine_fee = String.format("%.2f", price_urinefee);
price_urine.setText(urine_fee);
String skin_fee = String.format("%.2f", price_skinfee);
price_skin.setText(skin_fee);
fee1 = Qty1 * price_consultfee;
fee2 = Qty2 * price_vacfee;
fee3 = Qty3 * price_vac2fee;
fee4 = Qty4 * price_rabiesfee;
fee5 = Qty5 * price_dewormfee;
fee6 = Qty6 * price_cbcfee;
fee7 = Qty7 * price_urinefee;
fee8 = Qty8 * price_skinfee;
String sub1 = String.format("%.2f", fee1);
sub_consult.setText(sub1);
String sub2 = String.format("%.2f", fee2);
sub_vac.setText(sub2);
String sub3 = String.format("%.2f", fee3);
sub_vac2.setText(sub3);
String sub4 = String.format("%.2f", fee4);
sub_anti.setText(sub4);
String sub5 = String.format("%.2f", fee5);
sub_deworming.setText(sub5);
String sub6 = String.format("%.2f", fee6);
sub_cbc.setText(sub6);
String sub7 = String.format("%.2f", fee7);
sub_urine.setText(sub7);
String sub8 = String.format("%.2f", fee8);
sub_skin.setText(sub8);
subTotal = fee1 + fee2+ fee3+ fee4 + fee5 + fee6 + fee7 + fee8;
tax_ratefee = (subTotal * taxrate)/100;
//========================Tax=========================//
String subTax = String.format("%.2f", tax_ratefee);
txt_tax.setText(subTax);
//======================SubTotal======================//
String subTotalAll = String.format("%.2f", subTotal);
sub_total.setText(subTotalAll);
//====================OverallTotal=====================//
addup = subTotal + tax_ratefee;
String total = String.format("%.2f", addup);
txt_total.setText(total);
//=====================DateandTime=======================//
Calendar timer = Calendar.getInstance();
timer.getTime();
SimpleDateFormat intime = new SimpleDateFormat ("HH:mm:ss");
txt_time.setText(intime.format(timer.getTime()));
SimpleDateFormat indate = new SimpleDateFormat ("dd-MMM-yyyy");
txt_date.setText(indate.format(timer.getTime()));
I tried doing this :
if (qty_consult.getText().equals("")){
JOptionPane.showMessageDialog(null,"Empty Field/s");
}else {
double Qty1 = Double.parseDouble(qty_consult.getText());
fee1 = Qty1 * price_consultfee;
String consult_fee = String.format("%.2f", price_consultfee);
price_consult.setText(consult_fee);
String sub1 = String.format("%.2f", fee1);
sub_consult.setText(sub1);
subTotal = fee1;
tax_ratefee = (subTotal * taxrate)/100;
//========================Tax=========================//
String subTax = String.format("%.2f", tax_ratefee);
txt_tax.setText(subTax);
//======================SubTotal======================//
String subTotalAll = String.format("%.2f", subTotal);
sub_total.setText(subTotalAll);
//====================OverallTotal=====================//
addup = subTotal + tax_ratefee;
String total = String.format("%.2f", addup);
txt_total.setText(total);
//=====================DateandTime=======================//
Calendar timer = Calendar.getInstance();
timer.getTime();
SimpleDateFormat intime = new SimpleDateFormat ("HH:mm:ss");
txt_time.setText(intime.format(timer.getTime()));
SimpleDateFormat indate = new SimpleDateFormat ("dd-MMM-yyyy");
txt_date.setText(indate.format(timer.getTime()));
and it calculated the input perfectly and after that error of empty string pop-ups again. Am I doing something wrong here?
when working with user input you have to be ready to expect anything, the user always find a way to break your code, so I would recommend you to create a kind of a utility method for accessing and parsing the input. For instance:
private static double getNumberInput(JTextField field, double defaultValue){
String textInput = field.getText();
//Sorry, don't recall if getText can return a null value
//just making sure that we dont have a NullPointerException
//this part can be removed if getText never returns null
texInput = textInput == null? "" : textInput.trim(); //Make sure you trim the value
if("".equals(textInput)){
return defaultValue;
}
try{
return Double.parse(textInput);
}catch(NumberFormatException ex){
//Invalid input
return defaultValue;
}
}
This way you can reuse the method and be sure that when you are trying to get the value inside the field, you always have a value.
double Qty1 = getNumberInput(qty_consult, 0f);
double Qty2 = getNumberInput(qty_dogvac, 0f);
double Qty3 = getNumberInput(qty_catvac, 0f);
This way you'll never have a java.lang.NumberFormatException again.
Related
I have tested the numbers and they hold the correct values but it is printing out the end result completely wrong. E.X: If I put 2/4, it outputs 1
Here is my code:
import java.util.Scanner;
public class FractionConverter {
public static void main(String[] args) {
System.out.println("Welcome To The JEM Fraction Converter!\n");
Scanner sc = new Scanner(System.in);
String num = "0", choice;
System.out.println("Would You Like To Convert From 'Fraction - Decimal'(a) or 'Decimal - Fraction'(b)?");
choice = sc.nextLine();
if (choice.equalsIgnoreCase("a")) {
System.out.println("Please Enter A Fraction (x/y)");
num = sc.nextLine();
String[] parts = num.split("/");
String numerator = parts[0];
String denominator = parts[1];
double result = Double.parseDouble(numerator);
double result2 = Double.parseDouble(numerator);
System.out.println("\n" + numerator + "/" + denominator + " In Decimal Form Is: " + (result/result2));
}
}
}
Appreciate the help!
Replace this line:
double result2 = Double.parseDouble(numerator);
with this:
double result2 = Double.parseDouble(denominator);
double result = Double.parseDouble(numerator);
double result2 = Double.parseDouble(numerator);
... I suppose is a copy/paste problem, isn't it? (both times numerator)
I'm writing a program that converts units (ex. oz & lb) to new units of measurement (g & kg). I was going to have the user to input the unit they want to convert from and the value of the original unit. I also set constants to convert the selected units. What I'm having an issue with is using a switch statement to determine what conversion I should use (oz ---> g, oz --->, etc).
Here's the code:
System.out.print("Convert from: ");
String origMeasure = input.nextLine();
System.out.print("Convert to: ");
String newMeasure = input.nextLine();
System.out.print("Value: ");
double value = input.nextDouble();
double newValue = 0;
final double OZ_TO_G = 28.3;
final double OZ_TO_KG = 0.028;
final double LB_TO_G = 453.6;
final double LB_TO_KG = 0.045;
final double IN_TO_MM = 25.4;
final double IN_TO_CM = 2.54;
final double IN_TO_M = 0.0254;
final double FT_TO_MM = 304.8;
final double FT_TO_CM = 30.48;
final double FT_TO_M = 0.3048;
final String OZ = " oz";
final String LB = " lb";
final String IN = " in";
final String FT = " ft";
final String G = " g";
final String KG = " kg";
final String MM = " mm";
final String CM = " cm";
final String M = " m";
switch(origMeasure){
case(OZ):
newValue = (value * OZ_TO_G);
break;
}
System.out.println(value + origMeasure + "=" + newValue + newMeasure);
}
}
Concatinate the two strings together and use that as your case statement. So if the user inputs oz for the initial measurement, and then g for the final measurement, you will have switch(initial + final) to yield: ozg.
Have your case statement check for each:
String orig = input.next();
String end = input.next();
switch(orig + end){
case "ozg": //DO MATHEMETICAL FUNCTION HERE TO GET RESULT OF OZ --> G
}
}
You could use a input concatenation + dictionary to do this without a switch statement.
Dictionary<string, float> conversions = new Dictionary<string, float>();
conversion.add("OZ_TO_KG", 28.3);
System.out.print("Convert from: ");
String origMeasure = input.nextLine();
System.out.print("Convert to: ");
String newMeasure = input.nextLine();
System.out.print("Value: ");
double value = input.nextDouble();
string conversion = origMeasure + "_TO_" + newMeasure;
float rate = conversions[conversion];
double newValue = value * rate;
You have to validate if the conversion exists in order to not raise Exceptions.
I suggest you break down your code , in different classes one for each kind of measurement
1. One For Height,Weight etc ..(This would break your problem down)
Each of these classes may have a map , which would hold conversion unit eg,
kg-lb(key) -- > 2.20462(value)
m-cm --> 100 etc
You can put in a Parser which would parse the user input. User input can be in the format like ( 10 kg to lb) . parse the user input and create keys(kg-lb) to be used with map and just multiply the conversion unit
If this utility is something that you intend to extend and maintain in the future, I would suggest that you use enums and separate the conversion into two steps through a common base unit:
public enum UnitType
{
WGT("Weight"),
DST("Distance");
public final String title;
UnitType(String pTitle)
{
title = pTitle;
}
}
public enum Unit
{
//Weight Units: base unit for all is GM
GM(UnitType.WGT, BigDecimal.ONE, "Grams"),
KG(UnitType.WGT, new BigDecimal("1000"), "Kilograms"),
MG(UnitType.WGT, new BigDecimal("0.001"), "Milligrams"),
OZ(UnitType.WGT, new BigDecimal("28.3"), "Ounces"),
LB(UnitType.WGT, (new BigDecimal("16")).multiply(OZ.baseFactor), "Pounds"),
//Distance Units: base unit for all is MTR
MTR(UnitType.DST, BigDecimal.ONE, "Meters"),
MM(UnitType.DST, new BigDecimal("0.001"), "Millimeters"),
CM(UnitType.DST, new BigDecimal("0.01"), "Centimeters"),
KM(UnitType.DST, new BigDecimal("1000"), "Kilometers"),
FT(UnitType.DST, new BigDecimal("0.3048"), "Feet"),
YD(UnitType.DST, (new BigDecimal("3")).multiply(FT.baseFactor), "Yards"),
IN(UnitType.DST, FT.baseFactor.divide(new BigDecimal("12"), 10, BigDecimal.ROUND_HALF_UP), "Inches");
public final UnitType unitType;
public final BigDecimal baseFactor;
public final String title;
Unit(UnitType pUnitType, BigDecimal pBaseFactor, String pTitle)
{
unitType = pUnitType;
baseFactor = pBaseFactor;
title = pTitle;
}
public BigDecimal convert(Unit pTargetUnit, BigDecimal pValue, int pScale)
{
if (pTargetUnit.unitType != unitType)
{
throw new IllegalArgumentException(getErrorMsg(this, pTargetUnit));
}
return pValue.multiply(baseFactor).divide(pTargetUnit.baseFactor, pScale, BigDecimal.ROUND_HALF_UP);
}
private static String getErrorMsg(Unit pSourceUnit, Unit pTargetUnit)
{
StringBuilder sb = new StringBuilder("Cannot convert ");
sb.append(pSourceUnit.unitType.title).append(" (").append(pSourceUnit.title).append(") to ");
sb.append(pTargetUnit.unitType.title).append(" (").append(pTargetUnit.title).append(")");
return sb.toString();
}
}
So usage might look something like this:
public class UnitConverter
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
while (true)
{
System.out.print("Convert from: ");
String sourceUnitName = scanner.next().toUpperCase();
if (sourceUnitName.equals("EXIT"))
{
break;
}
Unit sourceUnit = Unit.valueOf(sourceUnitName);
System.out.println("Source unit: " + sourceUnit.title + System.lineSeparator());
System.out.print("Convert to: ");
String targetUnitName = scanner.next().toUpperCase();
Unit targetUnit = Unit.valueOf(targetUnitName);
System.out.println("Target unit: " + targetUnit.title + System.lineSeparator());
System.out.print("Value: ");
BigDecimal sourceValue = new BigDecimal(scanner.next());
BigDecimal targetValue = sourceUnit.convert(targetUnit, sourceValue, 10);
System.out.println(sourceValue.toString() + " " + sourceUnit.title + " = " + targetValue.toString() + " " + targetUnit.title);
}
}
}
This approach converts in two steps: 1) source unit to common base unit, 2) common base unit to target unit. Without converting through a common base unit, anything other than a very limited number of units and types quickly devolves into an unmaintainable Cartesian product of all-to-all conversion factors
I was wondering if someone could tell me
1. why, when i input weightNumber with a decimal place, weightConverted doesn't convert it to the whole number, even though I create variable for it?
2. how could i improve this "program" in any way, THANK YOU !!
here is the problem:
code:
import java.util.Scanner;
public class cofee {
public static void main (String []args){
double weightNumber = 0;
String packageType = "";
String serviceType ="";
double totalFee = 0;
double weightConverted = Math.round(weightNumber); // <- this is the problem, should i put it somewhere else?
final double LETTERCOSTP = 12.00;
final double LETTERCOSTS = 10.50;
final double BOXCOSTP = 15.75;
final double BOXCOSTS = 13.75;
final double BOXWEIGHTP = 1.25;
final double BOXWEIGHTS = 1.00;
// input
Scanner input = new Scanner(System.in);
System.out.print("Enter package type (letter/box): ");
packageType = input.nextLine().toLowerCase();
System.out.print("Enter type of service (standard/priority): ");
serviceType = input.nextLine().toLowerCase();
switch(packageType)
{
case "letter":
System.out.print("Enter the weight in ounces: ");
weightNumber = input.nextDouble();
break;
case "box":
System.out.print("Enter the weight in pounds: ");
weightNumber = input.nextDouble();
break;
default:
System.out.print("WRONG PACKAGE TYPE !!!");
}
// letter
if (packageType.equals("letter") && serviceType.equals("priority"))
{
totalFee = LETTERCOSTP;
}
if (packageType.equals("letter") && serviceType.equals("standard"))
{
totalFee = LETTERCOSTS;
}
// box
if (packageType.equals("box") && serviceType.equals("priority"))
{
totalFee = BOXCOSTP + ((weightConverted - 1.0) * BOXWEIGHTP);
}
if (packageType.equals("box") && serviceType.equals("standard"))
{
totalFee = BOXCOSTS + ((weightConverted - 1.0) * BOXWEIGHTS);
}
// display
System.out.println("The fee is € "+ totalFee + " for a package with");
System.out.println("\tType: "+packageType);
System.out.println("\tService: "+serviceType);
System.out.println("\tOunces: "+weightConverted);
}
}
The line double weightConverted = Math.round(weightNumber); will call round() with the value of weightNumber, which is 0, so it rounds 0 to... well... 0, and assigns it to weightConverted.
I'm trying to learn how to code in python, but am having trouble on finding ways to create custom classes online. I wrote a program in java and I am trying to convert it in python. I think I have the custom class down (I'm not sure), and I'm definitely having trouble with the driver.
my custom class (python):
class CostCalculator:
__item = ""
__costOfItem = 0.0
__tax = 0.0
__tip = 0.0
def set_item(self, item):
self.__item = item
def get_name(self):
return self.__item
def set_costOfItem(self, costOfItem):
self.__costOfItem = costOfItem
def get_costOfItem(self):
return self.__costOfItem
def get_tax(self):
__tax = self.__costOfItem * .0875
return self.__tax
def get_tip(self):
__tip = self.__costOfItem * .15
return self.__tip
My python driver attempt
import sys
from CostCalculator import CostCalculator
item = ""
cost = 0.0
totalTip = 0.0
totalTax = 0.0
overallTotal = 0.0
subtotal = 0.0
print("Enter the name of 3 items and their respective costs to get the total value of your meal")
print ("\n Enter the name of your first item: ")
item = sys.stdin.readline()
print("How much is " + item + "?")
cost = sys.stdin.readLine()
My java custom class and driver:
public class TotalCost
{
String item = " ";
double costOfItem = 0;
double tax = 0;
double tip = 0;
public void setItem ( String i )
{
item = i;
}
public String getItem()
{
return item;
}
public void setCostOfItem ( double c )
{
costOfItem = c;
}
public double getCostOfItem ()
{
return costOfItem;
}
public double getTax ()
{
double tax = costOfItem * .0875;
return tax;
}
public double getTip()
{
double tip = costOfItem * .15;
return tip;
}
public String toString()
{
String str;
str = "\nMeal: " + getItem() +
"\nCost of " + getItem() + ": " + getCostOfItem() +
"\nTax of " + getItem() + ": " + getTax() +
"\nTip of " + getItem() + ": " + getTip();
return str;
}
}
import java.util.Scanner;
public class Driver
{
public static void main (String args[])
{
Scanner input = new Scanner (System.in);
String item ;
double cost ;
double totalTip = 0;
double totalTax = 0;
double OverallTotal = 0;
double subtotal;
TotalCost a = new TotalCost ();
TotalCost b = new TotalCost ();
TotalCost c = new TotalCost ();
System.out.println("Enter the name of 3 items and their respective costs to get the total value of your meal");
System.out.println("Enter the name of your first item: ");
item = input.nextLine();
a.setItem ( item );
System.out.println("How much is " + a.getItem() + "?" );
cost = input.nextDouble();
a.setCostOfItem (cost);
input.nextLine();
System.out.println("Enter the name of your second item: ");
item = input.nextLine();
b.setItem (item);
System.out.println("How much is a " + b.getItem() + "?");
cost = input.nextDouble();
b.setCostOfItem (cost);
input.nextLine();
System.out.println("Enter the name of your third item: ");
item = input.nextLine();
c.setItem (item);
System.out.println("How much is a " +c.getItem() + "?" );
cost = input.nextDouble();
c.setCostOfItem(cost);
System.out.println(a + "\n" + b + "\n" + c);
subtotal = a.getCostOfItem() + b.getCostOfItem() + c.getCostOfItem();
totalTip = a.getTip() + b.getTip() + c.getTip();
totalTax = a.getTax() + b.getTax() + c.getTax();
OverallTotal = subtotal + totalTip + totalTax;
System.out.println("\n\tSubtotal: $" + subtotal);
System.out.println("\tTax: $" + totalTax);
System.out.println("\tTip: $" + totalTip);
System.out.println("\tMeal Total: $" + OverallTotal);
}
}
In Python, there is no notion of public vs private, everything is public so you do not need setters or getters.
What you do need is the __init__ function, which is similar to a constructor. You can initialize the member variables here so they are not static and shared among all instances of your class. You can also add default arguments so you many pass in any, all, or none of the arguments to the class upon instantiation.
class CostCalculator:
def __init__(self, item = "", cost = 0.0):
self.item = item
self.cost = cost
def __str__(self):
return 'Meal: {item}\nCost of {item}: {cost}\nTax of {item}: {tax}\nTip of {item}: {tip}'.format(item = self.item, cost = self.cost, tax = self.calc_tax(), tip = self.calc_tip())
def calc_tax(self):
return self.cost * 0.0875
def calc_tip(self):
return self.cost * 0.15
def calc_total(self):
return self.cost + self.calc_tax() + self.calc_tip()
Then you can create an instance of this class. Again note that you can directly access the members without setters or getters, for better or worse ;)
>>> c = CostCalculator('cheese', 1.0)
>>> c.item
'cheese'
>>> c.calc_tip()
0.15
Now you can invoke print on your object
>>> c = CostCalculator('cheese', 1.0)
>>> print(c)
Meal: cheese
Cost of cheese: 1.0
Tax of cheese: 0.085
Tip of cheese: 0.15
Lastly, the way you accept input from a user is generally via input (although messing around with stdin isn't necessarily wrong)
>>> tax = input('how much does this thing cost? ')
how much does this thing cost? 15.0
>>> tax
'15.0'
Another nice feature of Python is the built-in #property decorator,
which helps to replace setters and getters from Java. The #property
decorator allows you to create early versions of a class using property
attributes (i.e., self.tax). If it later becomes necessary to perform
calculations on the attribute or move it to a calculated attribute, the
#property attribute allows this to be done transparently to any
code that depends on the existing implementation. See example, below.
TAX_RATE = 0.0875
TIP_RATE = 0.15
class CostCalculator(object):
def __init__(self, item='', cost=0):
self.item = item
self.cost = cost
#property
def tax(self):
"""Tax amount for item."""
return self.cost * TAX_RATE
#property
def tip(self):
"""Tip amount for item."""
return self.cost * TIP_RATE
if __name__ == '__main__':
item = CostCalculator('Steak Dinner', 21.50)
assert item.tax == 1.8812499999999999
assert item.tip == 3.225
It is like CoryKramer said, python doesn't encourage use of private staff and you don't need setters and getters. But if you still want in, this might help:
class CostCalculator:
__item = ""
__cost_of_item = 0.0
__tax = 0.0
__tip = 0.0
def set_item(self, item):
self.__item = item
def get_name(self):
return self.__item
def set_cost_of_item(self, cost_of_item):
self.__cost_of_item = float(cost_of_item)
def get_cost_of_item(self):
return self.__cost_of_item
def get_tax(self):
self.__tax = self.__cost_of_item * 0.0875
return self.__tax
def get_tip(self):
self.__tip = self.__cost_of_item * 0.15
return self.__tip
item = ""
cost = 0.0
totalTip = 0.0
totalTax = 0.0
overallTotal = 0.0
subtotal = 0.0
print("Enter the name of 3 items and their respective costs to get the total vaalue of your meal")
ls = [CostCalculator(), CostCalculator(), CostCalculator()]
for entry in ls:
print "Enter the name of your item:"
item = raw_input()
entry.set_item(item)
print("How much is " + entry.get_name() + "?")
cost = raw_input()
entry.set_cost_of_item(cost)
subtotal = sum([x.get_cost_of_item() for x in ls])
totalTip = sum([x.get_tip() for x in ls])
totalTax = sum([x.get_tax() for x in ls])
I'm working on an assignment in which I use scanners to read lines and tokens of a .txt file. I need to do some conversions and rearrange a few strings, which I have done using some helper methods. The problem is that the code is only working for every other line that it reads from the file. I think I may have messed something up somewhere in the beginning of the code. Any hints or tips on what I would need to modify? Here's what I have thusfar:
public static void main(String[] args) throws FileNotFoundException {
Scanner input = new Scanner(new File("PortlandWeather2013.txt"));
while (input.hasNextLine()) {
String header = input.nextLine();
System.out.println(header);
Scanner input2 = new Scanner(header);
while (input2.hasNextLine()){
String bottomHeader = input.nextLine();
System.out.println(bottomHeader);
String dataLines = input.nextLine();
Scanner linescan = new Scanner(dataLines);
while (linescan.hasNext()){
String station = linescan.next();
System.out.print(station+ " ");
String wrongdate = linescan.next();
String year = wrongdate.substring(0,4) ;
String day = wrongdate.substring(6);
String month = wrongdate.substring(4,6);
System.out.print(month + "/" + day + "/" + year);
double prcp = linescan.nextDouble();
System.out.print("\t "+prcpConvert(prcp));
double snwd = linescan.nextDouble();
System.out.print("\t " + snowConvert(snwd));
double snow = linescan.nextDouble();
System.out.print("\t" + snowConvert(snow));
double tmax = linescan.nextDouble();
System.out.print("\t" + tempConvert(tmax));
double tmin = linescan.nextDouble();
System.out.println("\t" + tempConvert(tmin));
}
}
}
}
public static double prcpConvert(double x){
double MM = x/1000;
double In = MM * 0.039370;
double rounded = Math.round(In * 10)/10;
return rounded;
}
public static double snowConvert(double x){
double In = x * 0.039370;
double rounded = Math.round(In * 10)/10;
return rounded;
}
public static double tempConvert(double x){
double celsius = x/10;
double fahrenheit = (celsius *9/5)+32;
double rounded = Math.round(fahrenheit *10)/10;
return rounded;
}
nextLine() doesn't just fetch the last line, it also advances a line. Before your second loop you are calling nextLine() twice causing you to advance two lines each iteration of the loop.
You can fix your problem by setting dataLines = bottomHeader instead of calling nextLine() again.