Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

When I compile to get the survey title the overload constructor asks for title name input else the default constructor sets a default name. My code ask for the title and after I enter it hangs until I enter it again

Import java.util.Scanner;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

//package surveyproject;

public class Survey {

//declare variables
private static int respondentID;
public String surveyTitle;
public int initial_menu_Choice;
public int[][] ansArray = new int [3][3];
public String[] questArray = new String [3];
Scanner scan = new Scanner(System.in);

//default constructor
public Survey(){
surveyTitle = "Customer Survey";

}

//constructor with parameter
public Survey(String title){
respondentID = 0;
surveyTitle = title;

}

//method to get survey title
public String getSurveyTitle(){

return surveyTitle;
}

//method to get respondent ID
public int getRespondentID(){
return respondentID;
}

//method to generate respondent ID
public int generateRespondentID(){

//increments the respondent ID
respondentID++;

return respondentID;
}

public void setIntialMenuChoice(int inti_menu_choice){
initial_menu_Choice = inti_menu_choice;
}

//display survey results
public void displaySurveyResults(){
//print name of survey
//print ansArray
System.out.println("Survey: "+ surveyTitle);
System.out.println("Results of the survey: ");
System.out.print("Respondent ID| Q1\tQ2\tQ3 \n");
for(int i = 0; i < 3; i++){
System.out.print(" " + i + " | ");
for(int j = 0; j < 3; j++){
System.out.print(ansArray[i][j]+"\t");
}
System.out.println("\n");
}
}

public void displayQuestionStats(int questNum){
//display response entered for 'questNum'

System.out.println("Question stats for Question: "+questNum+" "+questArray[questNum-1]);
for(int i = 0; i < 3; i++){
System.out.println(ansArray[i][questNum-1]);
}

}

void enterQuestions(){

Scanner scan = new Scanner(System.in);
//user will enter 3 questions to be stored in string array
System.out.println("Enter 3 questions to create a survey");
for(int i = 0; i < 3; i++){
System.out.println("Enter question "+(i+1)+":");
questArray[i] = scan.next();
}

}

public void logResponse(int id, int questNum, int response){
//enter response in the matrix
ansArray[id][questNum] = response;
}

//user to fill in the survey questions
public void completeSurvey(int id){
System.out.println("Respondent "+ id+ " is taking survey");
Scanner inp = new Scanner(System.in);
int resp ;
System.out.println("Answer each question with number between 1 to 5");
for(int i=0; i<3; i++){
System.out.print("Question "+(i+1)+":");

//present question displayed to respondent
presentQuestion(i);

//check to see if input is within parameters
while(!inp.hasNextInt()){
System.out.println("Incorrect! Re-enter your choice: ");
inp.next();
}

resp = inp.nextInt();

//check for value of input between 1 and 5
while(resp < 1 || resp > 5){
System.out.print("Incorrect! Re-enter your choice: ");
resp = inp.nextInt();
}

//log the response
logResponse(id, i, resp);

}
}

//returns the number of the question that had the most positive responses.
public int topRatedQuestion(){

int countArr[] = new int[3];
int count;
//loop through respondentMatrix and find ques which has response of 5
for(int questNum = 0; questNum < 3; questNum++){
count=0;
for(int id = 0; id < 3; id++){
if(ansArray[id][questNum] == 5)
count++;
}
countArr[questNum]=count;

}

//find ques which has max value of count in countArr
int max = countArr[0];
int topQues=0;
for(int i=0; i<3; i++){
if(max < countArr[i]){
topQues = i;
max = countArr[i];
}
}

return topQues;

}

//returns the number of the question that had the lowest responses.
public int lowRatedQuestion(){
int countArr[] = new int[3];
int count;

//loop through ansArray and find questNum which has response of 1
for(int questNum = 0; questNum < 3; questNum++){
count=0;
for(int id=0; id<3; id++){
if(ansArray[id][questNum] == 1)
count++;
}
countArr[questNum]=count;
}

//find ques which has max value of count in countArr

int min = countArr[0];
int minQues = 0;
for(int i = 0; i < 3; i++){
if(min < countArr[i]){
minQues = i;
min = countArr[i];
}
}

return minQues;
}

//display 'ques' to the user from questions array
public void presentQuestion(int questNum){

//System.out.println("Question"+ques+" requested: ");
System.out.println(questArray[questNum]);
}

//overloaded method: both the respondent ID and the question will be displayed
public void presentQuestion(int questNum, int id){
System.out.println("Respondent "+id +", please respond to the following survey question:");
System.out.println(questArray[questNum]);
}

}

import java.util.Scanner;

public class SurveyConductor {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);
String surveyTitle;

System.out.println("Would you like to name your survey? Enter yes or no");

String answer = scan.next();

if(answer.equalsIgnoreCase("yes") || answer.equalsIgnoreCase("y")){

System.out.println("Please enter a name for your survey");
Scanner input = new Scanner(System.in);
surveyTitle = input.next();
Survey s = new Survey(surveyTitle);

}
else{

Survey s = new Survey("Customer Survey");

}
Survey dSurvey = new Survey(scan.next());{
dSurvey.enterQuestions();

}

do{
//respondent id of current respondent
int id = dSurvey.getRespondentID();
System.out.println("Respondent "+ id + "Please answer survey questions");

//respondent fills the survey
dSurvey.completeSurvey(id);

System.out.println("Are there more respondents (yes/no)?");

answer = scan.next();

//respondent id is generated
dSurvey.generateRespondentID();

}

while((dSurvey.getRespondentID() < 3) &&(answer.equals("yes") || answer.equals("Yes")));
//and there are more respondents
//displays survey results
dSurvey.displaySurveyResults();

//find question that had top responses
int top = dSurvey.topRatedQuestion();

System.out.println("Top rated question is: "+(top+1));

//find question that had lowest responses

int low = dSurvey.lowRatedQuestion();

System.out.println("Low rated question is: "+ (low+1));

//ask user to enter a number of question that they want to view

System.out.println("Enter a question number, you want to view "+ "results for: ");

int num = scan.nextInt();

//displays stats for question number entered

dSurvey.displayQuestionStats(num);

}
}

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91341030
  • Price:- $20

Guranteed 24 Hours Delivery, In Price:- $20

Have any Question?


Related Questions in Computer Engineering

On microsoft word what would be the advantage of using the

On Microsoft word, what would be the advantage of using the dialog box over setting various tabs directly on the ruler line? In what types of typing tasks would you find using the ruler line helpful?

Question discuss the advantages and disadvantages of

Question: Discuss the advantages and disadvantages of Incident Response testing. When is each type of testing appropriate? Are there situations that preclude the use of a particular type of testing? Requirement: I recomm ...

Question group work this weekbull introduce yourself to

Question: Group work this week: • Introduce yourself to your group • Start planning out the project with your group • The group should compile the following information into a draft document 1. What specific and detailed ...

Explain the two real world examples of database what are

Explain the two real world examples of database. What are they? How do people use them? Discuss at least one situation that would arise from problems in these database, such as redundant information, breach of informatio ...

42 of the cars in a dealer lot are red 21 are black and 10

42% of the cars in a dealer lot are red, 21% are black and 10% are white. The remainder are some other unspecified color. Salespersons randomly shows three cars to three different customers. What is the probability the f ...

Assignment -note in your assignment how you arrived at your

Assignment - Note: In your assignment, how you arrived at your solution is as important (if not more so) than the solution itself and will be assessed accordingly. There may be more than one way to find a solution, and y ...

What are some of the skill sets required for the various

What are some of the skill sets required for the various aspects of cloud administration. Are there any certifications related to cloud computing? Is there value in obtaining one of these certifications?

These sctp data chunks have arrived carrying the following

These SCTP DATA chunks have arrived carrying the following information: TSN:20 SI:2 SSN:8 BE:11 TSN:21 SI:2 SSN:9 BE:10 TSN:12 SI:2 SSN:7 BE:11 TSN:18 SI:3 SSN:15 BE:01 TSN:15 SI:3 SSN:15 BE:00 TSN:24 SI:1 SSN:23 BE:10 I ...

Question the redblue computation simulates two interactive

Question : The Red/Blue computation simulates two interactive flows: an n × n board is initialized so cells have one of three colors: red, white, and blue, where white is empty, red moves right, and blue moves down. Colo ...

Reminder all files must be closed when you are done with

Reminder: All files must be closed when you are done with them, even if it stops early due to an IOError. If you're using with, this will happen automatically. If you're trying to close things manually using .close(), th ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As