Question: i have this java code but the for loop isnt working or looping can anyone fix it ? import java.util.Scanner; class shop { class invoice

i have this java code but the for loop isnt working or looping can anyone fix it ?

import java.util.Scanner;

class shop {

class invoice { int no; // the Invoice No String custName; // the Customer name int amount; // the Invoice Amount invoice next; // points to the next Invoice invoice previous;

invoice(int no, String custName, int amount) {

this.no = no;

this.custName = custName; this.amount=amount;

}

invoice() {

no = 0;

custName = ""; amount =0;

}

}

invoice head, tail;

int count;

public shop() { head=null; count = 0; invoice hNode = new invoice (); invoice tNode=new invoice(); hNode.next=tNode; head=hNode; tail=tNode;

} public void add(int no, String name, int amount){ if(head==null){ head=new invoice(no,name,amount); tail=head; } else{ invoice curr=head; while(curr.next!=null){ curr=curr.next; curr.next=new invoice(no,name,amount); tail=curr.next ; } } } public void delete(int no) {

if (head.next == tail) {

System.out.println("This invoice doesnt exist");

return;

}

invoice p = head;

Object item = p.no;

while (p != tail) {

if (p.no == no) {

p.next.previous = p.previous;

p.previous.next = p.next;

count--; } p = p.next;

}

} public void printinvoice() { invoice curr=head; while(curr!=null){ System.out.println(curr); curr=curr.next; } } int countinvoice(){ invoice curr=head; while(curr!=null){ count+=1; curr=curr.next; } return count; }

int sum(){ invoice curr=head; while(curr!=null){ count+=1; curr=curr.next; } return count; } public int countInvoice() {

return count;

}

} public class assignment{ public static void main(String[] args) { Scanner input= new Scanner(System.in); shop shop = new shop(); int n = 0; System.out.print("Enter the number of Invoices in the shop: "); n = input.nextInt(); while (n

int no = 0; String name; int amount = 0; for(int i = 1; i

System.out.print("Enter Customer Name: "); name = input.next();

System.out.print("Enter ammount: "); amount = input.nextInt(); while(amount

shop.add(no, name, amount); System.out.println(); } System.out.println();

System.out.println(" printing invoices "); shop.printinvoice(); System.out.println();

System.out.println("pritning number of invoices "); shop.countinvoice(); System.out.println(); int del; System.out.println("enter number of invoice to be deleted"); del=input.nextInt(); if(del!=n){ System.out.println("invoice doesnt exist"); } else{ shop.delete(del); System.out.println("invoice number"+del+"is deleted"); } System.out.println("Invoices count = " + shop.countInvoice());

} } i have this java code but the for loop isnt working or

run: Enter the number of Invoices in the shop: 3 Enter No: 1 Enter Customer Name: do Enter ammount: 23

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!