Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


russell mahabir
adding loop
1 Answer(s)      2 years and 3 months ago
Posted in : Java Beginners


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


Advertisement
View Answers

January 12, 2012 at 4:44 PM


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();
        }
}


Related Tutorials/Questions & Answers:
adding loop
adding loop  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. >... the loop is: > Blockquote import java.util.*; class Output { public
loop
loop  what is the difference b/w do while,while and for loop..with example
Advertisements
loop
loop  i want to write my name(inder) through loop in java using star
for loop
for loop  what is for loop   Loops are used for iteration... for a number of times it is finite loop and if repetition is done infinitely it is infinite loop. Java provides several loop structures for iteration. Those
For loop
For loop  Hi! Please explain the following loop: for(i=0;i<a[j];i++) THANX!!   Please reply as soon as possible
for loop
for loop  how to performs the for loop when 2 inputs given like displays the triangle shape and how to take initial values or declaration values plz explain in detailed ex. 1 12 123 1234
Loop
to understand a loop my quesiton are: what du i do wrong in my code since.... (made in blueJ) Class Loop public void loopUpGeneral(int start, int stop... dk  Hi, Please check the for loop once again: for (int i
For Loop
For Loop  Write a program using a for loop that computes the following sum: 1/2 + 2/2 + 3/2 + 4/2 + 5/2 + ... N/2 N will be an integer limit the user enters. This is an example of my upcoming quiz. I need help on knowing
loop
loop  strong textHello can someone help me with this problem,I need to output the following code using a loop the code is as follows with the user inputs in inverted commas,thanks. ENTER CODE(XX to Stop) CODE:"D24" QUANTITY:"2
for loop
for loop  using only two for loop how can print below numbers 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5
for loop
for loop  using only two for loop how can print below numbers 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 7 7 7 7 7 7 7 6 6 6 6 6 6 5 5 5 5
Adding an employee
Adding an employee  coding for adding an employee
adding a dialogue
adding a dialogue  Blockquote Hi can you help with the program below,the program is a loop that prints out a code and a quantity when prompt for the user input.what I need is to modify the code to incorporate a dialogue asking
Adding two numbers
Adding two numbers  Accepting value ffrom the keyboard and adding two numbers
For..in loop
For..in loop         In this tutorial we will study for..in loop which is similar to for each loop of C#, Java and other popular languages, in this example
javascript adding a value to an array
javascript adding a value to an array  How to add a value to a function argument or an array in JavaScript
adding view to viewcontroller
adding view to viewcontroller  How to add a frame window that opens on button click .. in iPhone application
adding groups in contacts
adding groups in contacts  how to add groups in contacts using servlet and jsp????pls help.thanku in advance
Java for loop
Java for loop  Can a for statement loop indefinitely
adding buttons - Swing AWT
adding buttons  can u plzz explain how to add button to a dialog box and make them perform some event on the image loaded on the panel
adding buttons - Swing AWT
adding buttons  can u plzz explain how to add button to a dialog box and make them perform some event on the image loaded on the panel
Adding photo to iPhone simulator
Adding photo to iPhone simulator  Hi, there is no photo in my iPhone simulator.. how can i add one? Please suggest. Thanks
testcase for adding - JUNIT
testcase for adding  hi deepak...I am new to junit.can u send me a JUnit test case for adding or multiplying of two numbers.please i need it urgently
Adding Jar into Eclipse
Adding Jar into Eclipse  Hi, Please provide Step by step procedure to add jar, tld files and configurations in Eclipse Helios version and i am using Jboss5. Thanks&Regards, Shiva s
Dynamically adding textbox and labels
Dynamically adding textbox and labels  Sir, In my application I want to insert texbox and labels dynamically and want to insert database field value in that generated label. Plz help me, Thanks in advance
Adding customitem in canvas in J2ME?
Adding customitem in canvas in J2ME?  In J2ME how should we add a customitem inside the canvas.Because i need to perform key event handling for customitem.The key event handling is allowed in canvas not in form.So i try to use
webservices adding in eclipse
webservices adding in eclipse  hi team, i am working on webservices, please guide me how to add webservices in eclispe with step by step and give some examples also.   Please visit the following link: http
Adding images in itext pdf
Adding images in itext pdf  Hi, How to add image in pdf file using itext? Thanks   Hi, You can use following code: PdfWriter.getInstance(document,new FileOutputStream("imagesPDF.pdf")); Read more at Inserting
Java: Adding Row in JTable
Java: Adding Row in JTable   how about if we already have the JTAble created earlier. And i just found nothing to get its DefaultTableModel, thus, I can't call insertRow() method. Is there any work around for this? I found
For Loop - Struts
For Loop  Hi, How to use for loop in Struts2. I don't want use.... How to use the For loop in JSP. Thanks, Rajesh.  Hi Rajesh, i am sending simple use of for loop. In this example, you will see the use
for( ) loop in php
for( ) loop in php  Generally, when we use for loop in PHP or any other programming language why we use i++ and not ++i. What is the reason behind
for( ) loop in php
for( ) loop in php  Generally, when we use for loop in PHP or any other programming language why we use i++ and not ++i. What is the reason behind
Limits of "For loop"
Limits of "For loop"  Hi, How can I check the upper limit and lower limit of 'FOR' loop during unit testing using Junit. Thanks & Regards Ankit
jtable-adding a row dynamically
jtable-adding a row dynamically  hi..i am doing a project for pharmacy .. *pblm:* when i want to enter the details in jtable while running the application there are 3 rows and 4 columns which is default bt when we we have
How to write a loop and a while loop
How to write a loop and a while loop  How do I write a 1 loop and a 1 while loop for the example code: public boolean isTheFirstOneBigger (int num1, int num2) { if (num1 > num2) { return true
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable into this code pls help me.. package Com; import Com.Details; import java.awt.Color...(100,60,1300,600); add(pane); //Action Listener for button //for adding new
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable into this code pls help me.. package Com; import Com.Details; import java.awt.Color...(100,60,1300,600); add(pane); //Action Listener for button //for adding new
Adding JTable into existing Jframe.
Adding JTable into existing Jframe.  i need to add JTable into this code pls help me.. package Com; import Com.Details; import java.awt.Color...(100,60,1300,600); add(pane); //Action Listener for button //for adding new
loop statements
loop statements  write a program that reads from input an interger n and prints the factorial of all numbers between 1 and n
Adding checkbox to List as item
Adding checkbox to List as item   can we add checkox to List   Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; public class CheckBoxInList{ public static void
Dyanmically Adding Rows
Dyanmically Adding Rows  Hi sir Am doing project in that i need to add date picker in dynamically adding rows but the dates are storing in first test box only ill paste my code debug that code as soon as possible. Regards
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
loop example
loop example   1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 can you give me the code to get the number pyramid
For Loop/PHP
For Loop/PHP  Write a class called math. It is to have one property... 12345. How would you write this as a loop? Would I need to use the for loop or do/while loop?   PHP Factorial Example: <?php $n = 5; $i = 1; $f
for loop in java
for loop in java  54321 4321 321 21 1 using for loop or nested 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1 using for loop or nested... 8 9 6 7 8 9 10 all for loop code plz friends guide me
adding the delete code
adding the delete code  hello sir... i need to add a delete button to my code but i didn't know where can i put it.. i've tried but still not working.. please help me...this is the code.. package newproject1; import java.awt.
loop program
loop program  please tell me the code for the output 1 2 3foo 4 5bar 6foo 7baz 8 9foo 10 11 12foo 13 14baz 15foo bar 16 17 18foo . .......till 50
Advertisements
 

 

 

DMCA.com