(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 if (option == 2) {
overwrite();
} else if (option == 3) {
remove();
} else if (option == 4) {
display();
} else {
System.out.println("Invalid option");
}
} while (true);
System.out.println("You Quit The Program!");
}//closes main method
public static void add() {
System.out.print("Enter acc no : ");
String number = scanner.next();
accounts.add(number);
}//closes add method
public static void overwrite() {
System.out.print("Enter acc no : ");
String number = scanner.next();
int accPos = -1;
for (int i = 0; i < accounts.size(); i++) {
if (accounts.get(i).equalsIgnoreCase(number)) {
accPos = i;
}
}
if (accPos == -1) {
System.out.println("No Account is present with given
number");
return;
} else {
System.out.print("Enter new acc no : ");
String newAccNumber = scanner.next();
accounts.set(accPos, newAccNumber);
System.out.println("Successfully overwrite");
}
}//closes overwrite method
public static void remove() {
System.out.print("Enter acc no : ");
String number = scanner.next();
if (accounts.remove(number)) {
System.out.println("Successfully removed");
} else {
System.out.println("Account not present");
}
}//closes remove method
public static void display() {
System.out.println("Accounts :");
for (String number : accounts) {
System.out.println(number);
}
}//closes display method
}//closes Accounts class
//Accounts.java import java.util.ArrayList; import java.util.Scanner; public class Accounts { static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { ArrayList<String> accounts = new ArrayList<>(); 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(accounts); } else if (option == 2) { overwrite(accounts); } else if (option == 3) { remove(accounts); } else if (option == 4) { display(accounts); } else { System.out.println("Invalid option"); } } while (true); System.out.println("You Quit The Program!"); }//closes main method public static void add(ArrayList<String> accounts) { System.out.print("Enter acc no : "); String number = scanner.next(); accounts.add(number); }//closes add method public static void overwrite(ArrayList<String> accounts) { System.out.print("Enter acc no : "); String number = scanner.next(); int accPos = -1; for (int i = 0; i < accounts.size(); i++) { if (accounts.get(i).equalsIgnoreCase(number)) { accPos = i; } } if (accPos == -1) { System.out.println("No Account is present with given number"); return; } else { System.out.print("Enter new acc no : "); String newAccNumber = scanner.next(); accounts.set(accPos, newAccNumber); System.out.println("Successfully overwrite"); } }//closes overwrite method public static void remove(ArrayList<String> accounts) { System.out.print("Enter acc no : "); String number = scanner.next(); if (accounts.remove(number)) { System.out.println("Successfully removed"); } else { System.out.println("Account not present"); } }//closes remove method public static void display(ArrayList<String> accounts) { System.out.println("Accounts :"); for (String number : accounts) { System.out.println(number); } }//closes display method }//closes Accounts class
(How do I remove the STATIC ArrayList from the public class Accounts, and move it to...
import java.util.Scanner; public class TriangleMaker { public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle."); Scanner keyboard = new Scanner(System.in); int size = keyboard.nextInt(); for (int i = 1; i <= size; i++) { for (int j = 0; j < i; j++) { System.out.print("*"); } System.out.println(); } for (int...
Can you help me rearrange my code by incorporating switch I'm not really sure how to do it and it makes the code look cleaner. Can you help me do it but still give the same output? Also kindly add an in-line comment on what changes and rearrangement you've done so I can understand what's going on. import java.util.ArrayList; import java.util.Scanner; public class Bank { /** * Add and read bank information to the user. * @param arg A string,...
Convert into pseudo-code for below code =============================== class Main { public static void main(String args[]) { Scanner s=new Scanner(System.in); ScoresCircularDoubleLL score=new ScoresCircularDoubleLL(); while(true) { System.out.println("1--->Enter a number\n-1--->exit"); System.out.print("Enter your choice:"); int choice=s.nextInt(); if(choice!=-1) { System.out.print("Enter the score:"); int number=s.nextInt(); GameEntry entry=new GameEntry(number); ...
Complete the following Java program by writing the missing methods. public class 02 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a number: int n = scan.nextInt(); if (isOdd (n)) { //Print n to 1 System.out.println("Print all numbers from "+n+" to 1"); printNumToOne (n); } else { System.out.println(n + " is //End of main()
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');...
I need help asking the user to half the value of the displayed random number as well as storing each number generated by the program into another array list and displayed after the game is over at the end java.util.*; public class TestCode { public static void main(String[] args) { String choice = "Yes"; Random random = new Random(); Scanner scanner = new Scanner(System.in); ArrayList<Integer> data = new ArrayList<Integer>(); int count = 0; while (!choice.equals("No")) { int randomInt =...
I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...
Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class Delete extends Info { String name; int Id; int del; public Delete() { } public void display() { Scanner key = new Scanner(System.in); System.out.println("Input Customer Name: "); name = key.nextLine(); System.out.println("Enter ID Number: "); Id = key.nextInt(); System.out.println("Would you like to Delete? Enter 1 for yes or 2 for no. "); del = key.nextInt(); if (del == 1) { int flag = 0; //learned...
Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp { public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...
I need a java flowchart for the following code: import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("Enter the input size: "); int n=sc.nextInt(); int arr[]=new int[n]; System.out.print("Enter the sequence: "); for(int i=0;i<n;i++) arr[i]=sc.nextInt(); if(isConsecutiveFour(arr)) { System.out.print("yes the array contain consecutive number:"); for(int i=0;i<n;i++) System.out.print(arr[i]+" "); ...