-3
我無法弄清楚我的代碼在哪裏,也在我的if循環中,它不允許我在第一個循環後輸入更多的公司名稱。需要幫助使用數組創建發票程序
Assign4:
import java.util.Scanner;
public class Assign4 {
private static int invoice;
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
OurDate date = new OurDate();
Invoice inv = new Invoice();
Ledger led = new Ledger();
System.out.print("Enter the amount of monthly invoices: ");
invoice = scan.nextInt();
for(int i = 0; i < invoice; i++){
System.out.println("\nEnter info for invoice number " + i);
inv.setCompanyNameFromUser();
inv.toString();
inv.setBillAmountFromUser();
inv.setDateFromUser();
date.setDayFromUser();
date.setMonthFromUser();
date.setYearFromUser();
}
}
}
OurDate:
import java.util.Scanner;
public class OurDate {
private int day;
private int month;
private int year;
Scanner scan = new Scanner(System.in);
public OurDate(){
day = 0;
month = 0;
year = 1900;
}
public void setDayFromUser(){
System.out.print("Enter day : ");
day = scan.nextInt();
}
public void setMonthFromUser(){
System.out.print("Enter month : ");
month = scan.nextInt();
}
public void setYearFromUser(){
System.out.print("Enter year : ");
year = scan.nextInt();
}
public String toString(){
return null;
}
}
發票:
import java.util.Scanner;
public class Invoice {
private double billAmount;
private String name;
private OurDate dueDate;
Scanner scan = new Scanner(System.in);
public Invoice(){
billAmount = 0;
}
public void setDateFromUser(){
System.out.print("Enter invoice due date\n");
//dueDate = scan.nextInt();
}
public void setCompanyNameFromUser(){
System.out.print("Enter the company name : ");
name = scan.nextLine();
}
public void setBillAmountFromUser(){
System.out.print("Enter bill amount : ");
billAmount = scan.nextDouble();
}
public String toString(){
return name;
}
}
總帳:
import java.util.Scanner;
public class Ledger {
private Invoice [] invoices;
private int numInvoices;
Scanner scan = new Scanner(System.in);
public Ledger(){
}
/*public Ledger(int){
}*/
public void getInvoiceInfo(){
System.out.println("Enter info for the invoice number 0\n");
}
public void printInvoiceInfo(){
}
public double calculateMonthBills(){
return numInvoices;
}
}
什麼是「if循環」? –
也許一個案例http://stackoverflow.com/questions/13102045/skipping-nextline-after-using-next-nextint-or-other-nextfoo-methods –
你應該解釋你的代碼失敗的具體步驟。那麼你應該詳細描述你是如何解決這個問題的。然後,您應該描述哪些解決方案無效。然後你應該問一個具體和可回答的問題。 – csmckelvey