Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How can we limit the visibility of information in this code? import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class ReliabilityEx { public static

How can we limit the visibility of information in this code? import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class ReliabilityEx { public static void main(String args[]) throws IOException { method1(); method2(); } public static void method1() { String a, b; Scanner scanner = new Scanner(System.in); System.out.print("Enter the first number: "); a = scanner.next(); System.out.print("Enter the second number: "); b = scanner.next(); int x , y; x= Integer.parseInt(a); y = Integer.parseInt(b); System.out.println("Before swapping:"); System.out.println("a = " +x +", b = " +y); x = x ^ y; y = x ^ y; x = x ^ y; System.out.println("After swapping:"); System.out.print("a = " +x +", b = " +y); } public static void method2() throws IOException { Scanner scanner = new Scanner(System.in); System.out.print("Enter your first name: "); String fn = scanner.next(); System.out.print("Enter your last name: "); String ln = scanner.next(); System.out.print("Enter your email: "); String e = scanner.next(); System.out.print("Enter phone number: "); int p = scanner.nextInt(); System.out.print("Enter your ID: "); int id = scanner.nextInt(); System.out.print("Enter your Salary: "); int s = scanner.nextInt(); showUserInfo(fn,ln,e,p,id,s); addUserInfo(fn,ln,e,p,id,s); caculateUserIncomeTax(s); } public static void showUserInfo(String f, String l, String e, int p, int id, int s) { System.out.print("First name: " +f + " Last name: " + l + " emial address: " + e + " phone: " + p + " id: " + id + " salary: " + s); } public static void addUserInfo(String f, String l, String e, int p, int id, int s) throws IOException { FileWriter myWriter = new FileWriter("users.txt"); myWriter.write("First name: " +f + " Last name: " + l + " emial address: " + e + " phone: " + p + " id: " + id + " salary: " + s); myWriter.close(); System.out.println(" Successfully wrote to the file."); } public static void caculateUserIncomeTax(int s) { int tax = s * 20/100; int newIncome = s - tax; System.out.println("The user income tax is " + newIncome); } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions