I need help finishing the code and adding at least one more method to it(doesn\'
ID: 3656125 • Letter: I
Question
I need help finishing the code and adding at least one more method to it(doesn't matter what it does). Here is what I have: import java.util.Scanner; public class test { public static void main (String args[]) { int userinput; int total=0; Scanner s = new Scanner(System.in); printmenu(); userinput = s.nextInt(); total = getchoice (userinput); System.out.printf ("total:%d ", total); } public static int getchoice (int userinput) { int retval; switch(userinput) { case 1: retval = 2; break; case 2: retval = 3; break; case 3: retval = 5; break; case 4: retval = 1; break; default: retval = 0; } return retval; } public static void printmenu() { centerstring ("Our Menu"); System.out.printf (" "); centerstring ("0. Total and Exit. "); centerstring ("1. Eggs $2.00 "); centerstring ("2. Pancakes $3.00 "); centerstring ("3. Bacon $5.00 "); centerstring ("4. Bagels $1.00 "); centerstring ("------------------- "); centerstring ("Please enter your choice: "); } public static void centerstring (String printme) { int x; int y; x = printme.length(); x = 40-(x/2); for (y=0; yExplanation / Answer
import java.util.Scanner; public class Exercise { static void main(String[] args) { Scanner scnr = new Scanner(System.in); String houseType = "Unknown"; int choice = 0; double value = 0D; System.out.println("Enter the type of house you want to purchase"); System.out.println("1. Single Family"); System.out.println("2. Townhouse"); System.out.println("3. Condominium"); System.out.print("You Choice? "); choice = scnr.nextInt(); if (choice == 1) houseType = "Single Family"; if (choice == 2) houseType = "Townhouse"; if (choice == 3) houseType = "Condominium"; System.out.print("Up to how much can you afford? $"); value = scnr.nextDouble(); System.out.println("Desired House Type: " + houseType); System.out.println("Maximum value afforded: " + value); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.