How do I complete this? import java.util.Scanner; import java.io.*; public class
ID: 3744773 • Letter: H
Question
How do I complete this?import java.util.Scanner; import java.io.*;
public class App{
public static void main(String[] args) throws FileNotFoundException{ Scanner input=new Scanner(new File(args[0])); double taxRate = input.nextDouble(); int qty=input.nextInt(); ShoppingBag sb=new ShoppingBag(qty, taxRate); input.nextLine(); while(input.hasNextLine()){ String line=input.nextLine(); String[] tmp=line.split(" "); double retailPrice=Double.parseDouble(tmp[tmp.length-1]); int quantity =Integer.parseInt(tmp[tmp.length-2]); String itemName=""; for(int i=0; i<tmp.length -2; i++){ itemName += " "+tmp[i]; } itemName=itemName.trim(); Item item=new Item(itemName, quantity, retailPrice); sb.push(item); } System.out.println("The bag contains:"); System.out.println("------------------------------------------------"); System.out.println("Name of the Items Quantity Subtotal"); total=(d while(!sb.isEmpty()){ Item it=sb.top(); System.out.println(it); sb.pop(); } System.out.println("------------------------------------------------"); /* Total: $11.67 Tax (5%): $0.58 ----------------------------------------------- Grand Total: $12.25 */ }
}
How do I complete this?
import java.util.Scanner; import java.io.*;
public class App{
public static void main(String[] args) throws FileNotFoundException{ Scanner input=new Scanner(new File(args[0])); double taxRate = input.nextDouble(); int qty=input.nextInt(); ShoppingBag sb=new ShoppingBag(qty, taxRate); input.nextLine(); while(input.hasNextLine()){ String line=input.nextLine(); String[] tmp=line.split(" "); double retailPrice=Double.parseDouble(tmp[tmp.length-1]); int quantity =Integer.parseInt(tmp[tmp.length-2]); String itemName=""; for(int i=0; i<tmp.length -2; i++){ itemName += " "+tmp[i]; } itemName=itemName.trim(); Item item=new Item(itemName, quantity, retailPrice); sb.push(item); } System.out.println("The bag contains:"); System.out.println("------------------------------------------------"); System.out.println("Name of the Items Quantity Subtotal"); total=(d while(!sb.isEmpty()){ Item it=sb.top(); System.out.println(it); sb.pop(); } System.out.println("------------------------------------------------"); /* Total: $11.67 Tax (5%): $0.58 ----------------------------------------------- Grand Total: $12.25 */ }
}
import java.util.Scanner; import java.io.*;
public class App{
public static void main(String[] args) throws FileNotFoundException{ Scanner input=new Scanner(new File(args[0])); double taxRate = input.nextDouble(); int qty=input.nextInt(); ShoppingBag sb=new ShoppingBag(qty, taxRate); input.nextLine(); while(input.hasNextLine()){ String line=input.nextLine(); String[] tmp=line.split(" "); double retailPrice=Double.parseDouble(tmp[tmp.length-1]); int quantity =Integer.parseInt(tmp[tmp.length-2]); String itemName=""; for(int i=0; i<tmp.length -2; i++){ itemName += " "+tmp[i]; } itemName=itemName.trim(); Item item=new Item(itemName, quantity, retailPrice); sb.push(item); } System.out.println("The bag contains:"); System.out.println("------------------------------------------------"); System.out.println("Name of the Items Quantity Subtotal"); total=(d while(!sb.isEmpty()){ Item it=sb.top(); System.out.println(it); sb.pop(); } System.out.println("------------------------------------------------"); /* Total: $11.67 Tax (5%): $0.58 ----------------------------------------------- Grand Total: $12.25 */ }
} import java.util.Scanner; import java.io.*;
public class App{
public static void main(String[] args) throws FileNotFoundException{ Scanner input=new Scanner(new File(args[0])); double taxRate = input.nextDouble(); int qty=input.nextInt(); ShoppingBag sb=new ShoppingBag(qty, taxRate); input.nextLine(); while(input.hasNextLine()){ String line=input.nextLine(); String[] tmp=line.split(" "); double retailPrice=Double.parseDouble(tmp[tmp.length-1]); int quantity =Integer.parseInt(tmp[tmp.length-2]); String itemName=""; for(int i=0; i<tmp.length -2; i++){ itemName += " "+tmp[i]; } itemName=itemName.trim(); Item item=new Item(itemName, quantity, retailPrice); sb.push(item); } System.out.println("The bag contains:"); System.out.println("------------------------------------------------"); System.out.println("Name of the Items Quantity Subtotal"); total=(d while(!sb.isEmpty()){ Item it=sb.top(); System.out.println(it); sb.pop(); } System.out.println("------------------------------------------------"); /* Total: $11.67 Tax (5%): $0.58 ----------------------------------------------- Grand Total: $12.25 */ }
}
Explanation / Answer
i expect the code above to work fine, however i could not test it due to unavailability of test file. Please check and let me know. In case of any doubts, please ask in comments. If the answer helps you, please upvote. Thanks!
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.