HERE ARE MY CODES
I TRIED THE DO WHILE METHOD BUT IT DIDNT WORK AS WELL:
Should I do Case break or stick to do while method?
this is the main code
import java.util.Scanner;
import java.io.Console;
public class Main
{
public static void main(String[] args) {
String name;
int choice;
int time;
Console cons = System.console();
if (cons==null)
{
System.out.println("");
return;
}
Im starting do while here but it wont work
name = cons.readLine("Enter your Name: ");
Scanner scn = new Scanner(System.in);
System.out.println("\nMenu");
System.out.println("\n[1] Network Engineer\n[2] Software Engineer\n[3] Full Stack Developer\n[4] Technical Support");
System.out.print("\nEnter your job(Choose a number from the menu): ");
choice = scn.nextInt();
System.out.print("Enter no. of hours present at work: " );
time = scn.nextInt();
if (choice == 1)
{
int gsalary = 1200*time;
int nsalary = gsalary - (gsalary * 12 / 100);
cons.printf("\nHello %s!\n", name);
System.out.println("Your job salary as a Network Engineer is 1200 per hour.");
System.out.println("Your gross salary for this week is " gsalary ".");
System.out.println("Your net salary for this weeks is " nsalary ".");
}
if (choice == 2)
{
int gsalary = 800*time;
int nsalary = gsalary - (gsalary * 12 / 100);
cons.printf("\nHello %s!\n", name);
System.out.println("Your job salary as a Network Engineer is 800 per hour.");
System.out.println("Your gross salary for this week is " gsalary ".");
System.out.println("Your net salary for this weeks is " nsalary ".");
}
if (choice == 3)
{
int gsalary = 600*time;
int nsalary = gsalary - (gsalary * 12 / 100);
cons.printf("\nHello %s!\n", name);
System.out.println("Your job salary as a Network Engineer is 600 per hour.");
System.out.println("Your gross salary for this week is " gsalary ".");
System.out.println("Your net salary for this weeks is " nsalary ".");
}
if (choice == 4)
{
int gsalary = 500*time;
int nsalary = gsalary - (gsalary * 12 / 100);
cons.printf("\nHello %s!\n", name);
System.out.println("Your job salary as a Network Engineer is 500 per hour.");
System.out.println("Your gross salary for this week is " gsalary ".");
System.out.println("Your net salary for this weeks is " nsalary ".");
}
}
}Or may be Im just mistaken by those brackets can you help me determine whats the problem is? I am new in Java
CodePudding user response:
Try calling the Main()
method again using an Intent
or you could just try calling Main()
without using Intent
first to save some line space...