Can i make this return a value for papers

class Consumers {
private String firstname;
String Area(){
String Area = "";
if(Area.equalsIgnoreCase("y")) Area = "Urban";
else Area = "Suburban";
return Area;
private String gender;
private static int age;
private String Paper;
private static boolean fashion = false, sports = false,
entertainment = false, healthcare = false;
private static final String Area = "";
/* declare a constructor to initialise */
/* new instances of class Consumers */
public Consumers(String f, String A, String g,
int a, String P) {
firstname = f;
String Area = A;
gender = g;
age = a;
Paper = P;
/* methods to retrieve values of instance variables */
public String getFirstname() {
return firstname;
public String getArea(){
return Area;
public String getGender() {
return gender;
public int getAge() {
return age;
public String getPaper() {
return Paper;
//method to see if paper and consumer are suitable
public boolean isCompatibleTo(String paper2) {
return false;
private static void NewsPaperSupplements() {
// if rules
if(age < 25) {
fashion = true;
if(age < 35){
fashion = true;
sports = true;
if(age < 40){
fashion = true;
if(age < 60){
healthcare = true;
class SundayPapersApplication {
public static void main (String args[]) {
String firstname;
String Area;
Consumers person1;
Consumers person2;
String district;
String gender;
int age;
String Paper = "";
String answer;
// Create a final int variable of 5 customers.
final int numberOfConsumers = 5;
// Stores customers.
Consumers[] allConsumers = new Consumers[numberOfConsumers];
Terminal terminal = new Terminal("");
// Loops and fills with customers.
for(int i = 0; i < numberOfConsumers; i++) {
/* ask user for information about 1st client */
terminal.println("Enter data for 1st person");
firstname = terminal.readString("Firstname: ");
Area = terminal.readString("Area: ");
gender = terminal.readString("Gender (male/female): ");
age = terminal.readInt("Age: ");
/* create a new Client instance with given information */
person1 = new Consumers(firstname, Area,
gender, age, Paper);
/* determine if the given clients are compatible */
terminal.print(person1.getAge() + " " + person1.getArea() + "");
if (person1.isCompatibleTo(Paper))
terminal.println("suitable.");
else
terminal.println("not suitable.");
// Create a new Customer object and store it on the i-th
// place in your array.
allConsumers = new Consumers (firstname, Area,
gender, age, Paper);
for(int i = 5; i < numberOfConsumers; i++) {
// Print customers to the 'terminal'.
out of curosity, now i want to know why it keeps returning void for papers.?
can anyone help again.

it prints out a terminal, which asks the user for the information.
what i was asked to do was return a paper...i.e. fashion / healthcare and entertainment to people under 25 and from an urban area.
the only thing my program does is take the values from the customer and store them to the screen.
i know it's intially set to null....so how do i get the papers applicable to the above age group to print to screen and say whether it is suitable for them. i've tried an IF/Else statement but it doesn't work and im getting even more confused.

Similar Messages

  • The book who I selected doesn't move to the right in CheckedListBox and the reason is that I can't make an return.his code is good just for first user who I selected

    Imprumut = loan
    I have 6 tables: 
    I have one combobox(from where I select utilizatori(users)) and 2 CheckedListBox(Between first box and second box I have 2 buttons:imprumuta(loan) and restituie(return))
    This c# code works just for first user: Utilizator, but something's not good. When I add new utilizator(user) and select it,  the loan will be add in my SQL DataBase, but... the book who I selected doesn't move to the right in CheckedListBox and the reason
    is that I can't make an return
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using MySql.Data.MySqlClient;
    namespace proiect
        public partial class Imprumut : Form
            MySqlConnection con = new MySqlConnection("DataSource=localhost;UserID=root;database=biblio1");
            //stabilim conexiunea
            MySqlCommand comUser;//interogarea pe baza careia umplem comboBox
            MySqlDataAdapter adaptu;
            DataTable userT = new DataTable();
            MySqlCommand cmdCarti;//interogarea pe baza careia umplem checkListBox
            MySqlDataAdapter adaptCarti;
            DataTable CartiTabel = new DataTable();
            MySqlCommand cmdCartiImprumutate;//interogarea pe baza careia umplem checkListBox
            MySqlDataAdapter adaptCartiImprumutate;
            DataTable CartiImprumutateTabel = new DataTable();
            public int UserId
                get
                    return Convert.ToInt32(user.SelectedValue.ToString());
            void Completez_Combo_User()
                try
                    comUser = new MySqlCommand("SELECT n.userid, CONCAT(n.UserName) as UserN FROM users n left join userroles us on n.userid=us.userid left join roles r on r.roleid=us.roleid WHERE r.roleid='3'",
    con);
                    adaptu = new MySqlDataAdapter(comUser);
                    adaptu.Fill(userT);
                    user.Items.Clear();
                    user.DataSource = userT;
                    //DataTable din care sunt preluate datele pentru ComboBox user
                    user.ValueMember = "UserID";
                    //Valoarea din coloana UserID nu se afiseaza in combobox
                    user.DisplayMember = "UserN";
                    //Eelementele afisate in combobox, preluate din concatenarea mai multor coloane
                catch (Exception ex)
                    MessageBox.Show(ex.Message);
            void Completez_CheckList_Carti()
                try
                    cmdCarti = new MySqlCommand("SELECT BookID, CONCAT(title, ' ', ISBN,' ',author)as date_carte FROM books WHERE NumberLeft > 0 ORDER BY BookID", con);
                    adaptCarti = new MySqlDataAdapter(cmdCarti);
                    adaptCarti.Fill(CartiTabel);
                    imp.Items.Clear();
                    //carti.DataSource=null;
                    imp.DataSource = CartiTabel;
                    //DataTable din care sunt preluate datele pentru ComboBox carte
                    imp.ValueMember = "BookID";
                    //Valoarea din coloana BookID nu se afiseaza in combobox
                    imp.DisplayMember = "date_carte";
                    //Eelementele afisate in combobox, preluate din concatenarea mai multor coloane
                catch (Exception ex)
                    MessageBox.Show(ex.Message);
                void Completez_CheckList_Cartires()
                    try
                        cmdCartiImprumutate = new MySqlCommand(string.Format("SELECT b.BookID, CONCAT(title, ' ', ISBN,' ',author) as date_carte FROM books b inner join userbooks ub on ub.bookid = b.bookid
    WHERE ub.userid = {0} ORDER BY BookID", UserId), con);
                        adaptCartiImprumutate = new MySqlDataAdapter(cmdCartiImprumutate);
                        adaptCartiImprumutate.Fill(CartiImprumutateTabel);
                        res.Items.Clear();
                        //carti.DataSource=null;
                        res.DataSource = CartiImprumutateTabel;
                        //DataTable din care sunt preluate datele pentru ComboBox carte
                        res.ValueMember = "BookID";
                        //Valoarea din coloana BookID nu se afiseaza in combobox
                        res.DisplayMember = "date_carte";
                        //Eelementele afisate in combobox, preluate din concatenarea mai multor coloane
                    catch (Exception ex)
                        MessageBox.Show(ex.Message);
            void Inregistrez_imprumut_in_BD()
                int useridu = Convert.ToInt32(user.SelectedValue.ToString()); //useridu = id book
                int bookidi;
                try
                    DateTime azi = System.DateTime.Now; //  Data imprumutului
                    DateTime atunci = termenul.Value;   //  Data restituirii
                    MySqlTransaction tranzactie = con.BeginTransaction();
                    MySqlCommand adaugImpr = new MySqlCommand("INSERT INTO bookshistory(UserID, BookID,BorrowDate) VALUES(@UserID, @BookID, CAST(@BorrowDate as datetime))", con);
                    MySqlCommand scadCarti = new MySqlCommand("UPDATE books SET numberleft=numberleft-1 WHERE bookid=@bookid", con);
                    MySqlCommand adauga_userbooks = new MySqlCommand("INSERT INTO userbooks(userId,bookID)VALUES(@userID,@bookID)", con);
                    adauga_userbooks.Transaction = tranzactie;
                    adaugImpr.Transaction = tranzactie;
                    scadCarti.Transaction = tranzactie;
                    try
                        foreach (int i in imp.CheckedIndices)
                            imp.SelectedIndex = i;
                            bookidi = Convert.ToInt32(imp.SelectedValue.ToString());
                            MessageBox.Show(bookidi.ToString());
                                     //bookidi va fi id-ul cartea bifata, pe rand din checklistBox
                                     //Inregistrez in tabela imprumut
                            adaugImpr.Parameters.AddWithValue("@UserID", useridu);
                            adaugImpr.Parameters.AddWithValue("@BookID", bookidi);
                            adaugImpr.Parameters.AddWithValue("@BorrowDate", azi);
                            adaugImpr.ExecuteNonQuery();
                            adaugImpr.Parameters.Clear();
                            adauga_userbooks.Parameters.AddWithValue("@userID", useridu);
                            adauga_userbooks.Parameters.AddWithValue("@bookID", bookidi);
                            adauga_userbooks.ExecuteNonQuery();
                            adauga_userbooks.Parameters.Clear();
                                    //Scad numarl de carti disponibile pentru cartea imprumutat
                            scadCarti.Parameters.AddWithValue("@bookid", bookidi);
                            scadCarti.ExecuteNonQuery();
                            scadCarti.Parameters.Clear();
                        tranzactie.Commit();
                    catch (Exception ex)
                        tranzactie.Rollback();
                        string message = ex.Message;
                        if (ex.Message.ToLower().Contains("duplicate entry"))
                            message = "Una dintre carti mai exista deja";
                        MessageBox.Show(message);
                catch (Exception ex)
                    MessageBox.Show(ex.Message);
            void Inregistrez_restituire_in_BD()
                int useridu = Convert.ToInt32(user.SelectedValue.ToString()); //useridu = id book
                int bookidi;
                try
                    DateTime azi = System.DateTime.Now; //  Data imprumutului
                    DateTime atunci = termenul.Value;   //  Data restituirii
                    MySqlTransaction tranzactie = con.BeginTransaction();
                    MySqlCommand modificIstoric = new MySqlCommand("UPDATE bookshistory SET returndate = @returnDate WHERE userID = @userID AND bookID = @bookID", con);
                    MySqlCommand adaugCarti = new MySqlCommand("UPDATE books SET numberleft = numberleft + 1 WHERE bookID = @bookID", con);
                    MySqlCommand sterge_userbooks = new MySqlCommand("DELETE  FROM userbooks WHERE userID = @userID AND bookID = @bookID", con);
                    sterge_userbooks.Transaction = tranzactie;
                    modificIstoric.Transaction = tranzactie;
                    adaugCarti.Transaction = tranzactie;
                    try
                        foreach (int i in res.CheckedIndices)
                            res.SelectedIndex = i;
                            bookidi = Convert.ToInt32(res.SelectedValue.ToString());
                            MessageBox.Show(bookidi.ToString());
                            //bookidi va fi id-ul cartea bifata, pe rand din checklistBox
                            //Inregistrez in tabela imprumut
                            modificIstoric.Parameters.AddWithValue("@UserID", useridu);
                            modificIstoric.Parameters.AddWithValue("@BookID", bookidi);
                            modificIstoric.Parameters.AddWithValue("@returnDate", termenul.Value);
                            modificIstoric.ExecuteNonQuery();
                            modificIstoric.Parameters.Clear();
                            sterge_userbooks.Parameters.AddWithValue("@UserID", useridu);
                            sterge_userbooks.Parameters.AddWithValue("@BookID", bookidi);
                            sterge_userbooks.ExecuteNonQuery();
                            sterge_userbooks.Parameters.Clear();
                            //Scad numarl de carti disponibile pentru cartea imprumutat
                            //adaugCarti.Parameters.AddWithValue("@bookid", bookidi);
                            adaugCarti.Parameters.AddWithValue("@bookid", bookidi);
                            adaugCarti.ExecuteNonQuery();
                            adaugCarti.Parameters.Clear();
                        tranzactie.Commit();
                    catch (Exception ex)
                        tranzactie.Rollback();
                        MessageBox.Show(ex.Message);
                catch (Exception ex)
                    MessageBox.Show(ex.Message);
            public Imprumut()
                InitializeComponent();
                try
                    con.Open();
                catch (Exception ex)
                    MessageBox.Show(ex.Message);
                Completez_Combo_User();
                Completez_CheckList_Carti();
                Completez_CheckList_Cartires();
                //selecteaza_carti_utilizator();
                //  Initializez termenul din dateTimePicker la data de peste 15 zile fata de data sistemului
                termenul.Value = System.DateTime.Now.AddDays(15);
            private void imprumuta_Click(object sender, EventArgs e)
                Confirmare c = new Confirmare("Confirmati imprumutul?");
                DialogResult dr = c.ShowDialog();
                if (dr == DialogResult.Yes)
                    try
                        Inregistrez_imprumut_in_BD();
                        MessageBox.Show("Imprumutul a fost inregistrat");
                        //Dupa inregistrarea imprumutului o parte din carti nu mai sunt disponibile pentru imprumut
                        //Reincarc in CheckList cu Carti noua lista cu carti ramase dupa imprumut
                        //Pentru asta "resetez" datele din dataTable cartiT (sursa pentru carti.DataSource)
                        CartiTabel.Clear();
                        adaptCarti.Fill(CartiTabel);
                        CartiImprumutateTabel.Clear();
                        adaptCartiImprumutate.Fill(CartiImprumutateTabel);
                    catch (Exception ex)
                        MessageBox.Show(ex.Message);
                if (dr == DialogResult.No)
                    MessageBox.Show("Imprumutul NU a fost inregistrat");
                    imp.ClearSelected();
                    //deselecteaza cartea selectat
                    foreach (int i in imp.CheckedIndices)
                        imp.SetItemChecked(i, false);
                    //debifeaza cartile bifate
                //if (imp.CheckedItems.Count > 0)
                //    //res.Items.Clear();
                //    foreach (string str in imp.CheckedItems)
                //        res.Items.Add(str);//adauga in partea cealalta, imprumuta
                //    while (imp.CheckedItems.Count > 0)
                //        imp.Items.Remove(imp.CheckedItems[0]);
            private void restituie_Click(object sender, EventArgs e)
                Confirmare r = new Confirmare("Confirmati restituirea?");
                DialogResult dr = r.ShowDialog();
                if (dr == DialogResult.Yes)
                    try
                        Inregistrez_restituire_in_BD();
                        MessageBox.Show("Restituirea a fost inregistrata");
                        //Dupa inregistrarea imprumutului o parte din carti nu mai sunt disponibile pentru imprumut
                        //Reincarc in CheckList cu Carti noua lista cu carti ramase dupa imprumut
                        //Pentru asta "resetez" datele din dataTable cartiT (sursa pentru carti.DataSource)
                        CartiTabel.Clear();
                        adaptCarti.Fill(CartiTabel);
                        CartiImprumutateTabel.Clear();
                        adaptCartiImprumutate.Fill(CartiImprumutateTabel);
                    catch (Exception ex)
                        MessageBox.Show(ex.Message);
                if (dr == DialogResult.No)
                    MessageBox.Show("Restituirea NU a fost inregistrata");
                    res.ClearSelected();
                    //deselecteaza cartea selectat
                    foreach (int i in imp.CheckedIndices)
                        res.SetItemChecked(i, false);
                    //debifeaza cartile bifate
                if (res.CheckedItems.Count > 0)
                    foreach (string str in res.CheckedItems)
                        imp.Items.Add(str);
                    while (res.CheckedItems.Count > 0)
                        res.Items.Remove(res.CheckedItems[0]);
            private void button2_Click(object sender, EventArgs e)
                con.Close();
                this.Close();
            //private void selecteaza_carti_utilizator()
            //    res.Items.Clear();
            //    MySqlCommand selectcart = new MySqlCommand("select title from books,userbooks where userbooks.userid='" + user.SelectedValue.ToString() + "' and userbooks.bookid=books.bookid", con);
            //    MySqlDataReader reader = selectcart.ExecuteReader();
            //    try
            //        while(reader.Read())
            //            res.Items.Add(reader["title"]);
            //    catch(Exception ex)
            //        MessageBox.Show(ex.Message);
            //    finally
            //        reader.Close();

    Hello Vincenzzo,
    This issue seems to be a window form UI implemented related issue, for this i suggest that you could ask it to the windows form forum:
    http://social.msdn.microsoft.com/Forums/windows/en-US/home?forum=winforms
    The current forum you posted to is used to discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I seem to be short on space for the trial download. How can I make this work????

    I seem to have less space for my download.How can I make this download happen?????? Will I have to uninstall my old Adobe Photoshop(which has long since worked) in order for this to be installed??

    What exactly are you trying to download on what system? Feel free to download to external drives to bypass the immediate bottleneck, but that may not resolve your issue once you install....
    Mylenium

  • Please make this a good experiance for my first post on any board.  READ ME

    Hi all. Well first off, let me start by saying that my whole life I've owned PC's. And I'm not hacker Elliet. But I've gotten to know them pretty well. All the way from Windows 3.1 that came out a long time ago (more than 10 years ago)
    So after a while of hearing about MAC's I decided to start small and get an iPod (since they are so popular here in NYC) and see what apple was about. Well I really saw that Apple had a great product and started asking about their computers. And did plenty of research. And before the new Intel Macs came out, I was going to get a powerbook. But I had a feeling a new laptop was coming out and waited a lil while and sure enough. The Macbook Pro came out. So I went out and did all my research (as to this being the first real purchase of a Apple product and knew about the possible implications of a new first gen Intel chip in a apple product litterally making history) I knew I might become a new beta tester.
    So I started looking on these boards and did 2 weeks worth of hard research to see if the Mac Book Pro (MBP) was for me. And after all the problems i saw (ex: The whine, Right speaker distortion, heat coming from it, white line at bottom of screen, etc) I never saw or read anything about AOL connectivity problems. And I know, I know... alot of you are probably going to gripe and complain about AOL sucking and yada yada yada, but please. Cut me some slack. I actually like AOL. I got on it back in 92 when it came out, and really enjoyed it. And have been on it since. I like chatting on there, and so forth. And I hope you help with my problem instead of telling me to go get "a real ISP" I do have a real ISP, but I like my AOL too.
    So now to my problem....
    I have a Sony Viao 1.8ghz PC with 512 ram, 80 gig hard drive, 10/100 ethernet port. Connected to a Belkin Router (more info below on specs of router) connected to Opt Online Broadband Cable internet with VoIP. I use my macbook pro on the wireless network at my home.
    I got a mac book pro 1.83 ghz running 512 ram on Tiger OSX 10.4.6 I thought that I would wait till a connectivity patch (which I thought would have been 10.4.6) fix the airport problems came out till I posted something. But now that I've tried everything, I'm hoping you open this thread and help me and possibly someone else out there as well. I just d/l'd and installed the 10.4.6 update last night and it did'nt help. So here's more info on my specs. I have a belkin router wireless G 2.4 ghz 54mbs router and I have configured the router with it's firewall, wap2 encryption (as it's the only selection the router has that is available that matches what airport comes with in encryption) I hid my network, and have tried to upgrade the firmware on the router.
    Now Here's the real problem. I can connect to AOL on my MBP when I connect the actual ethernet cable to the MBP's Ethernet port (after I have let the cable modem do a hard reset to configure itself to a mac) I can connect to AOL. But when I disconnect the cable and return it to it's normal config, I can't connect to AOL. I can connect to the internet via safari, and firefox, and even AOL's IM on iChat. I can use Itunes all kinds of things. I can even play warcraft 3 wirelessly on battlenet. But connecting to AOL is a pain in the @$$. It's the only proggy I have that won't allow it to connect. I keep getting the error message "Your AOL connection ended because the AOL host was unable to start a new session. Please try to sign on again." Of course All i see for a while is the spinning black and white circle. And it goes through step 1 and 2, goes straight to 6. Then it goes blank, and BAM! That message pops up. And what's so frustrating is that I've tried every possible configuration on AOL, my router and even system preferences, for it to let connect. I even went into system preferences on the mac and went down the the Internet & Network "Sharing" icon and tried 100 possible combinations on that in the services tab, and firewall tab. I've turned them on, off, tried to make exceptions ETC. And no matter how much I play with the personal file sharing and windows sharing advanced settings and sigh every possible combination to make AOL connect via wirelessly. And nothing. I then even tried to fix the connection under AOL in setup. I've gone through and selected TCP Script, Airport Script. Cable Script, And practically every script I can think of. And nothing. I even went on to AOL and downloaded thier alleged fix to wireless accessing AOL. And nothing. I've been searching all over google, AOL's website, and all over these discussion boards and no mention of anyone even having the same problem. But please, someone out there with their infinit knowledge of how Macs run and having more experience than me, Please make this a good experiance for my first post on any board anywhere reguarding a mac. A MBP at that too.
    An update to this, But amazingly enough, I actually got it to connect to AOL wirelessly for the first time yest. But I have no Idea how i did it. I tried for 3 hours to reproduce it and no luck. I was accessing my router at it's website config screen and somehow I clicked on connect to AOL and while it was trying to connect to it, i reset the router and BAM, it connected to AOL. And I was in shock. I thought I solved it. Somewhere while it was reseting the router it connected and stayed connected to AOL till I signed off and tried to sign back on to see if I could now connect, and guess what. The same dumb message keeps popping up "Your AOL connection ended because the AOL host was unable to start a new session. Please try to sign on again." And all I did was sign off to test it, thinking I had fixed the problem. I tried for 3 hours like I stated above, and BAM got it connected to AOL wirelessly again (somehow while the router was resetting). And thinking I fixed it, or figured out the trick to getting it to work, signed off... I kissed aol goodbye again. And have been unable to reproduce the "glitch". SIGH Can someone out there please help me?
    I think I've made this message as detailed as possible, but please, can someone give me some constructive criticism on how to fix my AOL wireless connectivity problems. Do you know if it's my router? My MBP? AOL software? BTW, I got AOL software version 10.3.7 (Rev 4136.310 US) The latest version I D/L'ed from the AOL website. Anyone know If I should turn on or off some things such as personal fire sharing on, or firewall off or on? ANYTHING. Please. I've put alot of time into writing this post and making it as detailed as possible. And been having this problem for the past 3 weeks that I've had my MBP, and have waited long enough to use my AOL. If you need any further information or suggestions on making AOL work, please let me know. Thank you for taking the time to read all of this, and I really appreciate all of you in the time you take in responding back in trying to help me. I'll be monitoring this post almost hourly. So I hope someone out there can help. Thanks so much again. And help me make this transition to Mac a pleasant one knowing that there is a mac community out there willing to help a new mac client. Again, Many thanks
    In Heath and Wealth,
    Bruce
    Mac Book Pro 1.83 GHZ 512 Ram   Mac OS X (10.4.5)  

    I FIXED IT!
    FYI for the rest of you that might be having the same problem. DON'T USE A BELKIN ROUTER WITH AOL ON A MBP!!!!! It ***** wirelessly. or even hard connected, it won't connect. I went to best buy today, and got a refund on the belkin. I then went to J&R and got a D-Link router. And now it works perfect. I can now chat on AOL yet again, and I tried all the other web browsers I have and messengers, and warcraft 3 online via battlenet. And it works great. I want to give you guys a special thanks for taking time out to answer back to my post. FYI! Belkin wireless G routers do not connect you to AOL wirelessly on MBP's. No matter how much you mess around on them. I highly recommend a D-Link Router. They are easy to set up as long as you READ ( AND I MEAN IT!!!) read the instructions before you set anything up on it. Use the CD that it comes with, and you'll be good to go. Set it up and it works great Almost no dead zones in the house, and now I can use the MBP with all it's cababilities. Thanks people. I really appreciate it.
    P.S. I called belkin last night when i decided to get a refund on my router for today and when i talked to the tech, after puersuading him to tell me the truth. And stop BS'ing me, he broke down and admited that AOL does not work wirelessly on MBP's. So to make a long story short this time, There you go. And one last note, I'm very happy now with my d-link router. I honestly thought it would suck. Not being a brand name router or anything. But amazingly, it works like a brand name item! Again, many thanks all.
    Bruce

  • How can I make this code faster? optimized.

    Its part of two jsp pages that go back and forth. I feel I am creating new strings all of the time. I have 3 graphic representations of a radion button and a check box. its for a quiz program.
    if the button is not checked, it uses rd0.gif.
    if the button is checked, then its assigned rd1.gif.
    However, if the button is the wrong answer, then its assigned rd2.gif.
    the use of char arrays is neccasary, but not vital, I guess I could use indexof in the string. But I Dont know if its faster. I want to optimize the code, so it uses less resources.
    heres the code
    TrueFalse=entry[11].indexOf("TRUE");
    myButton = Integer.parseInt((String)session.getAttribute("BUTTONNO"));
    GivenAnswer =(String)session.getAttribute("GIVEN");
    if(TrueFalse==-1) {
    char[] questions = GivenAnswer.toCharArray();
    for(x=1;x<5;x++) {
    if(questions[x]=='1') { bp[x]="images/ck1.gif"; }else{ bp[x]="images/ck0.gif";}
    }else{
    if(myButton==1) {bp[1] = "images/rd1.gif";} else {bp[1] = "images/rd0.gif";}
    if(myButton==2) {bp[2] = "images/rd1.gif";} else {bp[2] = "images/rd0.gif";}
    questions is discarded.
    the quiz is fast at the begining, but once you go deeper and deeper it slows down. This is the second page:
    <%@ include file ="include4.jsp" %>
    <%
    session.setAttribute("BUTTONNO", "1");
    GivenAnswer =(String)session.getAttribute("GIVEN");
    char[] questions = GivenAnswer.toCharArray();
    questions[1]='1';
    tempString = new String (questions);
    GivenAnswer = tempString;
    session.setAttribute("GIVEN", GivenAnswer);
    %>
    <jsp:forward page="train2.jsp">
    </jsp:forward>
    I tried to keep all of the code on one page, but I am using images instead of real radio buttons, for several reasons. JSP doesnt seem to return a value for check/radio buttons in JSP, so clicking on an anchored image and going to a second JSP PAge seemed reasonable. I dont know how to force garbage collection. But the speed in which the pages and images appear, get slower and slower. so I Think im using up memory (Stings) at a greater rate than I should.
    thanks
    MIKe NIEMI
    [email protected]

    I'm not sure that an "optimisation" is necessarily what you're after. I doubt it's the creation of Strings that's causing any performance issue - even if it is then it's probably the result of something more sinister.
    Don't assume that your code is using a lot of resources.
    For example it's tempting to change it to this:
    if(myButton==1) {bp[1] = "images/rd1.gif";} else {bp[1] = "images/rd0.gif";}
    if(myButton==2) {bp[2] = "images/rd1.gif";} else {bp[2] = "images/rd0.gif";}
    // change to this?
    bp[myButton] = "images/rd1.gif";
    bp[3 - myButton] = "images/rd0.gif";I'd say that the original code was clearer and used just as many resources (once the Strings are interned).
    The same goes for this:
    if(questions[x]=='1') { bp[x]="images/ck1.gif"; }else{ bp[x]="images/ck0.gif";}
    // change to this?
    bp[x] = "images/ck" + questions[x] + ".gif";Again, the former is possibly clearer as it indicates that questions is really a boolean flag - it should also be easily optimised by the compiler.
    You're right that you could replace "questions" by simply using GivenAnswer.charAt(x).
    Enterprise Java applications can generate hundreds of thousands of Strings during their execution - your Servlet is unlikely to have a serious impact on that unless you've got an enormous loop in there or a very large user base.
    A golden rule of optimisation is not to assume that you know where the performance/resource bottlenecks are. Measure the improvement you get from a change - does it warrant the resultant increase in the complexity of the code?
    Put some profiling in your code - how long is it taking to run your Servlet? How many times is it being invoked? I can't imagine that the code you've provided will take more than a few milliseconds to run.
    Also, you can't force garbage collection. You can suggest it to the Java runtime (it might not even have a garbage collector!). However, this generally indicates a flaw in the application and should be avoided unless absolutely necessary (and it's not in this case!).
    If you really want to optimise then get hold of something like OptimizeIt - it will provide a great deal of information about what's being created and where.
    Hope this helps.

  • I got a new computer. How do I make this the primary pc for all of my apple devices?

    I purchased a new pc. How do I make this the primary pc for iTunes and all of my apple devices? I need to know how to take all Itunes files off old pc and put on new pc. Also, disable old pc.

    Backup your library using this User Tip.
    The same tool can be used to backup other important user data.
    Deauthorise the old computer
    Restore the library into the music folder of your new profile. (Use the same tool as for the backup)
    Install iTunes and sign in to your account.
    tt2

  • I have a spare Apple display screen an would like to make this a second screen for my iMac, would like some help on how to do this

    I have a spare Apple display screen and would like to make this a second scren for my iMac,
    would like to have some ideas on how to do this
    laro.t

    First format the drive to OS X Extended (journaled) with ownership set to be ignored:
    Next drag your iPhoto library from your Pictures folder to the EHD.  When the copying is complete launch iPhoto with the Option key held down and in the window that comes up select the library on the EHD:
    Check the file path under the window to make sure the correct library has been selected.
    Once you've confirmed that the EHD library is working properly and has all of your photos you can delete the library in your Pictures folder.
    OT

  • When filling out a form, some fields copy to others when I tab to the next. How can I make this stop?

    When filling out a form, some fields copy to others when I tab to the next. How can I make this stop?

    You can't using Adobe Reader. It looks like whomever created the form used the same identifiers (names) for various fields. Each field with the same name will populate with the information used in another field of the same name. This is intentional.
    Normally when I see this, it tells me that someone created an initial field then copy/pasted it to make additional fields but forgot to change the names.

  • Just restored my iPhone from iCloud. My wife and I have always shared one iCloud ID. But since my restore, when a call comes in, it rings on both my phone and hers. How can I make this stop?

    Just restored my iPhone 5  from iCloud. My wife and I have always shared one iCloud ID. But since my restore, when a call comes in, it rings on both my phone and hers. How can I make this stop?  We had it all set up fine before the restore, and there was a trick to it in the settings.  I've noticed that since my restore, her phone has picked up what looks like the symbol of a phone in the upper right corner of the display, right next to the Bluetooth symbol.

    Hi Big Slick,
    Welcome to the Apple Support Community!
    It sounds like your iPhones may be using a new feature in iOS 8 called Continuity. The following article and information explains how to set up this feature for phone calls. You can review the information on the setup to reverse this effect. My suggestion would be to turn off FaceTime on one of the devices.
    Connect your iPhone, iPad, iPod touch, and Mac using Continuity
    Phone calls
    With Continuity, you can make and receive cellular phone calls from your iPad, iPod touch, or Mac when your iPhone is on the same Wi-Fi network.
    To make and receive phone calls, here's what you need:
    Sign in to the same iCloud account on all your devices, including your Mac.
    Your iPhone and your iPad or iPod touch need to use iOS 8 or later. Your Mac needs to use OS X Yosemite.
    All devices must be on the same Wi-Fi network.
    All devices must be signed in to FaceTime using the same iCloud account. This means any device that shares your Apple ID will get your phone calls. Look below for instructions on how to turn off iPhone cellular calls.
    Wi-Fi Calling needs to be off. Go to Settings > Phone. If you see Wi-Fi Calling, turn it off.
    Cheers,
    Joe

  • How can I make Adobe Reader 9 open for incoming PDFs instead of Acrobat 5.0?

    How can I make Adobe Reader 9 open for incoming PDFs instead of Acrobat 5.0?

    Hi,
    Assuming that you have Reader 9.3.4 already installed on your machine, you can try the following to make Reader 9.3.4 as the default PDF opening application:
    1. Right click on any PDF on your system and click on the "Open With" Option in the context menu that appears. In case you get another submenu, click on Chose Program in that menu. (In case you do not see any "Open With" option, then hold down the Shift key and right click on the file)
    2. Click on Browse button in the dialog that appears, and select Reader 9. Make sure that you select the checkbox for "Always use the selected program to open this kind of file"
    3. Click on OK.
    This will make Adobe Reader 9 as the default viewer for all PDFs on your system.

  • Can i make a method to wait for 2 mins before executing in java??

    can i make a method to wait for 2 mins before executing??
    i mean when i execute a method ....it has to wait for 2 mins before finally executing...
    can i do this in java????
    Thanks,

    Sure, put this at the beginning of the method.
    try
        Thread.sleep(120000);
    catch (Exception ex)

  • How can I make this shape?

    How can I make this shape in fireworks:
    I want some images in my website to have rounded corners. Im doing this by adding 4 divs with background images and absolutely positioning them, one over each corner of the image. The background images are PNGs with transparent areas. This works as the site's background is a solid color, so the rounded corners dont need to actually be transparent.
    The issue im having is that the pixels on the curve need to be semi transparent. Id love to make this shape as a vector but I dont know how.
    Thanks

    Hi,
    There is another simple way to get the shape desired. Create a rounded rectangle that is twice your corner size - both width and height wise. Now adjust the rounded corners to almost make a circle (pull the yellow corner handle towards the center of the side). Now click the corner and you will be able to toggle between the different corner types. You can now either use the shape as it is (if you need it for corners of a sprite rounded rectangle) or you can cut it up to get the desired wedge.
    - Anita

  • Just upgraded to mountain lion, when I open iphoto or photoshop, the monitor color changes.  How can I make this stop?

    For some reaon, when I launch iphoto, or any other photo program, my monitor changes to a different scheme.  How can I make this stop?  Thanks.

    try disabling it, take a took at these snaps from my phone. Might not be really clear but can give you an idea
    Hope this is clear,
    Thanks for the suppport
    Nazmul

  • MacBook Pro (OS X 10.9.1) calendar continues to "connect to server" and will not allow shut down or restart. Force quit worked. How can I make this calendar "behave"?

    MacBook Pro (OS X 10.9.1) calendar continues to "connect to server" and will not allow shut down or restart. Force quit worked. How can I make this calendar usable? The problem began after I updated to Maverick.

    babowa, it seems like it is using Fuse & NTFS, so I don't think it's the classic WD + 10.9 mess, but extra WD tools & drivers can still break things MtTran.
    MrTran, if you must use unsupported disk formats on your Mac you must also consider actually paying the developers that made the trial software.
    It's probably a good idea to follow the developers removal instructions, reboot & then install one tool at a time.
    MacFuse, FuseOSX, NTFS-3G are all likley to confict if you run older versions so you need to be sure you are using the latest version. I can't remeber which one depends on the other, so you will need to read the manuals.
    When the disk is readable copy the data to another disk. You could probably do this from a Linux distro or Windows if OS X won't do it.
    If you insist on only using the trial versions you will need to reinstall Mac OS, copy data off this disk & reformat it.
    Is there any good reason for not using the Mac HFS extended format?

  • HT201317 since I have down loaded the iOS7 software my photos are no longer up loaded to my laptop. How can I make this start happeing again?

    Since I have downloaded the iOS7 software my photos no ,longer automatically sync and upload to my lap top. How can I make this happen again?

    Hi missvashenca,
    Thanks for using Apple Support Communities.  If your photos are not appearing on your computer from your iOS device anymore through Photo Stream, I'd first verify that the Photo Stream service is still enabled on your iOS device:
    iCloud: Set up Photo Stream
    http://support.apple.com/kb/PH2605
    If it is, you may also want to try switching it off and back on again.
    Likewise, I would also try this with your computer's Photo Stream settings.
    As always, I recommend backing up your photos before performing troubleshooting:
    iOS: How to back up and restore your content
    http://support.apple.com/kb/ht1766
    Cheers,
    - Ari

Maybe you are looking for

  • Error during creation of Billing Document

    Dear All, we are getting an error while creatin billing document . The error message is as follows. 1.0154000188 000010 Order item 0139000078 000010 is missing . Here my delivery number is 0154000188 . my order no is  0139000078. when i go technical

  • That USB/Firewire question again

    OK, I've done my research, no converter exists. Just bought my fiance a 60gb iPod to replace his old white one which had died. But he has been keeping his music on our old blue G3, and both its USB ports are occupied - keyboard and external hard driv

  • How to deinstall OMS10g binaries after OMS11g upgrade

    I've upgraded Grid Control from 10.2.0.5 -> 11.1.0 on our RHEL5 server. I now want to deinstall OMS10g, but when I run the installer, I don't see an OMS10g home in the list of homes available (I only see my 11g database, and OMS11g homes). The 10.2 G

  • How can I transfer files from my iPod to my Mac?

    I lost a bunch of old podcasts from my Mac and they are no longer on iTunes. I do have them on my iPod but I don't want to connect it to my Mac and have it sync up and lose the tracks. Is there a way to upload or transfer files or songs from my iPod

  • FF OPC read & write Mode Status

    How do I read & write to a block Mode Status using the OPC server.  For example I thought that each (such as Actual, or Target, etc) would be a bit mapped byte with each bit representing a mode, but it does not seem to work this way.