Hi I have a program that is not compiling when I add a loop can you help me?The program below is compiling without the loop.
> Blockquote mport java.util.*;
import java.text.*;
import java.util.Scanner;
class HardwareItems
{
String code;
String description;
double price;
HardwareItems(String code,String description,double price){
this.code=code;
this.description=description;
this.price=price;
}
public String getCode(){
return code;
}
public String getDescription(){
return description;
}
public double getPrice(){
return price;
}
public static void main(String []args){
ArrayList<HardwareItems> list=new ArrayList<HardwareItems>();
list.add(new HardwareItems("K16","Wood screws,brass,20mm",7.75));
list.add(new HardwareItems("D24","Wood glue,clear,1 liter",5.50));
list.add(new HardwareItems("M93","Sandpaper,fine grade",10.25));
list.add(new HardwareItems("M94","Sandpaper,fine grade",14.75));
DecimalFormat df=new DecimalFormat("$ ##.##");
System.out.println("Hardware Items");
System.out.println();
System.out.println("Code "+" Description "+" Unit Price ");
for(HardwareItems e : list){
System.out.println(e.getCode()+"\t"+e.getDescription()+"\t"+df.format(e.getPrice()));
}
Scanner in=new Scanner (System .in);
System.out.println("place your order!");
System.out.print("NAME:");
String l=in.nextLine();
System.out.print("ADDRESS-1:");
String m=in.nextLine();
System.out.print("ADDRESS-2:");
String n=in.nextLine();
System.out.print("ADDRESS-3:");
String o=in.nextLine();
System.out.print("POST CODE:");
String p=in.nextLine();
}
}
And the program containing the loop is:
> Blockquote import java.util.*;
class Output
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter Code (XX to stop)" );
System.out.print("Code:" );
String code=input.next();
System.out.print("Quantity: ");
int quantity=input.nextInt();
while(!code.equals("XX")){
System.out.print("Code:" );
code=input.next();
if(code.equals("XX")){
break;
}
System.out.print("Quantity: ");
quantity=input.nextInt();
}
}
}
thank you
import java.util.*;
import java.text.*;
class HardwareItems
{
String code;
String description;
double price;
HardwareItems(String code,String description,double price){
this.code=code;
this.description=description;
this.price=price;
}
public String getCode(){
return code;
}
public String getDescription(){
return description;
}
public double getPrice(){
return price;
}
public static void main(String []args){
Scanner in=new Scanner(System.in);
double total=0;
ArrayList<HardwareItems> list=new ArrayList<HardwareItems>();
list.add(new HardwareItems("K16","Wood screws,brass,20mm",7.75));
list.add(new HardwareItems("D24","Wood glue,clear,1 liter",5.50));
list.add(new HardwareItems("M93","Sandpaper,fine grade",10.25));
list.add(new HardwareItems("M94","Sandpaper,fine grade",14.75));
DecimalFormat df=new DecimalFormat("$ ##.##");
System.out.println("Hardware Items");
System.out.println();
System.out.println("Code "+" Description "+" Unit Price ");
for(HardwareItems e : list){
System.out.println(e.getCode()+"\t"+e.getDescription()+"\t"+df.format(e.getPrice()));
}
System.out.println("Enter Code (XX to stop)" );
System.out.print("Code:" );
String code=in.next();
System.out.print("Quantity: ");
int quantity=in.nextInt();
while(!code.equals("XX")){
System.out.print("Code:" );
code=in.next();
if(code.equals("XX")){
break;
}
System.out.print("Quantity: ");
quantity=in.nextInt();
}
System.out.println("place your order!");
System.out.print("NAME:");
String l=in.next();
System.out.print("ADDRESS-1:");
String m=in.next();
System.out.print("ADDRESS-2:");
String n=in.next();
System.out.print("ADDRESS-3:");
String o=in.next();
System.out.print("POST CODE:");
String p=in.next();
}
}