[Show all top banners]

coresoul
Replies to this thread:

More by coresoul
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 $20/java programming
[VIEWED 1097 TIMES]
SAVE! for ease of future access.
Posted on 04-28-06 1:45 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 






Problem









I will Pay you $ 20.00 by Pay pal if u do this program before 4 today. two
hrs left.


Problem:  


     Program will read a text file to create Food objects
which will consist of a food name, a serving size, and a number of calories. A
text file is read which contains the calories contained in specific food items. 
From this data, an array of Food objects will be created and used to populate a
combo box for user selection. The Food objects will also be used in calculating
the balance calories for a given user on a given day.  


     User input will be used to create User objects which
will be user name, age, gender, height, weight, and Food Diary objects
(composition).  The Food Diary objects will consist of Date (composition), Food
object (composition), number of servings, and a balance.  Food Diary objects
will consist of the activity on any given day (see text area in sample output
screen below).  All User objects are saved to a file as objects and can be
retrieved on subsequent runs of the program.


     The program will calculate the number of calories the
user is allowed per day to maintain the user’s current weight (see below for
formula to use for this). 


 


BMRMen = 66 + (13.7 * weightPounds/2.2) + (5 * heightInches*2.54) 
- (6.8 * age)


BMRWomen = 655 + (9.6 * weightPounds/2.2) + (1.8 *
heightInches*2.54)  - (4.7 * age)


 


src="problem2_files/image002.jpg" v:shapes="_x0000_s1025">


 


I wrote the
following code:


import javax.swing.*; 
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.*;
import java.util.*;
 
public class FoodCaloriesGUI extends JFrame
{
private ObjectOutputStream outputFile;
private ObjectInputStream inputFile;
private String fileName="FoodCalories.txt";
//private int recordCount=0;
private int month, day, year,serving,calories,balance;
private String name,food,date;

public FoodCaloriesGUI()
{
super ("Food Calories calculator");
//readTextFile();
//openFileForReading();
readRecordAndDisplay();
String outputArea="name\n"+"Date"+date+"\n"+"Food\t"+"Serving \t"+"Calories\n"+
food+"\t"+serving+"\t"+calories+"\n"+"------------------------------"+"\n"+"Balance\t\t"+balance;
JLabel lblName, lblAge, lblWeight,lblHeight,lblFemale,lblMale,lblFood;
JTextField txtName, txtAge, txtWeight,txtHeight;
JButton btnSave, btnNewUser;
ButtonGroup radioGroup;
JTextArea dataarea =new JTextArea(outputArea);
JRadioButton rbMale,rbFemale;
JComboBox cbFood;
lblName= new JLabel("Name: ");
lblAge= new JLabel("Age: ");
lblWeight= new JLabel("Weight(lbs): ");
lblHeight= new JLabel("Height(inches): ");
lblFemale= new JLabel("Female: ");
lblMale= new JLabel("Male: ");
lblFood= new JLabel("Choose a Food: ");


txtName= new JTextField(15);
txtAge= new JTextField(3);
txtWeight= new JTextField(6);
txtHeight= new JTextField(6);


cbFood= new JComboBox();
cbFood.setPreferredSize(new Dimension(100, 20));

Container c = getContentPane();
JPanel northPanel = new JPanel();
northPanel.setLayout(new FlowLayout());
btnSave= new JButton("SAVE");
northPanel.add(btnSave);

btnNewUser= new JButton("NEW USER");
northPanel.add(btnNewUser);

//btnSave.addActionListener(this);
//btnNewUser.addActionListener(this);
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new FlowLayout());
centerPanel.add(lblName);

centerPanel.add(txtName);

centerPanel.add(lblAge);

centerPanel.add(txtAge);

centerPanel.add(lblWeight);

centerPanel.add(txtWeight);

centerPanel.add(lblHeight);

centerPanel.add(txtHeight);

centerPanel.setLayout(new FlowLayout());
rbMale= new JRadioButton("Male",false);
rbFemale= new JRadioButton("female",false);
radioGroup = new ButtonGroup();
radioGroup.add(rbMale);
radioGroup.add(rbFemale);
centerPanel.add(rbMale);
centerPanel.add(rbFemale);
centerPanel.add(lblFood);
centerPanel.add(cbFood);
JPanel southPanel = new JPanel();
southPanel.setLayout(new FlowLayout());
southPanel.add (dataarea);


c.add(northPanel,BorderLayout.NORTH);
c.add(centerPanel,BorderLayout.CENTER);
c.add(southPanel,BorderLayout.SOUTH);

setSize(650,300);
setVisible(true);
}
public void openFileForReading()
{
try
{
inputFile=new ObjectInputStream(new FileInputStream("foodoutput.txt"));
}
catch (IOException e)
{
JOptionPane.showMessageDialog(this, "error opening file", "Error",JOptionPane.ERROR_MESSAGE);
}
}
public void readTextFile()
{
double bmrmale=0.0,bmrfemale=0.0;
try
{
FileReader file=new FileReader(fileName);
BufferedReader inputFile=new BufferedReader(file);
outputFile=new ObjectOutputStream(new FileOutputStream("foodoutput.txt"));
String txtfileline=inputFile.readLine();
while (txtfileline!=null)
{
txtfileline= txtfileline.trim();
if (!txtfileline.equals(""))
{
StringTokenizer tokenizer = new StringTokenizer(txtfileline,"*");
String food= tokenizer.nextToken();
int serving=Integer.parseInt(tokenizer.nextToken());
int calories=Integer.parseInt(tokenizer.nextToken());
FoodCaloriesData record = new FoodCaloriesData(food,serving,calories);
JOptionPane.showMessageDialog(null,"current Object: " + record);
outputFile.writeObject(record);
outputFile.flush();
}
}
}
catch (IOException ioe)
{
JOptionPane.showMessageDialog(null,"Error reading ","Error",JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}

public void readRecordAndDisplay()
{

}

public static void main (String args[])
{
FoodCaloriesGUI app= new FoodCaloriesGUI();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
}






Text file: FoodCalories.txt

1000 ISLAND, SALAD DRSNG,LOCAL*1 TBSP*25

1000 ISLAND, SALAD DRSNG,REGLR*1 TBSP*60

100% NATURAL CEREAL *1 OZ*135

40% BRAN FLAKES, KELLOGG'S*1 OZ*90

40% BRAN FLAKES, POST*1 OZ*90





Class:FoodCaloriesData

 
import java.io.*; 
public class FoodCaloriesData implements Serializable
{
private String food;
private int serving;
private int calories;
public FoodCaloriesData ( String theFood,int theServing,int theCalories)
{
food=theFood;
serving=theServing;
calories=theCalories;
}
public int getServing()
{
return serving;
}
public String getFood()
{
return food;
}
public int getCalories()
{
return calories;
}
public void setServing(int theServing)
{
serving=( ( ( theServing > 0 ) && (theServing < 100) ) ?
theServing : 0 );
}
public void setFood(String theFood)
{
food="";
}
public void setCalories(int theCalories)
{
calories=( ( ( theCalories > 0 ) && (theCalories < 100) ) ?
theCalories : 0 );
}
}
 

 






 
Posted on 04-28-06 2:08 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

no one java professional inside java
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 365 days
Recommended Popular Threads Controvertial Threads
श्राद्द
TPS Re-registration
सेक्सी कविता - पार्ट २
What are your first memories of when Nepal Television Began?
पाप न साप घोप्टो पारि थाप !!
पुलिसनी संग - आज शनिवार - अन्तिम भाग
निगुरो थाहा छ ??
ChatSansar.com Naya Nepal Chat
TPS Re-registration case still pending ..
Lets play Antakshari...........
What Happened to Dual Citizenship Bill
Basnet or Basnyat ??
Sajha has turned into MAGATs nest
NRN card pros and cons?
is Rato Bangala school cheating?
मेरो अम्रिका यात्रा -२
Do nepalese really need TPS?
कता जादै छ नेपाली समाज ??
susta manasthiti lai ke bhanchan english ma?
कृष्ण नै अन्तिम सत्य
Nas and The Bokas: Coming to a Night Club near you
राजदरबार हत्या काण्ड बारे....
Mr. Dipak Gyawali-ji Talk is Cheap. US sends $ 200 million to Nepal every year.
Harvard Nepali Students Association Blame Israel for hamas terrorist attacks
TPS Update : Jajarkot earthquake
is Rato Bangala school cheating?
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters