Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I improve my code?
    primarykey
    data
    text
    <p>I've just started Java programming yesterday (so don't expect too much) and I've written some code. My code works the way i want it to work but there is obviously things wrong with it, i was just wondering ways in which to improve it. I think I've added unnecessary things. I'm practicing to use classes and other stuff.</p> <p>the testing.java files contains:</p> <pre><code>import java.util.Scanner; class testing { private static Scanner input_sn; private static Scanner input_fn; private static Scanner input_mem; public static void main(String[] args){ String First_Name; String Second_Name; int members; int count; System.out.println("Members: "); input_mem = new Scanner(System.in); members = input_mem.nextInt(); funcs funcsObj = new funcs(); for (count = 0; count &lt; members; count++) { System.out.println("What is the first name? "); input_fn = new Scanner(System.in); First_Name = input_fn.nextLine(); System.out.println("What is the second name? "); input_sn = new Scanner(System.in); Second_Name = input_sn.nextLine(); funcsObj.names( funcsObj.setFn(First_Name), funcsObj.setSn(Second_Name)); } } } </code></pre> <p>and my funcs.java file contains:</p> <pre><code>public class funcs { private String firstName; private String secondName; private static int members = 0; public String setFn(String fn) { firstName = fn; return fn; } public String setSn(String sn) { secondName = sn; return sn; } public void names(String fn, String sn) { firstName = fn; secondName = sn; members++; System.out.printf("%d\t%s\t%s\n", members, fn, sn); } } </code></pre> <p>I think most of the problems can be found in the funcs.java file.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload