M new to this forum + new to java please help me with file handling program
hi i want to make a file handling program where in i want to input a text file say f1 whose style is mentioned as below
aaa...bcd
aaabbc
acdce
a..dd
abbcd
now i want to write d out put of file f1 to file f2 but only those string entries widout any ... in them how to do that :-(( please help :((
import java.io.*;
import java.lang.*;
class javcsse{
void javsce (){
BufferedReader in;
PrintWriter out;
String line;
try
in = new BufferedReader(new FileReader("e:\\cntcs\\n7.txt"));
out = new PrintWriter("e:\\cntcs\\n8.txt");
line = in.readLine();
while(line != null)
if(line.contains("...") && line.contains("....")){
break ;
else{
if(line.contains("cc"))
System.out.println(line+"\n");
out.println(line);
line = in.readLine();
in.close();
out.close();
} catch (Exception ex)
System.err.println(ex.getMessage());
public class javcse{
public static void main(String[] args) {
new javcsse();
}hey i wrote this code yet could u tell y is it still not working :((
Similar Messages
-
I am new to java please help!!
please help ive got a method thta i wanto to use it in another class, but it does not work.
//prueba.java
import java.io.*;
public class prueba
public int numero3;
public int suma(int numero1,int numero2)
int numero3=numero1+numero2;
return numero3;
//prueba1.java
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import prueba;
public class prueba1 extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
PrintWriter out = res.getWriter();
int num1=1;
int num2=1;
prueba uno=new prueba();
out.println(uno.suma(2,3));
when i ty to complie this file it throws me thie errors:
C:\resin-2.0.b2\doc\content-manager\admin\web-inf\classes\prueba1.java:4: cannot resolve symbol
symbol: class prueba
import prueba;
^
C:\resin-2.0.b2\doc\content-manager\admin\web-inf\classes\prueba1.java:15: cannot resolve symbol
symbol : class prueba
location: class prueba1
prueba uno=new prueba();
^
C:\resin-2.0.b2\doc\content-manager\admin\web-inf\classes\prueba1.java:15: cannot resolve symbol
symbol : class prueba
location: class prueba1
prueba uno=new prueba();
^
3 errors
Tool completed with exit code 1
both , prueba1.java and prueba.java are in the same folder.C:\resin-2.0.b2\doc\content-manager\admin\web-inf\classes\prueba1.java:15: cannot resolve symbol
symbol : class prueba
location: class prueba1
prueba uno=new prueba();
^
C:\resin-2.0.b2\doc\content-manager\admin\web-inf\classes\prueba1.java:15: cannot resolve symbol
symbol : class prueba
location: class prueba1
prueba uno=new prueba();
^
2 errors -
Totally New in Java - Please help!!
Hi Dear all,
l am totally new in Java, and l facing one problem,and really hope can get some help from yours,please!
l need to write this program:
The program should do the following:
1. Input two fields: action (action: add / delete), and account number (any
digit or character)
2. if the action is "add" then the program adds one text line to a text
file.
"New account is <account number>"
3. create the text file if it is not already exist (in c:\)
4. When program runs again with new input values, a new line will be
appended to the same file.
5. if the action is "delete" then the program finds the record and removes
the text line from the file.
My problem is :
l just know that l need to create the user interface first,but l don't know how to go on??
Would you please show me some step how to solve these problem?
Many many thanks!!
BaoBaoI don't know about Swing. I never use it.
The stuff to create and manipulate files is in the java.io package.
You'll probably want to use java.io.FileReader and java.io.FileWriter.
Note that FileWriter has a constructor that lets you append and not overwrite.
I'll start you off with a test.
public class AccountListAddTest() {
public static void main(String[] argv) {
AccountList accts = new AccountList();
accts.add("abcdefg12345"); // arg is a hypothetical account number
}Write an AccountList class that'll work if you compile and run this test. After you run this test for the first time, the file should contain the string
New account is abcdefg12345.
This test assumes that the filename is hardcoded into the AccountList class. To keep it simple, make the add method create a new appending FileWriter each time, write, then close the writer. -
i'm very new to java and i'm getting an error in my application. i took 4 applications that compiled and worked separatly and i tried to combine them into one application. i'm getting the error: unreported exception java.io.IOException; must be caught or declared to be thrown, in lines 73,78,83,88,120,146,149,152,155 in the and it points at the keyboard.readLine() but everything i've tried just gives me more errors. please help anything and everything will be greatly appreciated. here it is, sorry about format i dunno how to straighten it in here:
// ^ ^
// (0)(0) A Happy Piggy Application
// Problems: 2.6,2.8,2.9,2.12 (oo)
// An application finds the total number of hours, minutes, & seconds, finds the distance
// between two points, finds the volume and surface area of a sphere, and adds up the change
// in a jar. First, the total hours, minutes, and seconds problem.
import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class twoptsix
static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter screen = new PrintWriter(System.out, true);
public static void main (String[] args) throws IOException
double hoursa, minutesa, secondsa;
String hours;
System.out.print ("Please enter a number of hours: ");
hours = keyboard.readLine();
hoursa = Double.parseDouble(hours); //asks programmer friendly user to enter hours
String minutes;
System.out.print ("Please enter a number of minutes: ");
minutes=keyboard.readLine();
minutesa = Double.parseDouble(minutes); //asks programmer friendly user to enter minutes
String seconds;
System.out.print ("Pretty please enter a number of seconds: ");
seconds = keyboard.readLine();
secondsa = Double.parseDouble(seconds); //asks programmer friendly user to enter seconds
double allseconds;
allseconds = (hoursa * 3600) + (minutesa * 60) + secondsa; //adds up all the seconds of the time entered
System.out.println ("You have: " + hours + " hours..."); //displays hours
System.out.println ("" + minutes + " minutes..."); //displays minutes
System.out.println ("and " + seconds + " seconds..."); //displays seconds
System.out.println ("to get whatever you need to done!"); //witty attempt at humor
System.out.println ("The total amount of seconds is: " + allseconds + " seconds."); //displays total seconds
// An application that finds the distance between two points when the points
// are given by the user.
double x1, x2, y1, y2, total, distance;
String xa;
System.out.print ("Please enter the 'x' coordinate of first point: ");
xa = keyboard.readLine();
x1 = Double.parseDouble(xa); //asks programmer friendly user to enter first x value
String ya;
System.out.print ("...also need the 'y' coordinate of first point: ");
ya = keyboard.readLine();
y1= Double.parseDouble(ya); //asks programmer friendly user to enter first y value
String xb;
System.out.print ("...and the 'x' coordinate of the second point: ");
xb = keyboard.readLine();
x2 = Double.parseDouble(xb); //asks programmer friendly user to enter second x value
String yb;
System.out.print ("...don't forget the 'y' coordinate of the second point: ");
yb = keyboard.readLine();
y2 = Double.parseDouble(yb); //asks programmer friendly user to enter second y value
total = Math.pow(x2 - x1, 2.0) + Math.pow(y2 - y1, 2.0); //squares the differences of values
distance = Math.sqrt(total); //finds the square root of the sum of the differences of the values
System.out.print ("E=mc^2...oh and,");
System.out.print ("the distance between point (" + xa +"," + ya +") and point("+
xb + "," + yb + ") is : " + distance);
// An application that takes the radius of a sphere and finds and prints
// the spheres volume and surface area.
double radius,volume,area;
String rad;
System.out.print("Please enter the radius of a sphere: ");
rad = keyboard.readLine();
radius = Double.parseDouble(rad); //asks programmer friendly user to enter the radius of a sphere
DecimalFormat fmt = new DecimalFormat ("0.####");
volume = ((4 * Math.PI * Math.pow(radius,3.0)) / 3) ;
System.out.println (" The sphere has a volume of:" + fmt.format(volume)); //finds and displays volume
area = ( 4 * Math.PI * Math.pow(radius, 2.0)) ;
System.out.print (" The Surface Area of the sphere is: " + fmt.format(area)); //finds and displays surface area
// An application that finds the total, in dollars and cents, of a number of quarters,
// nickels, dimes, and pennies in your piggy bank.
int pennies, nickels, dimes, quarters;
double money1;
screen.println("Empty your piggy bank and count the change, how many quarters ya have?: ");
int q = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of quarters
screen.println("How many dimes?: ");
int d = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of dimes
screen.println("How many nickels?: ");
int n = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of nickels
screen.println("How many pennies?: ");
int p = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of pennies
NumberFormat money = NumberFormat.getCurrencyInstance();
money1 = (.25 * q) + (.1 * d) + (.05 * n) + (.01 * p);
screen.println("You're rich! Total, you've got: " + money.format(money1));//finds and displays total moneyOk here is the working code as one long function:
// ^ ^
// (0)(0) A Happy Piggy Application
// Problems: 2.6,2.8,2.9,2.12 (oo)
// An application finds the total number of hours, minutes, & seconds, finds the distance
// between two points, finds the volume and surface area of a sphere, and adds up the change
// in a jar. First, the total hours, minutes, and seconds problem.
import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class twoptsix
static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter screen = new PrintWriter(System.out, true);
public static void main (String[] args) throws IOException
double hoursa, minutesa, secondsa;
String hours;
System.out.print ("Please enter a number of hours: ");
hours = keyboard.readLine();
hoursa = Double.parseDouble(hours); //asks programmer friendly user to enter hours
String minutes;
System.out.print ("Please enter a number of minutes: ");
minutes=keyboard.readLine();
minutesa = Double.parseDouble(minutes); //asks programmer friendly user to enter minutes
String seconds;
System.out.print ("Pretty please enter a number of seconds: ");
seconds = keyboard.readLine();
secondsa = Double.parseDouble(seconds); //asks programmer friendly user to enter seconds
double allseconds;
allseconds = (hoursa * 3600) + (minutesa * 60) + secondsa; //adds up all the seconds of the time entered
System.out.println ("You have: " + hours + " hours..."); //displays hours
System.out.println ("" + minutes + " minutes..."); //displays minutes
System.out.println ("and " + seconds + " seconds..."); //displays seconds
System.out.println ("to get whatever you need to done!"); //witty attempt at humor
System.out.println ("The total amount of seconds is: " + allseconds + " seconds."); //displays total seconds
// } <----- MAIN FUNCTION USED TO END HERE!!!
//but we want to keep going so remove the bracket!
// An application that finds the distance between two points when the points
// are given by the user.
// { <-- other function used to start here, but now it continues
double x1, x2, y1, y2, total, distance;
String xa;
System.out.print ("Please enter the 'x' coordinate of first point: ");
xa = keyboard.readLine();
x1 = Double.parseDouble(xa); //asks programmer friendly user to enter first x value
String ya;
System.out.print ("...also need the 'y' coordinate of first point: ");
ya = keyboard.readLine();
y1= Double.parseDouble(ya); //asks programmer friendly user to enter first y value
String xb;
System.out.print ("...and the 'x' coordinate of the second point: ");
xb = keyboard.readLine();
x2 = Double.parseDouble(xb); //asks programmer friendly user to enter second x value
String yb;
System.out.print ("...don't forget the 'y' coordinate of the second point: ");
yb = keyboard.readLine();
y2 = Double.parseDouble(yb); //asks programmer friendly user to enter second y value
total = Math.pow(x2 - x1, 2.0) + Math.pow(y2 - y1, 2.0); //squares the differences of values
distance = Math.sqrt(total); //finds the square root of the sum of the differences of the values
System.out.print ("E=mc^2...oh and,");
System.out.print ("the distance between point (" + xa +"," + ya +") and point("+
xb + "," + yb + ") is : " + distance);
//second function used to end here...
//} <--- COMMENT OUT BRACKET SO WE CONTINUE
// An application that takes the radius of a sphere and finds and prints
// the spheres volume and surface area.
//{ <--- ANOTHER ONE TO COMMENT OUT
double radius,volume,area;
String rad;
System.out.print("Please enter the radius of a sphere: ");
rad = keyboard.readLine();
radius = Double.parseDouble(rad); //asks programmer friendly user to enter the radius of a sphere
DecimalFormat fmt = new DecimalFormat ("0.####");
volume = ((4 * Math.PI * Math.pow(radius,3.0)) / 3) ;
System.out.println (" The sphere has a volume of:" + fmt.format(volume)); //finds and displays volume
area = ( 4 * Math.PI * Math.pow(radius, 2.0)) ;
System.out.print (" The Surface Area of the sphere is: " + fmt.format(area)); //finds and displays surface area
// } <----- COMMENTED OUT FOR THE SAME REASON
// An application that finds the total, in dollars and cents, of a number of quarters,
// nickels, dimes, and pennies in your piggy bank.
//{ <----AND ANOTHER
int pennies, nickels, dimes, quarters;
double money1;
screen.println("Empty your piggy bank and count the change, how many quarters ya have?: ");
int q = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of quarters
screen.println("How many dimes?: ");
int d = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of dimes
screen.println("How many nickels?: ");
int n = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of nickels
screen.println("How many pennies?: ");
int p = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of pennies
NumberFormat money = NumberFormat.getCurrencyInstance();
money1 = (.25 * q) + (.1 * d) + (.05 * n) + (.01 * p);
screen.println("You're rich! Total, you've got: " + money.format(money1));//finds and displays total money
}P.S. To make the code formatted better put [ code ] before and [ /code ] after. It's not perfect, but a little better... -
Please, help me with file access in Java Applet.
import java.awt.*;
import java.applet.*;
import java.net.*;
public class ImageVi extends Applet {
URL PicPath1;
Image Img1;
public void init()
try
PicPath1 = new URL("http://nurchi.far.ru/pic/s08.jpg");
} catch (MalformedURLException Excep1) {}
public void paint(Graphics g) {
Img1=getImage(PicPath1);
g.drawImage(Img1, 10, 10, this);
The error message is:
Exception occurred during event dispatching:
java.security.AccessControlException: access denied (java.net.SocketPermission nurchi.far.ru resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:195)
at java.security.AccessController.checkPermission(AccessController.java, Compiled Code)
at java.lang.SecurityManager.checkPermission(SecurityManager.java, Compiled Code)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1019)
at sun.awt.image.URLImageSource.<init>(URLImageSource.java:48)
at sun.applet.AppletImageRef.reconstitute(AppletImageRef.java:40)
at sun.misc.Ref.get(Ref.java:53)
at sun.applet.AppletViewer.getCachedImage(AppletViewer.java:275)
at sun.applet.AppletViewer.getImage(AppletViewer.java:270)
at java.applet.Applet.getImage(Applet.java:190)
at ImageVi.paint(ImageVi.java:24)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:116)
at java.awt.Component.dispatchEventImpl(Component.java:2452)
at java.awt.Container.dispatchEventImpl(Container.java:1059)
at java.awt.Component.dispatchEvent(Component.java:2312)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:301)
at java.awt.EventDispatchThread.pumpOneEventForComponent(EventDispatchThread.java:120)
at java.awt.EventDispatchThread.pumpEventsForComponent(EventDispatchThread.java:95)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:90)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)Applets are not allowed to connect to other server
than the one they were loaded from. This is probably
the reason here.You mean that I can use the applet after uploading on my web-site and using "getDocumentBase()" only?
OK.
The applet works perfectly if I use that function, but I have another question.
If I want to use something like:
Img1=getImage(getDocumentBase(), "s01.jpg");
it works perfectly.
If I do the fillowing:
Img1=getImage(getDocumentBase(), "pic/s01.jpg");
it also works.
But is it possible to go a level up?
Like:
Img1=getImage(getDocumentBase(), "../pic/s01.jpg");
That is if an applet is in one folder and the pictures are in another, but to get to them I have to go a level up and then enter another folder.
Please help.
Thanks. -
New to Java, Please help
Hi, I was trying to play a game and came up with this java error (below), I uninstalled and reinstalled still no fix. I think i need a new class?, If anyone can explain the potential problem to me and help me fix it, that would be much appreciated. I'm a complete NEWB when it comes to java, I'm not even sure how to edit that code. so please remember to explain in the newbiest of newby answers. I am proficient with features of a computer just not java.
Java Plug-in 1.6.0_24
Using JRE version 1.6.0_24-b07 Java HotSpot(TM) Client VM
User home directory = C:\Users\Ethan
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
load: class loader.class not found.
java.lang.ClassNotFoundException: loader.class
at sun.plugin2.applet.Applet2ClassLoader.fi… Source)
at sun.plugin2.applet.Plugin2ClassLoader.lo… Source)
at sun.plugin2.applet.Plugin2ClassLoader.lo… Source)
at sun.plugin2.applet.Plugin2ClassLoader.lo… Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.lo… Source)
at sun.plugin2.applet.Plugin2Manager.create… Source)
at sun.plugin2.applet.Plugin2Manager$Applet… Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassNotFoundException: loader.class845681 wrote:
Hi, I was trying to play a game and came up with this java error (below), I uninstalled and reinstalled still no fix. I think i need a new class?, If anyone can explain the potential problem to me and help me fix it, that would be much appreciated. I'm a complete NEWB when it comes to java, I'm not even sure how to edit that code. so please remember to explain in the newbiest of newby answers. I am proficient with features of a computer just not java.If you want to learn how to program java, which is not the same as playing that particular game then you can start with the following link.
http://download.oracle.com/javase/tutorial/getStarted/index.html -
New To Java Coding, Help NEEDED With a little script
Well im just working on a script with an open uni course im doing, ive dont the script i was asked to do, but i was wondering if i could expand it abit more
* The DaylesGod class implements an application that
* simply prints "Dayles God!" to standard output.
class DaylesGod {
public static void main(String[] args) {
System.out.println("Dayle is GOD!"); // Display the string.
}thats what i have at the moment, i use cmd-cd C:\java
C:\java>java DaylesGod
Dayle is GOD
I was wondering if i could get it to display diffrent messages on diffrent lines? e.g
* The DaylesGod class implements an application that
* simply prints "Dayles God!" to standard output.
class DaylesGod {
public static void main(String[] args) {
System.out.println("Dayle is GOD!"); // Display the string.
System.out.println("Dayle is GOD!");
System.out.println("Dayle is GOD!");
}Dayle wrote:
Could you please give me an example of what that may look like please?
//New Wow
class Wow { //File Name
public static void main(String[] args) {
System.out.println("Wow");
System.out.println("Wow");
}This code executes fine in Jcreator, but only once, it wont type ''Wow'' Twice? Not to sure what to do, it wont run in cmd properly, want multiple ''Wows'' on seprate lines. If possible? Thank you :) and i will get in touch with shrink ha.That should print
Wow
WowAre you sure you're not having a problem with Jcreator or whatever you're viewing the output with? You might try executing this from the command line. There's no reason you can't do that.
Remember, System.out.println(x) is equivalent to System.out.print(x + '\n'). -
New to java, please help me :(
hi, i have to complete a BMI calculator with arrays and switch, i need it so that if input a / b is selected it will calculate metric / imperial (i know that both calcs are the same, its just a placeholder for the time being). once thats selected users are asked to input name, age, height and weight, then looped again for another user to input into the array.
once completed the name and age along with the BMI calculation for all the users that have inputted are displayed
the problem is, the calculations are wrong, where it should be outputting a BMI of between 20-23ish im getting 0.3
i think i had this problem when i done the switch example previously, but to fix that i just lumped all the code (inputs and calcs) into each case. in this method im guessing that would be an incorrect approach ?
btw, sorry for my layout, ive been debugging for ages now and havnt had time to clean it up :/
thank you in advance and heres my code:-
package bmicalculationex;
import javax.swing.*;
public class Main {
public static void main(String[] args) {
String output;
double Hfeet=0, Wstone=0, Hinches=0, Wlbs=0;
String Hfeetstr, Wstonestr, Hinchesstr, Wlbsstr, age;
String name;
double bmiweight=0, bmiheight=0, BMI=0;
Item[] myItemArray = new Item[2];
for(int i = 0;i<2;i++){
myItemArray[i] = new Item();
String input = JOptionPane.showInputDialog(
"Welcome to Chunks BMI calculator\n"+
"a) Metric.\n"+
"b) Imperial\n"+
"q) Quit\n"+
"\nPlease enter letter code" );
char code = input.charAt(0);
switch(code){
case 'a':
output= "Imperial.";
Wlbs = Wlbs * 0.45359237;
Hinches = Hinches * 0.0254;
Hfeet = Hfeet * 0.3048;
Wstone = Wstone * 6.35029318;
break;
case 'b': output= "Metric.";
Wlbs = Wlbs * 0.45359237;
Hinches = Hinches * 0.0254;
Hfeet = Hfeet * 0.3048;
Wstone = Wstone * 6.35029318;
break;
default: output= "Error.";
JOptionPane.showMessageDialog(null,"Invalid Selection.\n"+ "Please try again.");
JOptionPane.showMessageDialog(null, "You have selected :- " + output + "\n\n" +" Thank you.");
//User In-
for(int c=0;c<2;c++){
name = JOptionPane.showInputDialog("enter your name");
age = JOptionPane.showInputDialog("enter your age");
Hfeetstr = JOptionPane.showInputDialog("enter your Height");
Hinchesstr = JOptionPane.showInputDialog("enter the remainder");
Wstonestr = JOptionPane.showInputDialog("enter your weight");
Wlbsstr = JOptionPane.showInputDialog("enter the remainder");
Hfeet = Float.parseFloat(Hfeetstr);
Wstone = Float.parseFloat(Wstonestr);
Hinches = Float.parseFloat(Hinchesstr);
Wlbs = Float.parseFloat(Wlbsstr);
bmiweight = Wstone + Wlbs;
bmiheight = Hinches + Hfeet;
BMI = bmiweight / (bmiheight*bmiheight);
myItemArray[c].setname(name);
myItemArray[c].setyear(age);
myItemArray[c].setBMII(BMI);
String message = "";
for(int n=0;n<2;n++){
message = message + "Name :- " + myItemArray[n].getname() + " " + "Age :- " + " " + myItemArray[n].getaged() + "BMI :- " + " " +myItemArray[n].getBMI() +"\n";
JOptionPane.showMessageDialog(null, message);
}//end of main method
}//end of main class
class Item{
private String namea;
private String agea;
private double BMIa;
public Item(){
agea = "";
BMIa = 0;
namea = "";
public Item(String nameb, String ageb, double BMIb){
namea = nameb;
agea = ageb;
BMIa = BMIb;
public String getname(){
return namea;
public String getaged(){
return agea;
public double getBMI(){
return BMIa;
public String setname (String nameb){
namea = nameb;
return nameb;
public void setyear(String ageb){
agea = ageb;
public void setBMII(double BMIb){
BMIa = BMIb;
}yush !
i done it :D
i just ended up lumping all the code into each case like i did last time, as when i had the calculations outside of the cases it wasnt taking the values from inside the case. nevermind....
another problem i do have though, i need a loop so that once the program finishes it repeats itself until an X is entered, im not very good with loops :S
i tend to try it like this
quit = 1;
while (quit<2){
then just have one of the cases as quit +1
so in mine it looks liek this:
int quit=1;
while (quit<2){
String input = JOptionPane.showInputDialog(
"Welcome to Chunks BMI calculator\n"+
"a) Metric.\n"+
"b) Imperial\n"+
"q) Quit\n"+
"\nPlease enter letter code" );
char code = input.charAt(0);
switch(code){
case 'a':
JOptionPane.showMessageDialog(null, "You have selected imperial. "+"\n\n" +" Thank you.");
for(int c=0;c<2;c++){
name = JOptionPane.showInputDialog("enter your name");
age = JOptionPane.showInputDialog("enter your age");
Hfeetstr = JOptionPane.showInputDialog("enter your Height in feet");
Hinchesstr = JOptionPane.showInputDialog("enter the remaining inches");
Wstonestr = JOptionPane.showInputDialog("enter your weight in stone");
Wlbsstr = JOptionPane.showInputDialog("enter the remaining lbs");
Hfeet = Float.parseFloat(Hfeetstr);
Wstone = Float.parseFloat(Wstonestr);
Hinches = Float.parseFloat(Hinchesstr);
Wlbs = Float.parseFloat(Wlbsstr);
Wlbs = Wlbs * 0.45359237;
Hinches = Hinches * 0.0254;
Hfeet = Hfeet * 0.3048;
Wstone = Wstone * 6.35029318;
bmiweight = Wstone + Wlbs;
bmiheight = Hinches + Hfeet;
BMI = bmiweight / (bmiheight*bmiheight);
String cat="";
if (BMI <18.5) cat = ("Posh spice");
else if (BMI >= 18.5 && BMI <=25) cat = ("Fit !");
else if (BMI >25 && BMI <=30) cat = ("Fatty !");
else if (BMI >30)cat = ("Super Fatty");
myItemArray[c].setcat(cat);
myItemArray[c].setname(name);
myItemArray[c].setyear(age);
myItemArray[c].setBMII(BMI);
break;
case 'b': output= "Metric.";
etc.....
this is causing me the problems:
for(int i = 0;i<2;i++){
myItemArray[i] = new Item();
says a non static variable cannot be referenced from a static context, i know im being stupid with my implementation, but whats a better way ?
thanks again :)
Edited by: Clunk on Nov 17, 2008 4:05 PM -
Pascal to Java Please help me!
I am truobled in creating a validation method for the user loging in....
As I am perfect at Pascal can anyone translate the following pascla code to Java Please help me with this.
PROGRAM USERLOGIN;
TYPE
USER_TYPE = RECORD
USERNAME : STRING[15];
PASSWORD : STRING[15];
END;
USFILE = FILE OF USER_TYPE;
VAR
USER: USER_TYPE;
CKUSER: USER_TYPE;
RECFILE : USFILE;
I,J : INTEGER;
BEGIN
WRITE('ENTER USERNAME:');READLN(CKUSER.USERNAME);
WRITE('ENTER PASSWORD:');READLN(CKUSER.PASSWORD);
FILESPEC :='USERFILE.USR';
ASSIGN(RECFILE, FILESPEC);
RESET(RECFILE);
WHILE NOT EOF(RECFILE) DO
BEGIN
READ(RECFILE, USER);
IF CKUSER.USERNAME = USER.USERNAME AND CKUSER.PASSWORD = USER.PASSWORD THEN
LOGIN
ELSE
WRITE('USER NOT FOUND');
END;
END.Thank youDon't bother:
http://forum.java.sun.com/thread.jsp?forum=54&thread=539277 -
evidence of a freakin' rootkit (of sorts) haunting my remaining neurons for the last year @ all my android devices (including this new tablet).
PLEASE HELP ME
Jose Carlos Amaral Morgado
Tomar, Portugal
'''...personally identifying information removed'''Sorry Morgado. This is a Firefox for Android support forum. Not a general purpose. Android forum. Please ask in an Android OS forum.
Locking this thread.
Cheers!
...Roland -
I purchased an audiobook in Nov 2012 using iPhone 4S and then upgraded to iPhone 5 in Dec. Now I am not seeing the audio book in purchase history in iTunes. This means I am not able to get the book in my new iPhone. Please help.
Audiobooks are currently a one-time only download from the store. If you don't have it on your computer (audiobooks go into the Books part of your iTunes library) nor on a backup, then if it's still in the store you can try contacting iTunes support and see if they will grant you a re-download : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page
-
I have no trouble viewing apps in the iTunes Store on my iPad. However, every time I try to install a new app, I get an error message after a while - cannot connect to iTunes Store. This issues cropped up two days ago on my new iPad. Please help...
JUst experienced the exact same problem after changing password.Getting same message. Hope someone has an answer for this.
-
my osx version is 10.8.2. i was buying the facetime app for my mac. i got this error -"FaceTime can’t be installed on “Macintosh HD” because the version of OS X is too new." so please help me out of this funny situation.
https://www.apple.com/support/mac-apps/facetime/
-
New to java(need help on access specifier)
hi! i am new to java.plzzzzz help me i have to make a project on access specifier's i know all theroy.but
i am unable to understand how i can define all specifiers practicly.i mean in a program.
thanks.plzzzzzzzz help methe most common project i can think of is a payroll system..
you can have real implementation of all the access specifiers
good luck -
I want to transfer my Adobe CS3 licence to my new Laptop.
Please help me for Deactivate Adobe CS3 licence from old LaptopHi sanket chalke,
I'm not sure what Adobe product you need help with, but you might want to start with this document, which has deactivation information: Activation & Deactivation Help
Please let us know how it goes.
Best,
Sara
Maybe you are looking for
-
T code for PO Whose GR is not done
All SAP Gurus, Is there any t-code or process to know the list of Po whose GR is not made. Regards
-
Is ODI compatible with Microsoft SQL Server 2008??
Hi, We are trying to set ODI for SQL Server 2008 but we are getting an error: "connection failed". I do not know if the problem is the driver or the incompatibility between ODI and SQL Server 2008. Does someone use them together? Are compatible? If t
-
Lightroom vs Aperture....?
Hi, I'm quite often asked by people about Aperture and how it compares to Lightroom. As I have never used Aperture (I'm a PC) I cannot really answer that question. Are there any Aperture users out there that will help?
-
BSP - Function Module - UWS_BW_GET_LONGTEXTS_FOR_SRVY - Inputs
Dear Experts, I need to fetch the Long Texts for the Survey application. Which is submitted by the user. I am using the below function module to fetch the Long Text. 'UWS_BW_GET_LONGTEXTS_FOR_SRVY' For this FM. We need to pass the input to the struct
-
4th generation itouch heating up, keeps crashing and worse after screen cracked
My 4th generation itouch has been heating up a lot, crashing and the battery dies really fast and I just got it in November. Unfortunetly, I dropped it today and it cracked at the bottom and a crack through the screen but, now my itouch keeps crashin