I need to write a capital quiz that looks like this: What's the capital of Colorado? (STOP to quit) Denver Right!
The information is on a file i imported. I need to do three class and I'm stuck on the second one. first one:
/**
* Write a description of class State here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class State
{
private String state;
private String abbreviation;
private String capital;
/**
* Constructor for objects of class State
*/
public State(String state, String abbreviation, String capital)
{
this.state = state;
this.abbreviation = abbreviation;
this.capital = capital;
}
/**
* Lab 7 for CS 1054
* @return getmileage get method used
*/
public String getState()
{
return state;
}
/**
* Lab 7 for CS 1054
* @return getmileage get method used
*/
public String getAbbreviation()
{
return abbreviation;
}
/**
* Lab 7 for CS 1054
* @return getmileage get method used
*/
public String getCapital()
{
return capital;
}
/**
* Lab 6 for CS 1054
* @param breed1 used
*/
public void setState(String state1)
{
state = state1;
}
/**
* Lab 6 for CS 1054
* @param breed1 used
*/
public void setAbbreviation(String abbreviation1)
{
abbreviation = abbreviation1;
}
/**
* Lab 6 for CS 1054
* @param breed1 used
*/
public void setCapital(String capital1)
{
capital = capital1;
}
/**
* Lab 6 for CS 1054
* @return args agruments
*/
public String toString()
{
return state + " (" + abbreviation + "), "
+ capital;
}
}
second one:
import java.util.Random;
import java.util.Scanner;
import java.io.*;
/**
* Lab 8 CS 1054
*
* @author kcoyne4
* @version 10.24.2016
*/
public class CapitalQuiz
{
File myFile = new File("stateData.txt");
State[] states = new State[49];
double state = states.getState();
double abbrevaition = abbreviation.getAbbrevation();
double capital = capital.getCapital();
//states[index] = .getState
//String statesArray[] = new String[50];
//String abbreviationArray[] = new String[50];
//String capitalsArray[] = new String[50];
/**
* capital quiz
* @param args unused
*/
public CapitalQuiz(String file) throws FileNotFoundException
{
Scanner fileIn = new Scanner(new File("stateData.txt"));
Random gen = new Random();
fileIn.useDelimiter("[, \n]");
for (int i = 0; i < states.length; i++)
{
String state = fileIn.next();
String abrev = fileIn.next();
String capital = fileIn.next();
states = new State[i];
//states[i] = fileIn.next();
}
}
public void takequiz()
{
// Scanner fileIn = new Scanner(new File("stateData.txt"));
// fileIn.useDelimiter("[, \n]");
int index = gen.nextInt(states.length);
return myArray[randomIndex];
String states = " ";
// states = fileIn.next();
while (!states.equals("STOP"))
//repeats the statement when STOP is not written
{
states = gen.nextInt(state);
if (capital == states)
System.out.println("Correct!");
else if (capital == abbrevation)
System.out.println("Correct!");
else if (capital != states)
System.out.println("Wrong!");
else if (capital == abbrevation)
System.out.println("Wrong!");
System.out.println("What's the capital of" + "(STOP to quit)");
//what will be written if stop is not written
}
while (
{
System.out.println();
System.out.print("No, the answer is" + correct)
}
}
/while
{
System.out.println();
System.out.print("No, the answer is" + correct)
}
System.out.println()
System.out.println()
System.out.println("You answered" + correct + "out of"
double grade = correct / total
System.out.println("That's " + grade + "%")
Please help! Thanks!
Aucun commentaire:
Enregistrer un commentaire