当我在Mac上的终端中调用此代码时,它告诉我“无法找到或加载主类”,它也会在我的所有关于printf的代码上给出很多错误。
我是Java的新手,所以我认为这段代码是错误的。
所有我真正想问的是如何修复它,以便当我键入“java itemprice”时它将在终端中运行,因为它不显示错误。
另外,我想要一些system.out.printf代码的帮助。
import java.util.Scanner;
public class itempricecalc {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.print("What is your first name?");
String fname = scanner.nextLine();
String invf = fname.substring(0,2);
System.out.print("What is your last name?");
String lname = scanner.nextLine();
String invl = lname.substring(0,2);
System.out.println("Your name is: " +fname + lname);
System.out.println("What is your zipcode?");
int zipcode = scanner.nextInt();
invoice = (invf + invl + zipcode);
double salestax = 6.25;
double subtotal = 0;
System.out.println("What is item 1 called?")
String itemonename = scanner.nextLine():
System.out.println("Enter price of item 1");
double itemone = scanner.nextDouble();
System.out.println("How many of item 1 did you purchase?");
int itemoneamount = scanner.nextInt();
System.out.println("What is item 2 called?")
String itemtwoname = scanner.nextLine():
System.out.println("Enter price of item 2");
double itemtwo = scanner.nextDouble();
System.out.println("How many of item 2 did you purchase?");
int itemtwoamount = scanner.nextInt();
System.out.println("What is item 3 called?")
String itemthreename = scanner.nextLine():
System.out.println("Enter price of item 3");
double itemthree = scanner.nextDouble();
System.out.println("How many of item 3 did you purchase?");
int itemthreeamount = scanner.nextInt();
double itemonetp = itemoneamount * itemone;
double itemtwotp = itemtwoamount * itemtwo;
double totalprice = itemonetp + itemtwotp;
subtotal = subtotal + totalprice;
double taxtotal = subtotal * salestax;
System.out.print("Your name is: " + fname + " " + lname)
System.out.printf(“Invoice: %.2f”, invoice);
System.out.printf(“Total price of item one is + %.2f”, itemonetp);
System.out.printf(“Total price of item two is + %.2f”, itemtwotp);
System.out.printf(“Total price of your purchase is + %.2f”, totalprice);
System.out.printf(“Your total with tax comes to + %.2f”, taxtotal);
System.out.printf(“You purchased + %.2f + amount of item one”, itemoneamount);
System.out.printf(“You purchased + %.2f + amount of item two”, itemtwoamount);
}
}