473,473 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Use any kind of loop to fate my problem

4 New Member
hi,guys i have a problem about in java, My question is....Write a program named survey.java that displays a serves of survey question,with one-character answer.At the end of the survey, ask the user if he/she wants to enter another set of responses.If the user responds no, then displays the result of the survey for each question...so guys that is my problem and I hope u can help me...thanks
Jul 4 '07 #1
8 1596
anubhav vij
27 New Member
wats ur problem dear????
plz mention clearly.....
hi,guys i have a problem about in java,
Jul 4 '07 #2
anubhav vij
27 New Member
have u written some code for it till now???
if yes then mention it over here....
Jul 4 '07 #3
markrey
4 New Member
wats ur problem dear????
plz mention clearly.....
ok..guys thanks for reply..i hope u can help me that/
Jul 4 '07 #4
markrey
4 New Member
have u written some code for it till now???
if yes then mention it over here....
yes i make a code of that problem,but my teacher did'nt accept my code bcoz we did'nt disccus about System.in.read...we use only System.out.print...and also we use above import javax.swing.*;

This is my code, and my teacher did'nt accept it...we did'nt use throw Exception, we only use import


Expand|Select|Wrap|Line Numbers
  1.  public class Survey{
  2.     public static void main (String[] args) throws Exception { 
  3.         String ques1 = new String("Is your family happy? ");
  4.         String ques2 = new String("Is your father have a work? ");
  5.         String ques3 = new String("Is mother have a work? ");
  6.         String ques4 = new String("All of you here studying? ");
  7.         String question;
  8.         char selection, answer, response;
  9.         char another = 'y';
  10.         int i;
  11.         while (another == 'y') {
  12.             int numCorrect = 0;
  13.             for (i = 1; i <= 4; i++) {
  14.                 if (i == 1) {
  15.                     question = ques1;
  16.                     answer = 'y';
  17.                 }
  18.                 else if (i == 2) {
  19.                     question = ques2;
  20.                     answer = 'n';
  21.                 }
  22.                 else if (i == 3) {
  23.                     question = ques3;
  24.                     answer = 'n';
  25.                 }
  26.                 else {
  27.                     question = ques4;
  28.                     answer = 'n';
  29.                 }
  30.                 System.out.println("Enter y or n for the following questions");
  31.                 System.out.print(question);
  32.                 response = (char)System.in.read();
  33.                 System.in.read();
  34.                 System.in.read();
  35.                 if (response == answer) {
  36.                     System.out.println("Correct!");
  37.                     numCorrect++;
  38.                 }
  39.                 else
  40.                     System.out.println("Incorrect!" +
  41.                             "\nCorrect answer is " + answer);
  42.             }
  43.             System.out.println("\nNumber of correct answers: " + numCorrect);
  44.             System.out.print("\nEnter another set of responses (y or n):");
  45.             another = (char)System.in.read();
  46.             System.in.read();
  47.             System.in.read();
  48.         }
  49.     }
  50. }
Jul 4 '07 #5
r035198x
13,262 MVP
ok..guys thanks for reply..i hope u can help me that/
Well you write the program and post if you get problems with it. We'd like to help but we don't want to do the whole thing for you.
Jul 4 '07 #6
anubhav vij
27 New Member
buddy i didn't get u completely.......

wats ur main problem u subscribe that here.....
ur proper question...???
Jul 4 '07 #7
markrey
4 New Member
Well you write the program and post if you get problems with it. We'd like to help but we don't want to do the whole thing for you.
ok,,use also JOptionPane

public class Survey{
public static void main (String[] args) throws Exception {
String ques1 = new String("Is your family happy? ");
String ques2 = new String("Is your father have a work? ");
String ques3 = new String("Is mother have a work? ");
String ques4 = new String("All of you here studying? ");
String question;
char selection, answer, response;
char another = 'y';
int i;
while (another == 'y') {
int numCorrect = 0;
for (i = 1; i <= 4; i++) {
if (i == 1) {
question = ques1;
answer = 'y';
}
else if (i == 2) {
question = ques2;
answer = 'n';
}
else if (i == 3) {
question = ques3;
answer = 'n';
}
else {
question = ques4;
answer = 'n';
}
System.out.println("Enter y or n for the following questions");
System.out.print(question);
response = (char)System.in.read();
System.in.read();
System.in.read();
if (response == answer) {
System.out.println("Correct!");
numCorrect++;
}
else
System.out.println("Incorrect!" +
"\nCorrect answer is " + answer);
}
System.out.println("\nNumber of correct answers: " + numCorrect);
System.out.print("\nEnter another set of responses (y or n):");
another = (char)System.in.read();
System.in.read();
System.in.read();
}
}
}
Jul 4 '07 #8
r035198x
13,262 MVP
ok,,use also JOptionPane

public class Survey{
public static void main (String[] args) throws Exception {
String ques1 = new String("Is your family happy? ");
String ques2 = new String("Is your father have a work? ");
String ques3 = new String("Is mother have a work? ");
String ques4 = new String("All of you here studying? ");
String question;
char selection, answer, response;
char another = 'y';
int i;
while (another == 'y') {
int numCorrect = 0;
for (i = 1; i <= 4; i++) {
if (i == 1) {
question = ques1;
answer = 'y';
}
else if (i == 2) {
question = ques2;
answer = 'n';
}
else if (i == 3) {
question = ques3;
answer = 'n';
}
else {
question = ques4;
answer = 'n';
}
System.out.println("Enter y or n for the following questions");
System.out.print(question);
response = (char)System.in.read();
System.in.read();
System.in.read();
if (response == answer) {
System.out.println("Correct!");
numCorrect++;
}
else
System.out.println("Incorrect!" +
"\nCorrect answer is " + answer);
}
System.out.println("\nNumber of correct answers: " + numCorrect);
System.out.print("\nEnter another set of responses (y or n):");
another = (char)System.in.read();
System.in.read();
System.in.read();
}
}
}
When posting code, please use code tags like the ones I've added for you above. Now, were you asked to use JOptionPane by your teacher?
Jul 4 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

28
by: John Bailo | last post by:
Funny, how Bill Gate uses the Deutsches Bank and Barron's to defraud people and try to wreck his competitors ( he can't ). For example, ...
383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
4
by: Scott Smedley | last post by:
Hi all, I'm trying to write a special adaptor iterator for my program. I have *almost* succeeded, though it fails under some circumstances. See the for-loop in main(). Any pointers/help...
3
by: Major_Small | last post by:
would you include infinite loops, possibly infinite loops, unaccounted for user input, infinite recursion, and that type of thing? if so those are probably my biggest problems... more...
5
by: Jani Yusef | last post by:
Based on an interview question I heard of but did not know the answer to....... How do you find and remove a loop from a singly linked list? In a google groups search I found the following code...
149
by: Christopher Benson-Manica | last post by:
(Followups set to comp.std.c. Apologies if the crosspost is unwelcome.) strchr() is to strrchr() as strstr() is to strrstr(), but strrstr() isn't part of the standard. Why not? --...
17
by: Raymond Hettinger | last post by:
I'm considering deprecating these two functions and would like some feedback from the community or from people who have a background in functional programming. * I'm concerned that use cases for...
0
by: lokey03081 | last post by:
fate 1.21a crack http://cracks.00bp.com F R E E
0
by: cardo44541 | last post by:
fate crack http://cracks.00bp.com F R E E
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.