xtac Posted October 24, 2004 Share Posted October 24, 2004 package billing; import javax.swing.JOptionPane; public class input { // class input public static void main(String[] args) { // main header worker resident = new worker(); worker biz = new worker(); //data types double type; int acc; int premchanB= 0; int premchanR=0; String accType; String accNum; String bizType; String basicConR; String premB; String premR; String basicConB; double amtDue=0; accType = JOptionPane.showInputDialog(null, "1. Enter your account number" + "\n" + "2. Quit"); //menu type = Integer.parseInt(accType); // converts accType to an integer // if user chooses anything else but 1 or 2 it will result in error //needs to be sufficent if someone keeps entering wrong number(loop?) while (type != 1 && type != 2) { JOptionPane.showMessageDialog(null, " Must enter 1 or 2 ", "Try Again", //error JOptionPane.INFORMATION_MESSAGE); accType = JOptionPane.showInputDialog(null, "1. Enter your account number" + "\n" + "2. Quit"); //menu type = Double.parseDouble(accType); // converts accType to an integer } if (type == 1) // when user inputs 1 { accNum = JOptionPane.showInputDialog(null, "Please Enter Account Number"); acc = Integer.parseInt(accNum); //converts accNum to an integer } else { System.exit(0); //exits program nicely } bizType = JOptionPane.showInputDialog("Enter Buisness type :" + "\n" + //display of buisness types " r/R - Residential account" + "\n" + " b/B - Buisness account "); while (bizType !="r" || bizType !="R" || bizType != "B" || bizType != "b") { bizType = JOptionPane.showInputDialog( "Enter Buisness type :" + "\n" + //display of buisness types " r/R - Residential account" + "\n" + " b/B - Buisness account "); } if (bizType =="r" || bizType =="R") { basicConB = JOptionPane.showInputDialog("Enter basic connection"); premB = JOptionPane.showInputDialog("Enter amount of premium channels"); premchanB = Integer.parseInt(premB); } while (premchanB > 30) { premB = JOptionPane.showInputDialog("Enter amount of premium channels"); } System.exit(0); //exits program nicely having trouble, it won't ever recognize r,R,b,or B. Also am I doing anything uneccesary? Link to comment Share on other sites More sharing options...
0 mrvc Posted October 24, 2004 Share Posted October 24, 2004 (edited) Why are you parsing type as double in the first while loop but before the loop you parse it as an int? And to answer your first question: while (bizType !="r" || bizType !="R" || bizType != "B" || bizType != "b") You should use && instead of ||, like you did in the first while loop. Edited October 24, 2004 by mrvc Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted October 24, 2004 Share Posted October 24, 2004 Why are you parsing type as double in the first while loop but before the loop you parse it as an int?And to answer your first question: You should use && instead of ||, like you did in the first while loop. 584795953[/snapback] The other problem is that it needs to be while (!bizType.equals("r") ?|| !bizType.equals("R") || !bizType.equals("B") || !bizType.equals("b")) Either that, or change the type of bizType to char and change " to '. Link to comment Share on other sites More sharing options...
0 xtac Posted October 26, 2004 Author Share Posted October 26, 2004 Class worker : package billing; import javax.swing.*; public class worker { // class worker // constructor public worker (){ double amtDue = 0; // initilizes amtDue } double amtDue = 0; //residential double billR = 4.50; //bill process fee double bServiceR = 20.50; //basic service fee double premiumR= 7.50; //per premium channel double totalR = 0; //buisness double billB = 15.00; //bill processing fee double bServiceB = 75.00; // 75.00 for the first 10 connect ,$5 ea additional connect double premiumB = 50.00; // 50.00 per channel double totalB = 0; public void residential( double res){ //method for residential amtDue = amtDue + res + billR + bServiceR ; } public void buisness( double buis){ //method for buisness amtDue = amtDue + buis; } public void setAmount( double amt){ // setAmount method double amtDue = amt; } public double getAmount() //getAmount method { return amtDue; } } //end of class worker class input package billing; import javax.swing.JOptionPane; public class input { // class input public static void main(String[] args) { // main header worker resident = new worker(); //object resident worker biz = new worker(); //object biz //data types int type; int acc; int premchan = 0; double basicConex = 0; String accType; String accNum; String bizType; String basicCon; String prem; double amtDue = 0; do { accType = JOptionPane.showInputDialog(null, "1. Enter your account number" + "\n" + "2. Quit"); //menu if (!accType.equals("1") && !accType.equals("2")) { accType = JOptionPane.showInputDialog(null, "Please Enter 1 or 2" + "\n" + "1. Enter your account number" + "\n" + "2. Quit"); //menu } if (accType.equals("2")) { System.exit(0); } accNum = JOptionPane.showInputDialog(null, "Please Enter Account Number"); acc = Integer.parseInt(accNum); //converts accNum to an integer bizType = JOptionPane.showInputDialog("Enter Buisness type :" + "\n" + //display of buisness types " r/R - Residential account" + "\n" + " b/B - Buisness"); //HOW TO - need to redisplay ^ if user enters something other than r/R b/B than go on as normal if (bizType.equals("r") || bizType.equals("R") || bizType.equals("B") || bizType.equals("b")) { basicCon = JOptionPane.showInputDialog("Enter basic connection"); basicConex = Integer.parseInt(basicCon); //converts basicConex to an integer } else if (!bizType.equals("r") || !bizType.equals("R") && !bizType.equals("B") || bizType.equals("b")) { System.out.print("not"); } if (basicConex > 50) { basicCon = JOptionPane.showInputDialog(null, "Enter basic connection, amount must be less than 50", "Try Again", JOptionPane. INFORMATION_MESSAGE); } prem = JOptionPane.showInputDialog("Enter amount of premium channels"); premchan = Integer.parseInt(prem); if (premchan > 30) { prem = JOptionPane.showInputDialog(null, "Enter amount of premium channels, amount must be less than 30", "Try Again", JOptionPane.INFORMATION_MESSAGE); } if (!bizType.equals("r") || !bizType.equals("R")) { System.out.print(bizType); //testing } else if (!bizType.equals("b") || !bizType.equals("B")) { System.out.print(bizType); //testing } } while (accType.equals("1")); } //end of main }//end of class input Ok I spent a lot of time and fixed up what was going on. Now I have a problem, and it's a big one. I don't understand how to do the calculation using the worker class, or even if what I did in the worker class is on the right track. Link to comment Share on other sites More sharing options...
Question
xtac
package billing; import javax.swing.JOptionPane; public class input { // class input public static void main(String[] args) { // main header worker resident = new worker(); worker biz = new worker(); //data types double type; int acc; int premchanB= 0; int premchanR=0; String accType; String accNum; String bizType; String basicConR; String premB; String premR; String basicConB; double amtDue=0; accType = JOptionPane.showInputDialog(null, "1. Enter your account number" + "\n" + "2. Quit"); //menu type = Integer.parseInt(accType); // converts accType to an integer // if user chooses anything else but 1 or 2 it will result in error //needs to be sufficent if someone keeps entering wrong number(loop?) while (type != 1 && type != 2) { JOptionPane.showMessageDialog(null, " Must enter 1 or 2 ", "Try Again", //error JOptionPane.INFORMATION_MESSAGE); accType = JOptionPane.showInputDialog(null, "1. Enter your account number" + "\n" + "2. Quit"); //menu type = Double.parseDouble(accType); // converts accType to an integer } if (type == 1) // when user inputs 1 { accNum = JOptionPane.showInputDialog(null, "Please Enter Account Number"); acc = Integer.parseInt(accNum); //converts accNum to an integer } else { System.exit(0); //exits program nicely } bizType = JOptionPane.showInputDialog("Enter Buisness type :" + "\n" + //display of buisness types " r/R - Residential account" + "\n" + " b/B - Buisness account "); while (bizType !="r" || bizType !="R" || bizType != "B" || bizType != "b") { bizType = JOptionPane.showInputDialog( "Enter Buisness type :" + "\n" + //display of buisness types " r/R - Residential account" + "\n" + " b/B - Buisness account "); } if (bizType =="r" || bizType =="R") { basicConB = JOptionPane.showInputDialog("Enter basic connection"); premB = JOptionPane.showInputDialog("Enter amount of premium channels"); premchanB = Integer.parseInt(premB); } while (premchanB > 30) { premB = JOptionPane.showInputDialog("Enter amount of premium channels"); } System.exit(0); //exits program nicelyhaving trouble, it won't ever recognize r,R,b,or B.
Also am I doing anything uneccesary?
Link to comment
Share on other sites
3 answers to this question
Recommended Posts