JAVA PROGRAMING BEGIN ( work on Eclipse) For each of these, I want an OUTLINE li
ID: 3750789 • Letter: J
Question
JAVA PROGRAMING BEGIN ( work on Eclipse)
For each of these, I want an OUTLINE like in the lecture. If you write out all the code, you aren't clever, you just can't follow directions.
1)Write a program for a robot cashier at Subway. Show a menu of three kinds of sandwich with prices. Let the user pick sandwiches until they choose to stop. Assume they then give you a twenty dollar bill. Calculate their change and print it out to the screen one piece of money at a time. If their order came to more than $20, tell them they should feel bad for wasting your time.
2)I'm thinking of a number between 1 and 100. The user keeps guessing until they get it right. After each wrong guess, the AI will say Higher or Lower.
3)Show a list of three names. Ask the user who they would like to vote for. Repeat this a maximum of 13 times, or stop when they want to quit. Afterward display which person won.
4)Write a vet program for the best corgi ever. Once at the start, ask for the weight and daily calorie intake required. Then begin a loop asking how many calories she eats each day. Every seven days, print her new weight. If she eats an extra 3500 calories, she gains a pound. If she is 3500 calories short, she loses a pound. She can be fractional pounds.
5)Count how many vowels (aeiou) are in a word the user types until they type "xxxxx".
So the one hard part and pretty much the only way to lose points here is to be too vague. Your duck can type, but is not good at programming. You need to be specific, but not just reading a program line by line. Your duck only knows C-- so you can't use any Java terms. Every semester I get two or three people who answer all of them with "Step one, get input, step two, do program."
Explanation / Answer
Answer :-
Machine.java
import java.util.Scanner;
public class Machine {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
boolean flag = true;
System.out.println("Please enter amount:");
double amount = 0.0;
amount = input.nextDouble();
int vc=0,sc=0,nv=0;
double total = 0.0;
while(flag) {
System.out.println("--Menu--");
System.out.println("1. veg cheese sandwich--$3");
System.out.println("2. sweet corn sandwich--$5");
System.out.println("3. Non-veg sandwich--$9");
System.out.println("4. Quit and Collect bill");
int in = input.nextInt();
switch(in) {
case 1: total+=3;
vc++;
if(total>amount) {
System.out.println("Feel Bad, You are wasting time. Try Again.");
total=0;
vc=0;
nv=0;
sc=0;
}
break;
case 2: total+=5;
sc++;
if(total>amount) {
System.out.println("Feel Bad, You are wasting time. Try Again.");
total=0;
vc=0;
nv=0;
sc=0;
}
break;
case 3: total+=9;
nv++;
if(total>amount) {
System.out.println("Feel Bad, You are wasting time. Try Again.");
total=0;
vc=0;
nv=0;
sc=0;
}
break;
case 4: System.out.println("Your Order is:");
if(vc>0) {
System.out.println("veg cheese sandwich with quantity "+vc);
}
if(sc>0) {
System.out.println("sweet corn sandwich with quantity "+vc);
}
if(nv>0) {
System.out.println("Non-veg sandwich with quantity "+vc);
}
System.out.println("Total amount:"+total);
System.out.println("Paid amount:"+amount);
System.out.println("Remaining Balance:"+(amount-total));
System.out.println("Thank you for using. Bye");
flag = false;
default : System.out.println("Invalid choice. Try Agian!");
break;
}
}
}
}
Output:-
Please enter amount:
25
--Menu--
1. veg cheese sandwich--$3
2. sweet corn sandwich--$5
3. Non-veg sandwich--$9
4. Quit and Collect bill
1
--Menu--
1. veg cheese sandwich--$3
2. sweet corn sandwich--$5
3. Non-veg sandwich--$9
4. Quit and Collect bill
2
--Menu--
1. veg cheese sandwich--$3
2. sweet corn sandwich--$5
3. Non-veg sandwich--$9
4. Quit and Collect bill
3
--Menu--
1. veg cheese sandwich--$3
2. sweet corn sandwich--$5
3. Non-veg sandwich--$9
4. Quit and Collect bill
4
Your Order is:
veg cheese sandwich with quantity 1
sweet corn sandwich with quantity 1
Non-veg sandwich with quantity 1
Total amount:17.0
Paid amount:25.0
Remaining Balance:8.0
Thank you for using. Bye
Invalid choice. Try Agian!
Question 2:
Guess.java
import java.util.Random;
import java.util.Scanner;
public class Guess {
public static void main(String[] args) {
int number=0;
Scanner input = new Scanner(System.in);
Random rand = new Random();
number = rand.nextInt(100)+1;
boolean flag = true;
int count=0;
while(flag) {
System.out.println("Guess the number:");
int n=input.nextInt();
if(n==number) {
System.out.println("You guessed.");
count++;
System.out.println("Number of guesses:"+count);
flag = false;
}else if(n>number) {
System.out.println("Too high. Try Agian");
count++;
}else if(n<number) {
System.out.println("Too low. Try Agian");
count++;
}
}
}
}
Output:
Guess the number:
26
Too low. Try Agian
Guess the number:
100
Too high. Try Agian
Guess the number:
60
Too high. Try Agian
Guess the number:
50
Too high. Try Agian
Guess the number:
40
Too low. Try Agian
Guess the number:
45
Too high. Try Agian
Guess the number:
42
You guessed.
Number of guesses:7
Question 3:
Vote.java
import java.util.Scanner;
public class Vote {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int totone=0,tottwo=0,totthree=0;
for(int i=0;i<13;i++) {
System.out.println("voting system");
System.out.println("1. Modi");
System.out.println("2. Rahul");
System.out.println("3. Unknown");
System.out.println("Enter your vote:");
int num = input.nextInt();
if(num==1) {
totone++;
}else if(num==2) {
tottwo++;
}else {
totthree++;
}
}
if(totone>tottwo && totone>totthree) {
System.out.println("Modi won");
}else if(tottwo>totone && tottwo>totthree) {
System.out.println("Rahul won");
}else {
System.out.println("Unknown won");
}
}
}
Output:
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
1
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
2
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
3
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
2
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
2
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
1
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
1
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
3
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
3
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
3
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
3
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
3
voting system
1. Modi
2. Rahul
3. Unknown
Enter your vote:
3
Unknown won
Question 4: Vowels count
Vowels.java
import java.util.Scanner;
public class Vowels {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
boolean flag = true;
int vowels=0;
while(flag) {
System.out.println("Enter string:");
String s = input.nextLine();
s = s.toLowerCase();
if(s.endsWith("xxxxx")) {
for(int i=0;i<s.length();i++) {
if(s.charAt(i)=='a' || s.charAt(i)=='e' || s.charAt(i)=='i' || s.charAt(i)=='o' || s.charAt(i)=='u') {
vowels++;
}
}
flag = false;
}else {
for(int i=0;i<s.length();i++) {
if(s.charAt(i)=='a' || s.charAt(i)=='e' || s.charAt(i)=='i' || s.charAt(i)=='o' || s.charAt(i)=='u') {
vowels++;
}
}
}
}
System.out.println("total vowels count:"+vowels);
}
}
Output:
Enter string:
Harish
Enter string:
Priya
Enter string:
Sagar
Enter string:
Unknown
Enter string:
abc is good boy xxxxx
total vowels count:13
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.