Define get the survey title the overload constructor

Assignment Help Basic Computer Science
Reference no: EM13771269

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);

}
}

Reference no: EM13771269

Questions Cloud

Problems that safety and health managers : Explain the types of problems that safety and health managers can expect to confront in attempting to implement their own programs? Based on your own workplace environment how would you attempt to manage stress as a safety and health manager?
Determine the pertinent demographic social factors : Determine the pertinent demographic, social, political, and economic factors about your chosen country. Examine the manner in which your chosen country's criminal code would likely view the crime you witnessed. Provide a rationale for the response
Efficiency of human recourse management : The role of recruitment and selection in raising efficiency of Human Recourse Management.
Define get the survey title the overload constructor : 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
A symbol of interpersonal harmony : You have made an important presentation to several Japanese executives regarding a proposed partnership between your American company and their Japanese firm. The Japanese executives were very silent during the presentation. Most people in the United..
What civil rights laws may prohibit marwans conduct : What civil rights laws may prohibit Marwan's conduct with his fellow co-worker? Do those laws apply to his conduct toward the park guest
Supply and demand for loanable funds : The following graph shows the market for loanable funds in a closed economy. The upward-sloping orange line represents the supply of loanable funds, and the downward-sloping blue line represents the demand for loanable funds.
Safety-accidents and investigations : In the Business Source Complete database of the University Online Library, locate and read the article, "Safety, Accidents, and Investigations: Be Prepared for the Unexpected," by Robert A. Battles.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd