How can I split this program into two classes?
import java.io.*;
public class Quiz
{
static LineNumberReader cin = new LineNumberReader(new
InputStreamReader(System.in));
public static void main(String[] args)
{
int score = 0;
final int NumberofQuestions = 5;
int num;
System.out.println("\nWelcome to CSC 111 Java Quiz\n");
String[][] QandA = {
{"All information is stored in the computer using binary numbers:
","true"},
{"The word \"Public\" is a reserved word: ","false"},
{"Variable names may begin with a number: ","false"},
{"Will the following code result in 2? int num = 12%5:
","true"},
{"The statement { } is a legal code block: ","true"},
};
String[] Answers = new String[NumberofQuestions];
for(int x = 0; x < NumberofQuestions; x++)
{
System.out.print("\t" + (x+1) + ". " + QandA[x][0] + " ");
try { Answers[x] = cin.readLine(); }
catch (IOException e) { System.err.println("Error."); }
Answers[x]=Answers[x].toLowerCase();
if(QandA[x][1].equals(Answers[x]))
{
score++;
}
System.out.print("\n");
}
num = score * 20;
if (score == 5){
System.out.println("Congratulations! you got a perfect
score.");
} else if (score >= 4) {
System.out.println("Your score is " + num +"%. You can do
better!");
} else if (score >= 0) {
System.out.println("Your score is " + num +"%. I'd suggest you
review and try again.");
}
}
}
We need at least 10 more requests to produce the answer.
0 / 10 have requested this problem solution
The more requests, the faster the answer.
How can I split this program into two classes? import java.io.*; public class Quiz { static...
The DictionaryClient program featured in the class lecture also used the try-catch when creating a socket. Socket are auto-closeable and thus can use a try-with-resources instead. Edit the dictionary program to use try-with-resources instead. package MySockets; import java.net.*; import java.io.*; public class DictionaryClient { private static final String SERVER = "dict.org"; private static final int PORT = 2628; private static final int TIMEOUT = 15000; public static void main(String[] args) { Socket ...
Using java socket programming rewrite the following program to handle multiple clients simultaneously (multi threaded programming) import java.io.*; import java.net.*; public class WelcomeClient { public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.println( "Usage: java EchoClient <host name> <port number>"); System.exit(1); } String hostName = args[0]; int portNumber = Integer.parseInt(args[1]); try ( Socket kkSocket = new Socket(hostName, portNumber); PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true); BufferedReader in = new BufferedReader( new InputStreamReader(kkSocket.getInputStream())); ) { BufferedReader...
I need help running this code. import java.util.*; import java.io.*; public class wordcount2 { public static void main(String[] args) { if (args.length !=1) { System.out.println( "Usage: java wordcount2 fullfilename"); System.exit(1); } String filename = args[0]; // Create a tree map to hold words as key and count as value Map<String, Integer> treeMap = new TreeMap<String, Integer>(); try { @SuppressWarnings("resource") Scanner input = new Scanner(new File(filename));...
Please help to make the program working. Can not compile. import java.io.*; import java .util.*; public class Puzzlee { static int NN = 9; // Grid Size // sample input static int myGrid[][] = { {0,0,0,1,0,5,0,6,8}, {0,0,0,0,0,0,7,0,1}, {9,0,1,0,0,0,0,3,0}, {0,0,7,0,2,6,0,0,0}, {5,0,0,0,0,0,0,0,3}, {0,0,0,8,7,0,4,0,0}, {0,3,0,0,0,0,8,0,5}, {1,0,5,0,0,0,0,0,0}, {7,9,0,4,0,1,0,0,0} }; static class myCell { int myRow, myColumn; public myCell(int myRow, int myColumn) { super(); ...
Fix the following null pointer error. import java.util.*; import java.io.*; public class PhoneBook { public static void main(String[]args)throws IOException { PhoneBook obj = new PhoneBook(); PhoneContact[]phBook = new PhoneContact[20]; Scanner in = new Scanner(System.in); obj.acceptPhoneContact(phBook,in); PrintWriter pw = new PrintWriter("out.txt"); obj.displayPhoneContacts(phBook,pw); pw.close(); } public void acceptPhoneContact(PhoneContact[]phBook, Scanner k) { //void function that takes in the parameters //phBook array and the scanner so the user can input the information //declaring these variables String fname = ""; String lname = ""; String...
(How do I remove the STATIC ArrayList from the public class Accounts, and move it to the MAIN?) import java.util.ArrayList; import java.util.Scanner; public class Accounts { static ArrayList<String> accounts = new ArrayList<>(); static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int option = 0; do { System.out.println("0->quit\n1->add\n2->overwirte\n3->remove\n4->display"); System.out.println("Enter your option"); option = scanner.nextInt(); if (option == 0) { break; } else if (option == 1) { add(); } else...
Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); final int maxSize = 128; String[] titles = new String[maxSize]; int[] lengths = new int[maxSize]; int numDVDs = 0; String op; op = menu(stdIn); System.out.println(); while (!op.equalsIgnoreCase("q")) { if (op.equalsIgnoreCase("a")) { if (numDVDs < maxSize) numDVDs = addDVD(titles, lengths, numDVDs, stdIn); } else if (op.equalsIgnoreCase("t")) searchByTitle(titles, lengths, numDVDs, stdIn); else if (op.equalsIgnoreCase("l")) searchByLength(titles, lengths, numDVDs, stdIn); System.out.println('\n');...
Complete the code: package hw4; import java.io.File; import java.io.IOException; import java.util.LinkedList; import java.util.Scanner; /* * This class is used by: * 1. FindSpacing.java * 2. FindSpacingDriver.java * 3. WordGame.java * 4. WordGameDriver.java */ public class WordGameHelperClass { /* * Returns true if an only the string s * is equal to one of the strings in dict. * Assumes dict is in alphabetical order. */ public static boolean inDictionary(String [] dict, String s) { // TODO Implement using binary search...
Java Project Draw a class diagram for the below class (using UML notation) import java.io.BufferedReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; public class myData { public static void main(String[] args) { String str; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter text (‘stop’ to quit)."); try (FileWriter fw = new FileWriter("test.txt")) { do { System.out.print(": "); str = br.readLine(); if (str.compareTo("stop") == 0) break; str = str + "\r\n"; // add newline fw.write(str); } while (str.compareTo("stop") != 0); } catch (IOException...