Question

cs55(java) please

Part 1: You are a programming intern at the student transfer counselors office. Having heard you are taking CS 55, your bossimprove your GPA by ... Avoid if/else if... to match the school and the major. Switch/case makes the code cleaner Part 2: YoHints Think about decomposing the problem into simpler problems. You will likely find it helpful to write a few very simple mcodeMessage takes a String and a boolean flag. If the flag is true, it prints the given message encoded. If the flag is false

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Part1 code

import java.text.DecimalFormat;

import java.util.Scanner;

public class TransferAdvisor

{

private static DecimalFormat df2 = new DecimalFormat("0.##");

public static void main(String[] args)

{

Scanner sc=new Scanner(System.in);

String collageName,major;

double gpa;

System.out.print("Enter the school name: ");

collageName=sc.next();

System.out.print("Enter the smajor: ");

major=sc.next();

System.out.print("Enter your GPA: ");

gpa=sc.nextDouble();

  

switch(collageName.toUpperCase())

{

case "UCLA":

checkTransger(collageName,major,gpa);

break;

case "UCB":

checkTransger(collageName,major,gpa);

break;

case "UCI":

checkTransger(collageName,major,gpa);

break;

case "UCSD":

checkTransger(collageName,major,gpa);

break;

default:

System.out.println(collageName+" is not in the school system.");

  

}

}

private static void checkTransger(String collageName, String major, double gpa)

{

switch(major.toUpperCase())

{

case "CS":

switch(collageName.toUpperCase())

{

case "UCLA":

if(gpa>=3.7)

System.out.println("You can transger to "+collageName+" to study CS.");

else

System.out.println("You need to improve your GPA by "+df2.format(3.7-gpa)+" to transfer to "+ collageName +" to study "+major);

break;

case "UCB":

if(gpa>=3.8)

System.out.println("You can transger to "+collageName+" to study CS.");

else

System.out.println("You need to improve your GPA by "+df2.format(3.8-gpa)+" to transfer to "+ collageName +" to study "+major);

break;

case "UCI":

if(gpa>=3.6)

System.out.println("You can transger to "+collageName+" to study CS.");

else

System.out.println("You need to improve your GPA by "+df2.format(3.6-gpa)+" to transfer to "+ collageName +" to study "+major);

break;

case "UCSD":

if(gpa>=3.5)

System.out.println("You can transger to "+collageName+" to study CS.");

else

System.out.println("You need to improve your GPA by "+df2.format(3.5-gpa)+" to transfer to "+ collageName +" to study "+major);

break;

}

break;

case "ECON":

switch(collageName.toUpperCase())

{

case "UCLA":

if(gpa>=3.5)

System.out.println("You can transger to "+collageName+" to study "+major);

else

System.out.println("You need to improve your GPA by "+df2.format(3.5-gpa)+" to transfer to "+ collageName +" to study "+major);

break;

case "UCB":

if(gpa>=3.4)

System.out.println("You can transger to "+collageName+" to study CS.");

else

System.out.println("You need to improve your GPA by "+df2.format(3.4-gpa)+" to transfer to "+ collageName +" to study "+major);

break;

case "UCI":

if(gpa>=3.7)

System.out.println("You can transger to "+collageName+" to study CS.");

else

System.out.println("You need to improve your GPA by "+df2.format(3.7-gpa)+" to transfer to "+ collageName +" to study "+major);

break;

case "UCSD":

if(gpa>=3.3)

System.out.println("You can transger to "+collageName+" to study CS.");

else

System.out.println("You need to improve your GPA by "+df2.format(3.3-gpa)+" to transfer to "+ collageName +" to study "+major);

break;

}

break;

case "ENGLISH":

switch(collageName.toUpperCase())

{

case "UCLA":

if(gpa>=3.2)

System.out.println("You can transger to "+collageName+" to study "+major);

else

System.out.println("You need to improve your GPA by "+df2.format(3.2-gpa)+" to transfer to "+ collageName +" to study "+major);

break;

case "UCB":

if(gpa>=3.3)

System.out.println("You can transger to "+collageName+" to study CS.");

else

System.out.println("You need to improve your GPA by "+df2.format(3.3-gpa)+" to transfer to "+ collageName +" to study "+major);

break;

case "UCI":

if(gpa>=3.4)

System.out.println("You can transger to "+collageName+" to study CS.");

else

System.out.println("You need to improve your GPA by "+df2.format(3.4-gpa)+" to transfer to "+ collageName +" to study "+major);

break;

case "UCSD":

if(gpa>=3.0)

System.out.println("You can transger to "+collageName+" to study CS.");

else

System.out.println("You need to improve your GPA by "+df2.format(3.0-gpa)+" to transfer to "+ collageName +" to study "+major);

break;

}

break;

default:

System.out.println("There is no major "+major+" at "+collageName);

}

}

  

}

output

Transfer Advisor - NetBeans IDE 8.0.1 Eile Edit View Navigete Source Refgctor Run Debug Profile Team Iools Window Help SearchTransfer Advisor - NetBeans IDE 8.0.1 Eile Edit View Navigete Source Refgctor Run Debug Profile Team Iools Window Help SearchTransfer Advisor - NetBeans IDE 8.0.1 Eile Edit View Navigete Source Refgctor Run Debug Profile Team Iools Window Help Searchpart 2

import java.util.Scanner;

public class SecretMessage

{

public static void main(String[] args)

{

Scanner sc=new Scanner(System.in);

String plainMsg,encodedMsg;

int choice;

char c;

do

{

System.out.print("Enter 1 to encode,2 to decode, 3 to quit: ");

choice=sc.nextInt();

  

switch(choice)

{

case 1:

System.out.println("Enter a text to encode: ");

plainMsg=sc.nextLine();

  

encodedMsg="";

for(int i=0;i<plainMsg.length();i++)

{

c=plainMsg.charAt(i);

if(Character.isLetter(c))

{

encodedMsg+=codeChar(c,true);

}

else

encodedMsg+=c;

}

System.out.println(encodedMsg);

  

break;

case 2:

System.out.println("Enter a text to decode: ");

encodedMsg=sc.nextLine();

plainMsg="";

for(int i=0;i<plainMsg.length();i++)

{

c=encodedMsg.charAt(i);

if(Character.isLetter(c))

{

plainMsg+=codeChar(c,false);

}

else

plainMsg+=c;

}

System.out.println(plainMsg);

break;

case 3:

break;

default:

System.out.println("Invalid choice!!!");

}

}while(choice!=3);

}

public static char codeChar(char c,boolean flag)

{

String letters="abcdefghijklmnopqrstuvwxyz";

String enc="kngcadsxbvfhjtiumylzqropwe";

char ch='a';

if(flag)

{

if(isLowerCaseLetter(c))

{

ch=enc.charAt(letters.indexOf(c));

}

else

{

c=toLowerCase(c);

ch=enc.charAt(letters.indexOf(c));

ch=Character.toUpperCase(ch);

}

}

else

{

if(isLowerCaseLetter(c))

{

ch=letters.charAt(enc.indexOf(c));

}

else

{

c=toLowerCase(c);

ch=letters.charAt(enc.indexOf(c));

ch=Character.toUpperCase(ch);

}

}

return ch;

}

private static boolean isLowerCaseLetter(char c) {

return Character.isLowerCase(c);

}

private static char toLowerCase(char c) {

return Character.toLowerCase(c);

}

}

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ Having heard you have gotten really good at programming, your friend has come to...

    In C++ Having heard you have gotten really good at programming, your friend has come to ask for your help with a simple task. She would like you to implement a program to encrypt the messages she exchanges with her friends. The idea is very simple. Every letter of the alphabet will be substituted with some other letter according to a given key pattern like the one below. "abcdefghijklmnopqrstuvwxyz" "doxrhvauspntbcmqlfgwijezky" // key pattern For example, every 'a' will become a...

  • WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you...

    WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you will write functions to encrypt and decrypt messages using simple substitution ciphers. Your solution MUST include: a function called encode that takes two parameters: key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order; plaintext, a string of unspecified length that represents the message to be encoded. encode will return a string representing the ciphertext. a...

  • Do this using the C language. show me the code being executed and also copy and...

    Do this using the C language. show me the code being executed and also copy and paste the code so i can try it out for myseld Instructions A cipher is mirrored algorithm that allow phrases or messages to be obfuscated (ie. "scrambled"). Ciphers were an early form of security used to send hidden messages from one party to another. The most famous and classic example of a cipher is the Caesar Cipher. This cypher worked by shifting each letter...

  • Q16-Decoder (0.5 points) Write a code block to decode strings from secret encodings back to reada...

    Q16-Decoder (0.5 points) Write a code block to decode strings from secret encodings back to readable messages. To do so: Initialize a variable called decoded as an empty string . Use a for loop to loop across all characters of a presumed string variable called encoded Inside the loop, convert the character to another character o Get the unicode code point for the character (using ord o Subtract the value of key to that code point (which should be an...

  • Cryptography, the study of secret writing, has been around for a very long time, from simplistic...

    Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...

  • Write a static method called encodeString that takes a string as input and prints to the...

    Write a static method called encodeString that takes a string as input and prints to the console a word where each letter is advanced by one value. In addition, your method should return the encoded String. You may make use of the method provided below to help you. public static char encode(char x) { int current = x; current++; return (char)current; } This method takes a character and returns an "encoded" character. In other words, encode('a') will return 'b'. Your...

  • Can someone please help me for this assignment? Cryptography — the science of secret writing —...

    Can someone please help me for this assignment? Cryptography — the science of secret writing — is an old science; the first recorded use was well before 1900 B.C. An Egyptian writer used previously unknown hieroglyphs in an inscription. We will use a simple substitution cypher called rot13 to encode and decode our secret messages. ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the 13th letter after it, in...

  • MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...

    MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an abstract class that will be the base class for other two classes. It should have: A...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • I'm also having trouble on dividing the code into methods. This is my work done so...

    I'm also having trouble on dividing the code into methods. This is my work done so far and net beans give me a lot of errors. Help! package caesarcipher; import textio.TextIO; /** * * @author */ public class CaesarCipher { enum code {encodeText, decodeText }; /** * @param args the command line arguments */ public static void main(String[] args) {    String code; char x;    int totalcount = 0;    while(true){ TextIO.put("Type in an E to encode a message...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT