/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package testteacher; import java.util.Scanner; class Teacher { private String name; private double salary; public Teacher(String name, double salary) { this.name = name; this.salary = salary; } public void setName(String name) { this.name = name; } public void setSalary(double salary) { this.salary = salary; } public String getName() { return name; } public double getSalary() { return salary; } @Override public String toString() { return name + "---" + salary; } } class Test { String name; double salary; Scanner input = new Scanner(System.in); public void inputInformation() { System.out.println("------------------"); System.out.print("Enter Teacher name: "); name = input.nextLine(); System.out.print("Enter Teacher salary: "); salary = input.nextDouble(); input.nextLine(); // t = Teacher(name, salary); } public int menu() { int choose; System.out.println("1. TC = 1 - test getName()"); System.out.println("2. TC = 2 - test Salary()"); System.out.println("3. TC = 3 - test toString()"); System.out.println("Other. Quits !"); System.out.print("Enter TC: "); choose = input.nextInt(); input.nextLine(); return choose; } void run() { int isContinue = 1; do { inputInformation(); Teacher t = new Teacher(name, salary); int choose = menu(); switch (choose) { case 1: System.out.println("OUTPUT:"); System.out.println(t.getName()); break; case 2: System.out.println("Enter new salary: "); salary = input.nextDouble(); input.nextLine(); System.out.println("OUTPUT:"); t.setSalary(salary); System.out.println("New salary: " + t.getSalary()); break; case 3: System.out.println("OUTPUT:"); System.out.println(t); break; default: isContinue = 0; } } while (isContinue == 1); } } public class TestTeacher { /** * @param args the command line arguments */ public static void main(String[] args) { Test te = new Test(); te.run(); } }