Question

The goal in this exercise is to develop a program that will print out a list...

The goal in this exercise is to develop a program that will print out a list of student names together with other information foreach. The tab character

(an escape sequence) is helpful in getting the list to line up nicely. A program with only two names is in the file Names.java.

// ************************************************************

// Names.java

//

// Prints a list of student names with their hometowns

// and intended major

// ************************************************************

public class Names

{

// --------------------------

//

main prints the list

// --------------------------

public static void main (String[] args)

{

System.out.println ();

System.out.println (" \tName\t\tHometown") ;

System.out.println ("\t====\t\t========");

System.out.println ("\tSally\t\tRoanoke");

System.out.println ("\tAlexander\tWashington")

System.out.println ();

}

}

1. Save Names.java to your directory. Compile and run it to see how it works.

2. Modify the program so that your name and hometown and the name and hometown of at least two classmates sitting near

you in lab also are printed. Save, compile and run the program. Make sure the columns line up.

3. Modify the program to add a third column with the intended major of each person (assume Sally's major is Computer

Science and Alexander's major is Math). Be sure to add a label at the top of the third column and be sure everything is

lined up (use tab characters!).

Homework Answers

Answer #1

//names.java file content

import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class names{

public static void main(String []args){
System.out.println ();
System.out.println (" \tName\t\tHometown") ;
System.out.println ("\t====\t\t========");
System.out.println ("\tSally\t\tRoanoke");
System.out.println ("\tAlexander\tWashington");
//add two more student sitting near you
System.out.println ("\tJohn\t\tNewyork");
System.out.println ("\tSamanth\t\tBoston");
System.out.println ();
  
}
}

if executing in linux env , first compile

javac names.java

then execute using java names

//output of the program after adding two more names

        Name            Hometown                                                                                                                                                

        ====            ========                                                                                                                                                

        Sally           Roanoke                                                                                                                                                 

        Alexander       Washington                                                                                                                                              

        John            Newyork                                                                                                                                                 

        Samanth         Boston   

---------------------------------------------------------------------------

//program to add one more column major

import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class names{

public static void main(String []args){
System.out.println ();
System.out.println (" \tName\t\tHometown\tMajor") ;
System.out.println ("\t====\t\t========\t=====");
System.out.println ("\tSally\t\tRoanoke\t\tComputer science");
System.out.println ("\tAlexander\tWashington\tMath");
//add two more student sitting near you
System.out.println ("\tJohn\t\tNewyork\t\tElectronics");
System.out.println ("\tSamanth\t\tBoston\t\tSocial");
System.out.println ();
  
}
}

--------------------------------------------------------

output of second program

sh-4.3$ javac names.java                                                                                                                                                        

sh-4.3$ java -Xmx128M -Xms16M names

                                                                                                                                                                                

        Name            Hometown        Major                                                                                                                                   

        ====            ========        =====                                                                                                                                   

        Sally           Roanoke         Computer science                                                                                                                        

        Alexander       Washington      Math                                                                                                                                    

        John            Newyork         Electronics                                                                                                                             

        Samanth         Boston          Social   

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
public class Programming { public static void main(String args[]) { System.out.println("I am learning how to program.");...
public class Programming { public static void main(String args[]) { System.out.println("I am learning how to program."); } } Compile this and execute this program then modify it to display I am learning how to program in Java. Change class name to Javaprogramming.java. compile and execute. Modify the Javaprogramming class so it prints two lines of output. Change name to Awesome. Add second output statement that displays That's awesome ! Save as awesome.java then compile and execute
In c++ create a class to maintain a GradeBook. The class should allow information on up...
In c++ create a class to maintain a GradeBook. The class should allow information on up to 3 students to be stored. The information for each student should be encapsulated in a Student class and should include the student's last name and up to 5 grades for the student. Note that less than 5 grades may sometimes be stored. Your GradeBook class should at least support operations to add a student record to the end of the book (i.e., the...
7.6 LAB: Exception handling to detect input String vs. Integer The given program reads a list...
7.6 LAB: Exception handling to detect input String vs. Integer The given program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incremented. The program fails and throws an exception if the second input on a line is a String rather than an Integer. At FIXME in the code, add a try/catch statement to catch java.util.InputMismatchException, and output 0 for the age. Ex: If the input is: Lee 18 Lua...
Build two arrays[ ] (Integer and String) and convert them to two ArrayLists and write two...
Build two arrays[ ] (Integer and String) and convert them to two ArrayLists and write two overloaded generic static search method to find the index locations of a specified value. One of the search methods applies to the array type while the other (overloaded) search method applies to the collection type. Implement the following generic linear search method and write a client program to display results: (Here is the header) public static <E extends Comparable<E>> int search(E[] list, E key)...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do depending upon what the user enters, please refer to the examples below to use to test your program. Run your final program one time for each scenario to make sure that you get the expected output. Be sure to format the output of your program so that it follows what is included in the examples. Remember, in all examples bold items are entered by...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to...
Task 1: You will modify the add method in the LinkedBag class.Add a second parameter to the method header that will be a boolean variable: public boolean add(T newEntry, boolean sorted) The modification to the add method will makeit possible toadd new entriesto the beginning of the list, as it does now, but also to add new entries in sorted order. The sorted parameter if set to false will result in the existing functionality being executed (it will add the...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
Objective: Write a Java program that will use a JComboBox from which the user will select...
Objective: Write a Java program that will use a JComboBox from which the user will select to convert a temperature from either Celsius to Fahrenheit, or Fahrenheit to Celsius. The user will enter a temperature in a text field from which the conversion calculation will be made. The converted temperature will be displayed in an uneditable text field with an appropriate label. Specifications Structure your file name and class name on the following pattern: The first three letters of your...
Finish the CustomerAccountTransactions program that reads customer accounts receivable data from a file and then applies...
Finish the CustomerAccountTransactions program that reads customer accounts receivable data from a file and then applies a series of transactions to the accounts. Its main() method uses the CustomerAccounts class to manage a collection of CustomerAccount objects: reading customer accounts data & transactions, and obtaining a String showing the customer accounts data after the operations are complete. You will need to complete the readCustomerAccounts () and applyTransactions() methods in the CustomerAccounts class. First, please fill in your name in the...
c++ Program Description You are going to write a computer program/prototype to process mail packages that...
c++ Program Description You are going to write a computer program/prototype to process mail packages that are sent to different cities. For each destination city, a destination object is set up with the name of the city, the count of packages to the city and the total weight of all the packages. The destination object is updated periodically when new packages are collected. You will maintain a list of destination objects and use commands to process data in the list....