bostonuser
October 16th, 2007, 11:30 PM
This is a simple program-my question is when you are using control structures such as for loops or switch,
do you write the code using the dialog boxes, for some reason I don't automatically think of the dialog box when writing a program-I don't know why I do this, possibly because I learned assembly language. I found an excellent tutorial on java, but I am curious if you experiment with different pop ups or do you keep it simple when using a control structure like this?
Thanks
import java.io.*;
public class Flooring{
public static void main(String args[]) throws Exception{
int ch;
// local variable declarations
// Outputs for program directions
System.out.println("Welcome to \"My\" Flooring Depot");
System.out.println("\nThis program asks the user to enter a choice of flooring for a new home."
+ "\nPlease enter the number that matches your flooring choice then press" + "\nthe Enter key.");
System.out.println("Enter 1 for Scored Concrete, costs $3000.");
System.out.println("Enter 2 for Carpeting, comes with $5000 allowance.");
System.out.println("Enter 3 for Wood Floors in the living area, carpeting in the bedrooms,"
+ "\ntile in the bath areas,"
+ "\nAnd a $5000 carpet allowance, totaling $10,000.");
// alternating prompts for input and statements to capture users input
// System.out.print is used instead of System.out.println so the prompt
// stays on the same line as the text
System.out.print("your choice is : ");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try{
ch=Integer.parseInt(in.readLine());
switch(ch){
case 1: System.out.println("Scored Carpeting, costs $3000");
break;
case 2: System.out.println("Carpeting, comes with $5000 allowance");
break;
case 3: System.out.println("Wood Floors in the living area, carpeting in the bedrooms,"
+ "\ntile in the bath areas,"
+ "\nAnd a $5000 carpet allowance, totaling $10,000.");
break;
default: System.out.println("Invalid entry!");
break;
}
}
catch(NumberFormatException ex){
System.out.println(ex.getMessage() + " is not a numeric value.");
System.exit(0);
}
}
}
do you write the code using the dialog boxes, for some reason I don't automatically think of the dialog box when writing a program-I don't know why I do this, possibly because I learned assembly language. I found an excellent tutorial on java, but I am curious if you experiment with different pop ups or do you keep it simple when using a control structure like this?
Thanks
import java.io.*;
public class Flooring{
public static void main(String args[]) throws Exception{
int ch;
// local variable declarations
// Outputs for program directions
System.out.println("Welcome to \"My\" Flooring Depot");
System.out.println("\nThis program asks the user to enter a choice of flooring for a new home."
+ "\nPlease enter the number that matches your flooring choice then press" + "\nthe Enter key.");
System.out.println("Enter 1 for Scored Concrete, costs $3000.");
System.out.println("Enter 2 for Carpeting, comes with $5000 allowance.");
System.out.println("Enter 3 for Wood Floors in the living area, carpeting in the bedrooms,"
+ "\ntile in the bath areas,"
+ "\nAnd a $5000 carpet allowance, totaling $10,000.");
// alternating prompts for input and statements to capture users input
// System.out.print is used instead of System.out.println so the prompt
// stays on the same line as the text
System.out.print("your choice is : ");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
try{
ch=Integer.parseInt(in.readLine());
switch(ch){
case 1: System.out.println("Scored Carpeting, costs $3000");
break;
case 2: System.out.println("Carpeting, comes with $5000 allowance");
break;
case 3: System.out.println("Wood Floors in the living area, carpeting in the bedrooms,"
+ "\ntile in the bath areas,"
+ "\nAnd a $5000 carpet allowance, totaling $10,000.");
break;
default: System.out.println("Invalid entry!");
break;
}
}
catch(NumberFormatException ex){
System.out.println(ex.getMessage() + " is not a numeric value.");
System.exit(0);
}
}
}