Question: When i run this code and enter information on out put i get an error. Prof feedback was Your output did not execute but you
When i run this code and enter information on out put i get an error. Prof feedback was "Your output did not execute but you started your program well.The reason your program is giving you an error is because of your format." how may i fix this issue?
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Scanner;
public class Expense {
String name;
double airlinefare,dolltoconvert;
int noofnight;
public static void main(String[] args) {
// TODO Auto-generated method stub
Expense c= new Expense();
c.ask();
c.show();
}
//convert dollar to CUC.
public double convertdollar() {
double pen=dolltoconvert*0.10;
double tax=dolltoconvert*0.03;
return dolltoconvert-(pen+tax);
}
//calculate hotel charge.
public double hotelcharge(){
return noofnight*256.10;
}
//calculate total
public double total() {
return airlinefare +hotelcharge();
}
//display the receipt in well formatted text.
private void show() {
//TODO Auto-generated method stub
Locale locale = new Locale("en", "US");
NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance();
System.out.println();
System.out.printf("%-13s %-1s %-1s " , "", name + " Expense Report", "");
System.out.printf("%-25s %-10s %-5s ","", "Airline Fare", ""+ currencyFormatter.format(airlinefare));
System.out.printf("%-25 %-10s %-5s ","", "Hotel", "=", ""+ currencyFormatter.format(hotelcharge()));
System.out.printf("%-25 %-10s %-5s ", "Total", "=", ""+ currencyFormatter.format(total()));
System.out.printf("%-25s %-10s %-5s ", ""+ currencyFormatter.format(dolltoconvert)+"dollars", "=",
""+currencyFormatter.format(convertdollar())+ "Cuban CUC");
System.out.printf("%-25s %-10s %-5s ","Penalty", "=", "10%");
System.out.printf("%-25s %-10s %-5s ", "Conversion rate", "=", "3%");
}
//ask for input from user
private void ask() {
Scanner sc = new Scanner(System.in);
System.out.printf("Enter your last name : ");
name=sc.next();
System.out.printf("Enter airline fare :$ ");
airlinefare= sc.nextDouble();
System.out.printf("Enter the number of nights : ");
noofnight=sc.nextInt();
System.out.printf("Enter dollar to convert :$ ");
dolltoconvert=sc.nextDouble();
String nn="";
nn=nn+Character.toUpperCase(name.charAt(0));
for(int i=1;i nn+=Character.toLowerCase(name.charAt(i)); } name=nn; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
